预期dense_Dense1_input 的形状为“a"但得到了形状为“b"的数组 [英] Expected dense_Dense1_input to have shape "a" but got array with shape "b"

查看:68
本文介绍了预期dense_Dense1_input 的形状为“a"但得到了形状为“b"的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人愿意帮助我完成这个 TensorFlow JS 项目吗?这是一个带有机器学习功能的聊天机器人,我坚持构建神经网络",给我这个错误

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

项目链接:https://github.com/ran-j/ChatBotNodeJS

/routes/index.js 第 189 行的训练代码

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}); 

推荐答案

该错误表明为模型定义的形状与模型使用的张量(无论是训练张量还是测试张量)不匹配.

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.

预期dense_Dense1_input 的形状为a,但数组的形状为b

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

在错误中 a 是模型的形状,b 是引发错误的张量的形状.所以需要改变模型的形状是b还是张量的形状是a.

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.

最简单的方法是将模型形状更改为 b,因为第二种方法意味着张量的重塑,即

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}));

这篇关于预期dense_Dense1_input 的形状为“a"但得到了形状为“b"的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆