我使用 tf.expandDims() 来添加尺寸。因为我可以进入 model.fit(),但由于这个错误而卡住了无法开始训练,因为另一个 fit() 调用正在进行。 and 无法读取未定义的属性“长度”。你可以在这里找到我的代码
// Train the model using the data.
let tesnor_dim =[];
let tensr;for(var j=0; j<2; j++){
console.log('resize_image',resize_image);
tensr = tf.expandDims(ysarr[j], 0);
tesnor_dim.push(tensr);
console.log('tesnor_dim',tesnor_dim);
model.fit(resize_image[j], tesnor_dim[j], {epochs: 100}).then((loss) => {
console.log('resize_image[j]',resize_image[j]);
console.log('tesnor_dim[j]',tesnor_dim[j]);
console.log('loss',loss);
const t = model.predict(resize_image[j]);
console.log('Prediction:::'+t);
pred = t.argMax(1).dataSync(); // get the class of highest probability
const labelsPred = Array.from(pred).map(e => setLabel[e])
console.log('labelsPred:::'+labelsPred);
//const saveResults = model.save('downloads://my-model-1');
//console.log(saveResults);
}).catch((e) => {
console.log(e.message);
})
}
当多个fit
在同一模型上调用,它们必须按顺序完成。这意味着第二个调用只有在第一个调用完成后才开始。使用async
and await
除非第一个呼叫完成,否则将阻止您的第二个呼叫发生。
loss = await model.fit(resize_image[j], tesnor_dim[j], {epochs: 100})
// continue rest of processing
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)