-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Dear,
I am trying to integrate the code from the Coral codelab into the Node-RED application, to allow our community to detect objects fast in images (e.g. persons in IP cam images for video surveillance). Our current solution can already draw rectangles around detected objects (via tfjs), but I would like to add Coral support.
First I load the a pre-trained TfLite model for object detection (which I download from this site):
var modelUrl = "https://raw.githubusercontent.com/google-coral/test_data/master/tf2_ssd_mobilenet_v2_coco17_ptq_edgetpu.tflite";
const options = {delegates: [new CoralDelegate()]};
var tfLiteModel = await tflite.loadTFLiteModel(modelUrl, options);
Once the model is loaded, the input of my code is an image (as a NodeJs buffer):
var tf = require('@tensorflow/tfjs-node');
var img = tf.node.decodeImage(new Uint8Array(imgBuffer));
const expanded = tf.expandDims(img, 0);
const prediction = tfLiteModel.predict(expanded);
const percentage = tf.div(tf.mul(prediction, tf.scalar(100)), tf.scalar(255));
const data = percentage.dataSync();
However the tf.mul
throws following exception:
Error: Argument 'a' passed to 'mul' must be a Tensor or TensorLike, but got 'Object'
at convertToTensor (/home/pi/.node-red/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:5433:15)
at mul_ (/home/pi/.node-red/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:11026:14)
at Object.mul__op [as mul] (/home/pi/.node-red/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:5485:29)
...
The prediction
object looks like this:
Noob question: does this mean perhaps that it has recognized 4 different classes of objects in my image, and that I need to loop these 4 tensors (simply via Object.keys(...))
? Which I then must map to a label, and somehow extract the coordinates of the bounding box?
It would also be nice if somebody could explain (in simple words ;-) ) why the expandDims(img, 0)
is required, and what the tf.div(tf.mul(prediction, tf.scalar(100)), tf.scalar(255))
is doing.
Thanks!!!
Bart Butenaers