Identifying objects in tensorflowjs using custom keras models

87 Views Asked by At

I want to use a tensorflow model in javascript for real-time object detection. For that, I am following this tutorial by tensorflow.org: https://www.tensorflow.org/js/tutorials/conversion/import_keras I have trained model in keras, exported the model to a .h5 format, converted it to a json file and finally imported the model.

Here’s a snippet of my javascript code block,

net = await tf.loadLayersModel('http://localhost:8000/converted/model.json');
const imgEl = document.getElementById('img');
const t = tf.browser.fromPixels(imgEl)
let result = await net.predict(t)

The image I am trying to identify is 255 x 255 , RGB I get error that the input image is 3 dimensional but the expected was 4. I have attached the snipped of the error. error in javascript

I have tried re-shaping the input image but to no avail. Can someone help?

0

There are 0 best solutions below