Tensorflow JS : Error: Invalid TF_Status: 3 Message: In[0] and In[1] has different ndims: [1,8,8,64,2] vs. [2,1]

501 Views Asked by At

I converted a saved model into Tensorflow JS & was trying to get results from it. I was using NodeJS to load the model.json file. I created a endpoint for it and was sending a image url to it. Here is what I did :

const tf = require("@tensorflow/tfjs-node");
var model;
loadModel();

async function loadModel() {
    model = await tf.loadGraphModel('https://LinkTo/YourModel/model.json');
    console.log("Model Loading Done!!")
}

async function detectcellPhone(imgurl) {
    const imgTensor = tf.node.decodeImage(new Uint8Array(fs.readFileSync(imgurl)), 3);
    const predictions = await model.executeAsync(imgTensor.expandDims(0));
    return predictions;
}

I was able to load the model successfully but when I was trying to get predictions from it, I encountered the following error :

Error: Invalid TF_Status: 3 Message: In[0] and In[1] has different ndims: [1,8,8,64,2] vs. [2,1]

I have answered my own questions below.

1

There are 1 best solutions below

0
S M On

After spending a few hours to figure out about the error, I realized that the version of @tensorflow/tfjs-node was 3.13.0. After updating it to the latest version of 3.13.19 the error disappeared. May not be big deal, but I thought I should post it so that others can benefit from this.