Tensorflow.js Loading Model Returns Function Predict Is Not Defined
When I load a saved model like this (please dont mind the fact that the predict function has no input) const tf = require('@tensorflow/tfjs'); require('@tensorflow/tfjs-node'); co
Solution 1:
You need to work with promises.
loadModel()
returns a promise resolving into the loaded model. So to access it you either need to use the .then()
notation or be inside an async
function and await
it.
.then()
:
tf.loadModel('file://./model-1a/model.json').then(model => {
model.predict();
});
async/await
:
async function processModel(){
const model = await tf.loadModel('file://./model-1a/model.json');
model.predict();
}
processModel();
or in a shorter, more direct way:
(async ()=>{
const model = await tf.loadModel('file://./model-1a/model.json');
model.predict();
})()
Post a Comment for "Tensorflow.js Loading Model Returns Function Predict Is Not Defined"