Which, of the several tfjs nodes, is this ? - My version - node-red-contrib-tfjs-coco-ssd - creates a msg.classes property that is an array of classes and counts.
(Note : - be warned that installing two similar tfjs nodes often causes conflicts withe underlying tfjs binary so you may need to uninstall one before installing another if you choose to do that)
I am not sure if I should try yours. We have a flow for predicting with cocossd classes of a picture obtained from an streaming ip video. And our goal would be to show in a dashboard the number of persons vs time in the incoming pictures.
Do you think I should use node-red-contrib-tfjs-coco-ssd?
var filter = "person"; //what to find - note this could come from msg.payload or anywhere!
var filtered = msg.details.filter(el => el.class == filter); //filter to elements with .class equal to filter
msg.payload = filtered; //set payload to the filtered results
return msg; //send the payload to next node
this will give you an array of items where class == person
If you truly only want the count then change it to this...
var filter = "person"; //what to find - note this could come from msg.payload or anywhere!
var filtered = msg.details.filter(el => el.class == filter); //filter to elements with .class equal to filter
if(filtered && filtered.count)
msg.payload = filtered.count; //set payload to the count found
else
msg.payload = 0;
return msg; //send the payload to next node
And it seems like it does not filter the elements with .class equal to filter, because I added a new node msg.details, after the function node and it still shows in the pane objects with different class type than person (boat, for example).
Regarding with the counting part. I tried as well to check it taking the information to a dashboard, but it is always showing 0, even if in the debug pane you can see that it is detecting "person".
Perhaps I am not configuring correctly the dashboard settings.
As I alluded to, it was untested code. I should have used .length not .count
Change the code to this...
var filter = "person"; //what to find - note this could come from msg.payload or anywhere!
var filtered = msg.details.filter(el => el.class == filter); //filter to elements with .class equal to filter
if(filtered && filtered.length) {
msg.payload = filtered.length; //set payload to the count found
} else {
msg.payload = 0;
}
msg.filtered = filtered; //pass the filtered array in the msg for future capabilities
return msg; //send the msg to the next node
NOTE: I have added the property .filtered to the msg so if you want to display the score or access the bounding box - the filtered results will be already in the msg for you (just ignore this property if not needed)