Tensorflow.js模型维度不匹配



我是tensoflow.js的新手,由于维度不匹配,我在创建CNN模型时遇到了问题。我有一个使用tf.browser.fromPixels(image);的三维阵列。

但当我试图训练我的ai时,它不会启动,我得到了消息: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);
}
}
});
}

好的,这是我的代码:

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);
}
}
});
}

我发现我的";CCD_ 3";需要设置与decoder单元相同的

这是固定代码:

image = new Image(4, 4);
data = tf.browser.fromPixels(image);
model = tf.sequential();
encoder = tf.layers.dense({units: 3, batchInputShape:[null, null, 3], activation: 'relu', kernelInitializer:"randomNormal", biasInitializer:"ones"});
decoder = tf.layers.dense({units: 3, activation: 'relu'});
model.add(encoder);
model.add(decoder);
model.compile({loss:'meanSquaredError', optimizer:tf.train.adam()});
async function botTraining(model, epochs = 60){
history = 
await model.fit(data, data,{ epochs: epochs + 1,
callbacks:{
onEpochEnd: async(epoch, logs) =>{
console.log("Epoch:" + epoch + " Loss:" + logs.loss);
}
}
});
}

相关内容

  • 没有找到相关文章

最新更新