Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

node.js - Expected dense_Dense1_input to have shape "a" but got array with shape "b"

Anyone would help me with this TensorFlow JS project ? It's a Chat bot with machine learn, I stuck on 'build neural network' , giveme this error

Project Link : https://github.com/ran-j/ChatBotNodeJS

The training code at /routes/index.js line 189

//Build neural network
  model = tf.sequential();
  model.add(tf.layers.dense({inputShape: [documents.length], units: 100}));
  model.add(tf.layers.dense({units: 4}));
  model.compile({loss: 'categoricalCrossentropy', optimizer: 'sgd'});

  model.fit(xs, ys, {epochs: 1000}); 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The error indicates that there is a mismatch between the shape defined for the model and the tensors used by the model be it the training or test tensors.

In order to get rid of the error you need both shapes to match.

Expected dense_Dense1_input to have shape a but got array with shape b

In the error a is the shape of the model and b is the shape of the tensor that is throwing the error. So one needs to change whether the shape of the model to b or the shape of the tensor to be a.

The easiest way is to change the model shape to b since the second way would imply a reshape of the tensor i.e

model.add(tf.layers.dense({inputShape: b, units: 100})); 

Given the model of the question, it will be

model.add(tf.layers.dense({inputShape: [27, 48], units: 100}));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...