Object Detection using node-red-contrib-tfjs-coco-ssd

And my Mac...

And my Lenovo with Debian

@dceejay
https://github.com/tensorflow/tfjs/blob/master/tfjs-node/README.md
I have seen that to support GPU there is also a @tensorflow/tfjs-node-gpu required that I have tried (so far unsuccessful) to install in my NVIDIA. Certainly I understand that the node might need modifications to take advantage of the GPU, right now I just try to manually install @tensorflow/tfjs-node and @tensorflow/tfjs-node-gpu but so far, no success. I have reached out to the NVIDIA forum crying for help
Why do this? Well, for the thrill, I really would like to know how fast the analyze would run on the Jetson when utilizing the GPU with 128 kernels

1 Like

I think you should try:
npm install @tensorflow/tfjs-node

I have modified the code in the posiRectangle a bit. I thought it could be nice to let the rectangles be looped and reprinted on the image as long as there is no new image to show. It works pretty nice I think

In the example, a new box is overlayed every 2 second. If you prefer another timing, just change in the code below (msg.detect.length*2000) and also in the delay node in my previous example

image

EDIT: Had a small bug in the code below, now boxes from previous image is stopped if a new image has no detected objects :innocent:

var st = context.get('started')||false;
var reset = {reset:true};

if(msg.detect.length>0){
    clearTimeout(st);
    node.send(reset);
    showBoxes();
}else{
    clearTimeout(st);
    node.send(reset);
}

function writeBox(element) {
    let box = element;
    msg.x = box.bbox[0];
    msg.y = box.bbox[1];
    msg.width = box.bbox[2];
    msg.height= box.bbox[3];
    msg.class = box["class"];
    msg.score = box["score"];
    node.send(msg);
}

function showBoxes() {
    msg.detect.forEach(element => writeBox(element))
    st = setTimeout( showBoxes, msg.detect.length*2000 );
    context.set('started', st);
}


:sob: fails but instead of

 Error: Unsupported system: gpu-linux-arm

I get

 Error: Unsupported system: cpu-linux-arm
#### Rebuild the package on Raspberry Pi

To use this package on Raspberry Pi, you need to rebuild the node native addon with the following command after you installed the package:

$ npm rebuild @tensorflow/tfjs-node --build-from-source

Ref:

On a Pi Zero that results with a Error: Unsupported system: cpu-linux-arm

Nice - @krambriw would you mind if I enhance the built in the example to do this ? (or indeed do you want to PR it ?)

I don't know how to PR so if possible for you, could you?

BTW I just made a little video demonstrating the feature
https://www.youtube.com/watch?v=aPjf-MCjGVc

Did you use the full command, as in my reply and the reference?

npm rebuild @tensorflow/tfjs-node --build-from-source

--build-from-source

In your reply back you omitted the key switch --build-from-source

still gets the same error

To really go to the end of the project, I think it will be up to the user to choose to display (or not) the boxes:

  • alternatively, one by one, as in the example of @krambriw
  • either by showing all the boxes at once @krambriw if you could do this option it would be great
    (I would have liked to do it myself, but I have been learning to code javascript for only 1 year! lol)

That will be a bit tricky I think,,,,for the time I can not imagine any other way than saving the image for each box and then re-use it for the next,,,maybe there is a better way

Also, please note I updated the code in the posiRectangle, I had a small bug, see above

ok, i will try my side but it will take time :nerd_face:

That's no fun....

Sorry I don't have a PI handy, because if I did I would give it a try and hopefully be able to help more.

Could you try on WIN10? I have :
Error: Cannot find module 'C:\Users\christian\.Node-RED-Desktop\node_modules\@tensorflow\tfjs-node\lib\napi-v4\tfjs_binding.node'
Require stack:

  • C:\Users\christian.Node-RED-Desktop\node_modules@tensorflow\tfjs-node\dist\index.js
  • C:\Users\christian.Node-RED-Desktop\node_modules\node-red-contrib-tfjs-coco-ssd\tfjs.js
  • C:\Users\christian\AppData\Local\Programs\node-red-desktop\resources\app.asar\node_modules@node-red\registry\lib\loader.js
    ............etc `

I just did a basic install of the node in a Win10 VM and I get

C:\Users\demo\.node-red>npm i node-red-contrib-tfjs-coco-ssd

> @tensorflow/tfjs-node@1.4.0 install C:\Users\demo\.node-red\node_modules\@tensorflow\tfjs-node
> node scripts/install.js

CPU-windows-1.4.0.zip
* Downloading libtensorflow
[==============================] 6526191/bps 100% 0.0s
[==============================] 2039730/bps 100% 0.0s
* Building TensorFlow Node.js bindings
+ node-red-contrib-tfjs-coco-ssd@0.1.3
added 92 packages from 93 contributors and audited 656 packages in 75.569s

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities


C:\Users\demo\.node-red>node-red

And then restart Node-RED - instal the example and it works... (for me)

I try immediately

The installation went well

PS C:\Users\christian\.node-red> npm i node-red-contrib-tfjs-coco-ssd

> @tensorflow/tfjs-node@1.4.0 install C:\Users\christian\.node-red\node_modules\@tensorflow\tfjs-node
> node scripts/install.js

CPU-windows-1.4.0.zip
* Downloading libtensorflow
[==============================] 3034429/bps 100% 0.0s
[==============================] 3134220/bps 100% 0.0s
* Building TensorFlow Node.js bindings
+ node-red-contrib-tfjs-coco-ssd@0.1.4
added 84 packages from 104 contributors and audited 566 packages in 33.336s
found 0 vulnerabilities

PS C:\Users\christian\.node-red>

it looks like yours installed more packages than me? But same error in Node-red-Desktop :

Error: Cannot find module 'C:\Users\christian\.Node-RED-Desktop\node_modules\@tensorflow\tfjs-node\lib\napi-v4\tfjs_binding.node'
Require stack:
- C:\Users\christian\.Node-RED-Desktop\node_modules\@tensorflow\tfjs-node\dist\index.js
- C:\Users\christian\.Node-RED-Desktop\node_modules\node-red-contrib-tfjs-coco-ssd\tfjs.js

The same when I try on NVIDIA Jetson Nano (ubuntu)
"Error: /home/wk/.node-red/node_modules/@tensorflow/tfjs-node/lib/napi-v5/tfjs_binding.node: cannot open shared object file: No such file or directory"

When I look into this inside /home/wk/.node-red/node_modules/@tensorflow/tfjs-node I can see that several folders and files are missing

In a Pi3:
image

In the NVIDIA Jetson Nano where Node-RED otherwise runs perfect:
image