Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

85
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda