【发布时间】:2021-07-05 16:10:55
【问题描述】:
您好,我正在使用 Tensorflow.js 创建我的第一个神经网络。
我想使用点 (0,0)、(0,1)、(1,0)、(1,1) 和标签 0、1、1、0 作为我的 NN 的输入。我尝试了以下方式:
async function runModel() {
// Build and compile model.
const model = tf.sequential();
model.add(tf.layers.dense({units: 2, inputShape: [2]}));
model.compile({optimizer: 'sgd', loss: 'meanSquaredError'});
// Generate some synthetic data for training.
const xs = tf.tensor2d([[1], [0]], [2,1]);
const ys = tf.tensor2d([[1]], [1, 1]);
// Train model with fit().
await model.fit(xs, ys, {epochs: 10});
// Run inference with predict().
model.predict(tf.tensor2d([[0], [1]], [2, 1])).print();
}
runModel()
我最终得到了错误:
未捕获(承诺中)错误:检查输入时出错:预期 dense_Dense1_input 的形状为 [,2],但得到的数组的形状为 [2,1]。
我尝试使用所有参数,但我不明白(即使有文档)如何成功。
【问题讨论】: