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

149
Vistas
Tensorflow error: expected dense_Dense1_input to have shape [null,3] but got array with shape [3,1]

I'm trying to build a TF model which takes a tensor with [1,3] shape

// example: [1,2,3]

And the output is the same

here's a simple code to reproduce the error

const {
  tensor1d,
  sequential,
  layers,
} = require('@tensorflow/tfjs-node');

const model = sequential();

  model.add(
    layers.dense({
      units: 3,
      inputShape: [3],
    })
  );

  model.compile({
    loss: 'meanSquaredError',
    optimizer: 'adam',
  });

  let inputTensor = tensor1d([1,2,3]);
  let outputTensor = tensor1d([1,2,3]);

model.fit(inputTensor, outputTensor);

let result = model.predict(inputTensor); // it fires the error here

The model.fit & model.predict functions both take the same input shape from inputTensor variable, however it fires error in the second function model.predict

Any explanation for that error, I'm a bit newbie in Tensorflow

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

When you feed data into tensorflow model, remember the shape of input data should have batch dimension.

So your input data have to expand the dimension, like this:

let inputTensor = tensor1d([[1,2,3]]);
let outputTensor = tensor1d([[1,2,3]]);

Or use tensorflow function tf.expandDims to do this :

The shape of output and input tensor will be (1,3).

The error message means you feed 3 data with 1 dimension, but model expect 3 dimension.

about 4 years ago · Santiago Trujillo Denunciar
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