错误:输入 0 与层 conv2d_Conv2D1 不兼容:预期 ndim=4,发现 ndim=5

时间:2020-12-23 00:06:12

标签: javascript node.js tensorflow


async function train() {
    
    var labels = [0] // 0 = L 
    var tensorLabels = tf.oneHot(tf.tensor1d(labels, 'int32'), 3);

    var buffer = fs.readFileSync("./train/L/L.png")
    var tensorFeature = tf.node.decodeImage(buffer)

    var tensorFeatures = tf.stack([tensorFeature])
    
    const model = tf.sequential();
    model.add(tf.layers.conv2d({
      inputShape: [1, 132, 180, 3], // numberOfChannels = 3 for colorful images and one otherwise
      filters: 32,
      kernelSize: 3,
      activation: 'relu',
    }));
    model.add(tf.layers.flatten()),
    model.add(tf.layers.dense({units: 3, activation: 'softmax'}));

    model.compile({loss: 'meanSquaredError', optimizer: 'sgd'})
    model.fit(tensorFeatures, tensorLabels)
}

我正在尝试用字母“L”(132x180)训练张量流模型,我对 tf.我希望我能在使用图像的训练方面得到一些帮助。

1 个答案:

答案 0 :(得分:0)

通过改变 inputShape 修复:

 inputShape: [180, 132, 3],