[英]Error: Error when checking input: expected dense_Dense1_input to have 3 dimension(s). but got array with shape 1,9
[英]Error when checking input: expected dense_Dense1_input to have x dimension(s). but got array with shape y,z
我對Tensorflowjs和Tensorflow很新。 我有一些數據,這是100%的容量,所以0到100之間的數字,每天有5小時這些容量。 所以我有一個5天的矩陣,其中包含5%的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);
});
我收到一個錯誤: Error when checking input: expected dense_Dense1_input to have 3 dimension(s). but got array with shape 5,5
Error when checking input: expected dense_Dense1_input to have 3 dimension(s). but got array with shape 5,5
。 所以我懷疑我是以某種方式錯誤地輸入或映射我的數據。
您的錯誤來自一方面訓練和測試數據的大小不匹配,另一方面來自定義為模型的輸入
model.add(tf.layers.dense({units: 1, inputShape: [5, 5] }));
inputShape是您的輸入維度。 這是5,因為每個功能都是一個大小為5的數組。
model.predict(tf.tensor(5))
另外,為了測試您的模型,您的數據應該與訓練模型時的形狀相同。 您的模型無法使用tf.tensor(5)
預測任何內容。 因為您的訓練數據與您的測試數據大小不匹配。 考慮這個測試數據而不是tf.tensor2d([5, 1, 2, 3, 4], [1, 5])
這是一個有效的snipet
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.