Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

79
Visualizações
tensorflowJS cant figure out arrays

I am trying to input an array of data and output a prediction or a guess for what the result should be for the given data, I do not know much about neural nets but have a basic understanding on how their training works... I was hoping that it would see the two given inputs combined add up to the output in the three examples I provided for it such as [1, 2] should = 3 but I have hit a wall with inputting arrays and am getting the fallowing error

UnhandledPromiseRejectionWarning: Error: input expected a batch of elements where each example has shape [1] (i.e.,tensor shape [*,1]) but the input received an input with 3 examples, each with shape [2] (tensor shape [3,2])

any ideas someone can give me on how I should be going about this would be etremely helpful -.-

import tf from '@tensorflow/tfjs';

// create model object
const model = tf.sequential();
model.add(tf.layers.dense({
    units: 1,
    inputShape: [1]
}));

// compile model object
model.compile({
    optimizer: 'sgd',
    loss: 'meanSquaredError'
});


// training datasets
// input data for training
const xs = tf.tensor2d([
    [1, 2],
    [5, 6],
    [3, 4]

]);

// output data for training
const ys = tf.tensor1d([
    3,
    11,
    7

]);


async function firstFunction(_callback) {


    // Train model with fit().method
    await model.fit(xs, ys, {
        epochs: 100000
    })
    _callback();
}


function secondFunction() {

    //We wait for the call back from first function.
    firstFunction(function() {

        // We run the prediction.                    
        prediction = model.predict(tf.tensor2d([
            [6, 9],
        ])).dataSync()[0]

    });
}

secondFunction()
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda