Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!