检查输入时出错:预期density_Dense1_input具有x尺寸.但是得到了形状为y,z的数组 [英] Error when checking input: expected dense_Dense1_input to have x dimension(s). but got array with shape y,z

查看:98
本文介绍了检查输入时出错:预期density_Dense1_input具有x尺寸.但是得到了形状为y,z的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总体来说,我对Tensorflowjs和Tensorflow还是很陌生.我有一些数据,容量使用率超出100%,因此数字介于0和100之间,并且每天有5个小时记录这些容量.所以我有一个5天的矩阵,其中100%中包含5个百分比.

I'm very new to Tensorflowjs and Tensorflow in general. I have some data, which is capacity used out of 100%, so a number between 0 and 100, and there are 5 hours per day these capacities are noted. So I have a matrix of 5 days, containing 5 percentages out of 100%.

我有以下模型:

const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [5, 5] }));
model.compile({ loss: 'binaryCrossentropy', optimizer: 'sgd' });

// Input data
// Array of days, and their capacity used out of 
// 100% for 5 hour period
const xs = tf.tensor([
  [11, 23, 34, 45, 96],
  [12, 23, 43, 56, 23],
  [12, 23, 56, 67, 56],
  [13, 34, 56, 45, 67],
  [12, 23, 54, 56, 78]
]);

// Labels
const ys = tf.tensor([[1], [2], [3], [4], [5]]);

// Train the model using the data.
model.fit(xs, ys).then(() => {
  model.predict(tf.tensor(5)).print();
}).catch((e) => {
  console.log(e.message);
});

我收到返回错误:检查输入时出错:预期density_Dense1_input具有3个维度.但是得到了形状为5,5的数组.因此,我怀疑我以某种方式错误地输入或映射了我的数据.

I'm getting an error returned: Error when checking input: expected dense_Dense1_input to have 3 dimension(s). but got array with shape 5,5. So I suspect I'm entering or mapping my data incorrectly in some way.

推荐答案

您的错误来自训练和测试数据大小不匹配,而另一方面来自定义作为模型的输入

Your error comes from a mismatch of the size of the training and test data from one hand on the other hand by what is defined as the input of your model

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

inputShape 是您的输入维度.这里是5,因为每个要素都是大小为5的数组.

The inputShape is your input dimension. Here it is 5, because each features is an array of size 5.

model.predict(tf.tensor(5))

此外,为了测试模型,数据的形状应与训练模型时的形状相同.您的模型无法使用 tf.tensor(5)进行任何预测.因为您的训练数据和测试数据大小不匹配.考虑使用此测试数据,而不是 tf.tensor2d([5,1,2,3,4],[1,5])

Also to test your model, your data should have the same shape as when your are training your model. Your model cannot predict anything with tf.tensor(5). Because your training data and your test data size do not match. Consider this test data instead tf.tensor2d([5, 1, 2, 3, 4], [1, 5])

这是一个正常工作的 snipet

这篇关于检查输入时出错:预期density_Dense1_input具有x尺寸.但是得到了形状为y,z的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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