Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlowJS Exception - Cannot start training because another fit() call is ongoing

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);
            })
            }
like image 767
ANKIT SHARMA Avatar asked Jun 04 '26 10:06

ANKIT SHARMA


1 Answers

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
like image 94
edkeveked Avatar answered Jun 07 '26 01:06

edkeveked



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!