【问题标题】:Error: Error when checking input: expected dense_Dense1_input to have 3 dimension(s). but got array with shape 1,9错误:检查输入时出错:预期 dense_Dense1_input 具有 3 个维度。但得到了形状为 1,9 的数组
【发布时间】:2021-01-05 11:29:19
【问题描述】:

我对 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]);

【问题讨论】:

    标签: javascript tensorflow tensorflow.js


    【解决方案1】:

    inputShape 的大小为 2,因此,特征(此处为 xtrain 和 xtest)的维度应为 3。

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

    鉴于您的 xtrain 和 xtest 形状,[a, b],inputShape,应该是 [b]

    herethere 讨论了模型和训练数据之间的这种形状不匹配

    【讨论】:

    • 我还是不明白,你能告诉我输入的形状应该是什么吗?
    • inputShape 应该是[9],最后一个单元应该是[9],形状为xtrainytrain。虽然,它会使错误消失,但不一定足以具有良好的准确性。你可以在这里查看这个答案:stackoverflow.com/questions/55943498/model-is-not-learning/…
    猜你喜欢
    • 1970-01-01
    • 2020-06-18
    • 2020-06-09
    • 1970-01-01
    • 2020-02-27
    • 2020-07-01
    • 2020-06-08
    • 2020-12-08
    • 1970-01-01
    相关资源
    最近更新 更多