【发布时间】:2021-03-30 21:47:57
【问题描述】:
我是 tensoflow.js 的新手,我在创建 CNN 模型时遇到问题,因为尺寸不匹配。我有一个使用 tf.browser.fromPixels(image); 的 3d 数组。
但是当我尝试训练我的人工智能时它不会启动,我收到了消息:Uncaught (in promise) Error: Error when checking target: expected dense_Dense2 to have shape [6,6,4], but got array with shape [6,6,3].
这里是完整的代码:
image = new Image(32, 32);
data = tf.browser.fromPixels(image); //to get pixel array
model = tf.sequential();
encoder = tf.layers.dense({units: 4, batchInputShape:[6, 6, 3], activation: 'relu', kernelInitializer:"randomNormal", biasInitializer:"ones"});
decoder = tf.layers.dense({units: 4, activation: 'relu'});
model.add(encoder);
model.add(decoder);
model.compile({loss:'meanSquaredError', optimizer:tf.train.adam()});
async function botTraining(model, epochs = 60){ //train ai 60 epochs
history =
await model.fit(data, data,{ epochs: epochs + 1,
callbacks:{
onEpochEnd: async(epoch, logs) =>{
console.log("Epoch:" + epoch + " Loss:" + logs.loss);
}
}
});
}
【问题讨论】:
标签: javascript tensorflow conv-neural-network png autoencoder