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

**URL:** <https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931>\
**Category:** General\
**Created:** [10 March 2020 14:41 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931 "2020-03-10T14:41:53Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [11 March 2020 23:22 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/21 "2020-03-11T23:22:28Z")

</div>

And my Mac...

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [12 March 2020 07:09 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/22 "2020-03-12T07:09:23Z")

</div>

And my Lenovo with Debian

@dceejay  
[https://github.com/tensorflow/tfjs/blob/master/tfjs-node/README.md](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

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [12 March 2020 07:11 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/23 "2020-03-12T07:11:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [12 March 2020 08:42 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/24 "2020-03-12T08:42:51Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/2/32b88851a28720bcc16fc644e0855088fbe38503.png)

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

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [12 March 2020 09:01 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/25 "2020-03-12T09:01:28Z")

</div>

> [@krambriw](#):
>
> I think you should try:  
> `npm install @tensorflow/tfjs-node`

😭 fails but instead of

```auto
 Error: Unsupported system: gpu-linux-arm

```

I get

```auto
 Error: Unsupported system: cpu-linux-arm

```

---

<div class="post-metadata">

**Author:** ![unixneo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/unixneo/32/17441_2.png) [@unixneo](https://discourse.nodered.org/u/unixneo)\
**Post date:** [12 March 2020 09:12 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/26 "2020-03-12T09:12:28Z")

</div>

> [@zenofmud](#):
>
> hmmm got the same thing trying to install it on a Pi Zero W (just thought I'd try) though mine ends with `Error: Unsupported system: gpu-linux-arm`

```auto
#### 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:

> **[@tensorflow/tfjs-node](https://www.npmjs.com/package/@tensorflow/tfjs-node)**
>
> This repository provides native TensorFlow execution in backend JavaScript applications under the Node.js runtime, accelerated by the TensorFlow C binary under the hood. It provides the same API as...

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [12 March 2020 09:41 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/27 "2020-03-12T09:41:17Z")

</div>

> [@unixneo](#):
>
> npm rebuild @tensorflow/tfjs-node

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [12 March 2020 09:49 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/28 "2020-03-12T09:49:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [12 March 2020 10:01 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/29 "2020-03-12T10:01:16Z")

</div>

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](https://www.youtube.com/watch?v=aPjf-MCjGVc)

---

<div class="post-metadata">

**Author:** ![unixneo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/unixneo/32/17441_2.png) [@unixneo](https://discourse.nodered.org/u/unixneo)\
**Post date:** [12 March 2020 10:01 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/30 "2020-03-12T10:01:30Z")

</div>

> [@zenofmud](#):
>
> On a Pi Zero that results with a `Error: Unsupported system: cpu-linux-arm`

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

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

```

**--build-from-source**

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [12 March 2020 10:10 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/31 "2020-03-12T10:10:34Z")

</div>

> [@unixneo](#):
>
> npm rebuild @tensorflow/tfjs-node --build-from-source

still gets the same error

---

<div class="post-metadata">

**Author:** ![SuperNinja](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/superninja/32/5761_2.png) [@SuperNinja](https://discourse.nodered.org/u/SuperNinja)\
**Post date:** [12 March 2020 10:22 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/32 "2020-03-12T10:22:33Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [12 March 2020 10:32 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/33 "2020-03-12T10:32:30Z")

</div>

> [@SuperNinja](#):
>
> either by showing all the boxes at once @krambriw if you could do this option it would be great

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

---

<div class="post-metadata">

**Author:** ![SuperNinja](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/superninja/32/5761_2.png) [@SuperNinja](https://discourse.nodered.org/u/SuperNinja)\
**Post date:** [12 March 2020 10:49 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/34 "2020-03-12T10:49:00Z")

</div>

ok, i will try my side but it will take time 🤓

---

<div class="post-metadata">

**Author:** ![unixneo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/unixneo/32/17441_2.png) [@unixneo](https://discourse.nodered.org/u/unixneo)\
**Post date:** [12 March 2020 11:15 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/35 "2020-03-12T11:15:06Z")

</div>

> [@zenofmud](#):
>
> still gets the same error

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.

---

<div class="post-metadata">

**Author:** ![SuperNinja](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/superninja/32/5761_2.png) [@SuperNinja](https://discourse.nodered.org/u/SuperNinja)\
**Post date:** [12 March 2020 12:00 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/36 "2020-03-12T12:00:47Z")

</div>

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 `

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [12 March 2020 13:20 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/37 "2020-03-12T13:20:33Z")

</div>

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

```auto
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)

---

<div class="post-metadata">

**Author:** ![SuperNinja](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/superninja/32/5761_2.png) [@SuperNinja](https://discourse.nodered.org/u/SuperNinja)\
**Post date:** [12 March 2020 13:26 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/38 "2020-03-12T13:26:05Z")

</div>

> [@dceejay](#):
>
> npm i node-red-contrib-tfjs-coco-ssd

I try immediately

---

<div class="post-metadata">

**Author:** ![SuperNinja](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/superninja/32/5761_2.png) [@SuperNinja](https://discourse.nodered.org/u/SuperNinja)\
**Post date:** [12 March 2020 13:38 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/39 "2020-03-12T13:38:07Z")

</div>

The installation went well

```auto
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 :

```auto
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

```

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [12 March 2020 13:45 UTC](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931/40 "2020-03-12T13:45:52Z")

</div>

> [@dceejay](#):
>
> npm i node-red-contrib-tfjs-coco-ssd

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/95b02047a3c367a237abe58e7c33605a1f9d7555.png)

In the NVIDIA Jetson Nano where Node-RED otherwise runs perfect:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/9/092b18e5bf06694bcd9d6bcb7146a6f24e2221fe.png)

[Previous page](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931.md?page=1)

[Next page](https://discourse.nodered.org/t/object-detection-using-node-red-contrib-tfjs-coco-ssd/22931.md?page=3)
