TensorFlowJS异常 - 无法启动训练,因为正在进行另一次fit()调用 [英] TensorFlowJS Exception - Cannot start training because another fit() call is ongoing

查看:294
本文介绍了TensorFlowJS异常 - 无法启动训练,因为正在进行另一次fit()调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用tf.expandDims()来添加尺寸。因为我可以进入model.fit(),但由于此错误而卡住无法启动训练,因为正在进行另一次fit()调用。无法读取属性'length'未定义。
您可以在此处找到我的代码

I used tf.expandDims() to add dimensions. Since I'm able to go into model.fit(), but got stuck due to this error Cannot start training because another fit() call is ongoing. and Cannot read property 'length' of undefined. You can find my code here

// 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 await 将阻止您的第二次通话,除非第一次完成。

When multiple fit are called on the same model, they have to be done sequentially. It means that the second call has to start only when the first one has completed. Using async and await will prevent your second call to happen unless the first has completed.

loss = await model.fit(resize_image[j], tesnor_dim[j], {epochs: 100})
// continue rest of processing

这篇关于TensorFlowJS异常 - 无法启动训练,因为正在进行另一次fit()调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆