【问题标题】:Tensorflowjs yields shape error when trainingTensorflowjs 在训练时会产生形状错误
【发布时间】:2018-07-17 14:51:41
【问题描述】:

我正在尝试使用 tensorflow 版本 tfjs@0.12.0 训练一个简单的网络模型,并且我正在使用层 API。它只是一个将两个数字作为输入并返回相同的两个数字的网络——因此网络应该尝试学习单位矩阵。

我正在使用 6 个示例进行训练,因此我的输入和输出的形状都是 [6,2] 但是我遇到了形状错误。

我的 javascript 文件如下:

function setup() {
    const model = tf.sequential();

    const hidden = tf.layers.dense({
        units: 4,
        useBias: true,
        activation:'sigmoid',
        inputDim: [2],
    });

    model.add(hidden);

    const output = tf.layers.dense({
        units: 2,
        activation:'sigmoid',
    });

    model.add(output);

    model.compile({
        optimizer: 'sgd',
        loss: 'meanSquaredError',
    });

    const xs = tf.tensor2d([
        [0.25, 0.92],
        [0.12,0.3],
        [0.4,0.74],
        [0.3,0.82],
        [0.09,0.95],
        [0.53,0.2],
    ]);

    const ys = tf.tensor2d([
        [0.25, 0.92],
        [0.12,0.3],
        [0.4,0.74],
        [0.3,0.82],
        [0.09,0.95],
        [0.53,0.2],
    ]);


    console.log(model.fit(xs,ys));
}

但是,当我运行脚本时,出现形状错误:

Promise { <state>: "rejected" }
sketch.js:46:5
Error: Error when checking input: expected dense_Dense1_input to have shape [,2], but got array with shape [6,2].

【问题讨论】:

    标签: javascript tensorflow tensorflow.js


    【解决方案1】:

    hidden 层声明中设置inputDim: 2inputShape: [2]

    【讨论】:

      猜你喜欢
      • 2019-03-30
      • 2019-10-20
      • 2019-05-06
      • 2019-12-24
      • 1970-01-01
      • 1970-01-01
      • 2019-05-19
      • 2021-03-30
      • 1970-01-01
      相关资源
      最近更新 更多