错误:检查输入时出错:dense_Dense1_input应具有3个维度.但得到了形状为1.9的数组



我真的是tensorflow.js的新手,我正在尝试做一个简单的模型,告诉你你点击了的画布的哪一边

const model = tf.sequential();
model.add(
tf.layers.dense({
units: 200,
activation: "sigmoid",
inputShape: [0, 1],
})
);
model.add(
tf.layers.dense({
units: 2,
activation: "softmax",
})
);
model.compile({
optimizer: optimizer,
loss: "categoricalCrossentropy",
metrics: ["accuracy"],
});

我的训练和测试数据

const yTrain = tf.tensor2d(
[10, 130, 60, 20, 150, 110, 3, 160, 99],
[1, 9]
);
const xTrain = tf.tensor2d([0, 1, 0, 0, 1, 1, 0, 1, 0], [1, 9]);
const yTest = tf.tensor2d(
[5, 106, 33, 88, 104, 140, 7, 60, 154],
[1, 9]
);
const xTest = tf.tensor2d([0, 1, 0, 0, 1, 1, 0, 0, 1], [1, 9]);

inputShape的大小为2,因此,特性(此处为xtain和xtest(的大小应为3。

另外,将维度大小设为0是没有意义的(这意味着张量是空的(。

给定extrin和xtest形状,inputShape[a, b]应该是[b]

已经在这里和那里讨论了模型和训练数据之间的这种形状不匹配

最新更新