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

156
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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