Post object detection - Tf model

Hello everyone. I'm trying to make an object detection, using the node Tf model, with my custom Tensorflow.js model.
This is what it looks like:


Tf model gives me these results:
NODERED2

But I would like to get a nicer format: like ClassName, score. So I used post object detection node, but it throws me an error:
NODERED3
This node, it points to the classes of my model.

{
  "0": "zakrivljene skare",
  "1": "Hvataljke",
  "2": "Skalpel",
  "3": "Ravne skare",
  "4": "Pinceta"
}

Node-red3

here is Flow:

[{"id":"f5ab4212.216cd","type":"ui_button","z":"94afeb23.054898","name":"","group":"97e4a5c1.956978","order":5,"width":7,"height":1,"passthru":false,"label":"Take a picture","tooltip":"","color":"","bgcolor":"","icon":"fa-camera","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":100,"y":320,"wires":[["a8645ed2.8dbdc"]]},{"id":"91819385.69657","type":"base64","z":"94afeb23.054898","name":"","action":"str","property":"payload","x":700,"y":260,"wires":[["b5bc47a3.778bb8"]]},{"id":"b5bc47a3.778bb8","type":"template","z":"94afeb23.054898","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<img width=\"352px\" height=\"288px\" src=\"data:image/jpg;base64,{{{payload}}}\">","output":"str","x":880,"y":260,"wires":[["1f441c77.d470a4"]]},{"id":"1f441c77.d470a4","type":"ui_template","z":"94afeb23.054898","group":"97e4a5c1.956978","name":"","order":6,"width":7,"height":5,"format":"<div ng-bind-html=\"msg.payload\"></div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":1040,"y":260,"wires":[[]]},{"id":"c8ba58c4.bbf278","type":"function","z":"94afeb23.054898","name":"","func":"var now = new Date();\nvar yyyy = now.getFullYear();\nvar mm = now.getMonth() < 9 ? \"0\" + (now.getMonth() + 1) : (now.getMonth() + 1); \nvar dd  = now.getDate() < 10 ? \"0\" + now.getDate() : now.getDate();\nvar hh = now.getHours() < 10 ? \"0\" + now.getHours() : now.getHours();\nvar mmm  = now.getMinutes() < 10 ? \"0\" + now.getMinutes() : now.getMinutes();\nvar ss  = now.getSeconds() < 10 ? \"0\" + now.getSeconds() : now.getSeconds();\n\n\nmsg.imagename = \"image_\"+  yyyy + mm + dd + \"-\" + hh + mmm + ss + \".jpg\";\n\nmsg.filename = \"/home/pi/\"+ msg.imagename;\n\nnode.status({fill:\"blue\",shape:\"ring\",text:msg.imagename});\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":880,"y":360,"wires":[["9c577bd.6cec088"]]},{"id":"9c577bd.6cec088","type":"file","z":"94afeb23.054898","name":"","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":1050,"y":360,"wires":[[]]},{"id":"a8645ed2.8dbdc","type":"usbcamera","z":"94afeb23.054898","filemode":"0","filename":"image01.jpg","filedefpath":"1","filepath":"","fileformat":"jpeg","resolution":"1","name":"","x":290,"y":320,"wires":[["91819385.69657","c8ba58c4.bbf278"]]},{"id":"42e4dd7d.64bed4","type":"debug","z":"94afeb23.054898","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1250,"y":420,"wires":[]},{"id":"c418f755.09a728","type":"ui_dropdown","z":"94afeb23.054898","name":"File Selector","label":"","tooltip":"","place":"Select a file","group":"97e4a5c1.956978","order":11,"width":4,"height":1,"passthru":false,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","topicType":"str","x":910,"y":100,"wires":[["ccfb1644.317238"]]},{"id":"4d729f97.d07b4","type":"function","z":"94afeb23.054898","name":"Format data","func":"// format the data for the dropdown\nmsg.options = [];\nfor (var i=0; i<msg.payload.length; i++) {\n    // This is a file\n    obj = {};\n    obj [msg.payload[i].name.replace(/^.*(\\\\|\\/|\\:)/, '')]=msg.payload[i].name;\n    msg.options.push(obj);\n}\nmsg.payload={};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":710,"y":100,"wires":[["c418f755.09a728"]]},{"id":"814fb010.c9e93","type":"ui_template","z":"94afeb23.054898","group":"97e4a5c1.956978","name":"","order":14,"width":7,"height":3,"format":"<div ng-bind-html=\"msg.payload\" height=\"400\" style=\"height: 400px;\"><br/>\n</div>\n\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":1100,"y":160,"wires":[[]]},{"id":"671ffb56.de45d4","type":"template","z":"94afeb23.054898","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<table width=\"100%\">\n    <tr><th>File Name</th><th>Size</th><th>Created</th><th>Changed</th></tr>\n    {{#payload}}\n        <tr>\n            <td><a href=\"/download?filename={{name}}\" target=\"blank\">{{fname}}</a></td>\n            <td>{{stat.size}}</td>\n            <td>{{stat.created}}</td>\n            <td>{{stat.changed}}</td>\n        </tr>\n    {{/payload}}\n</table>\n","output":"str","x":940,"y":160,"wires":[["814fb010.c9e93"]]},{"id":"df773472.6ea0c8","type":"function","z":"94afeb23.054898","name":"Convert timestamps","func":"for (var i=0; i<msg.payload.length; i++) {\n    msg.payload[i].stat.created = msg.payload[i].stat.created.toISOString().slice(0, 19).replace('T', ' ');\n    msg.payload[i].stat.changed = msg.payload[i].stat.changed.toISOString().slice(0, 19).replace('T', ' ');\n    msg.payload[i].stat.accessed = msg.payload[i].stat.accessed.toISOString().slice(0, 19).replace('T', ' ');\n    msg.payload[i].stat.statusChanged = msg.payload[i].stat.statusChanged.toISOString().slice(0, 19).replace('T', ' ');\n    msg.payload[i].fname = msg.payload[i].name.replace(/^.*(\\\\|\\/|\\:)/, '');\n}\nreturn msg;","outputs":1,"noerr":0,"x":740,"y":160,"wires":[["671ffb56.de45d4"]]},{"id":"ea5802a4.76cb","type":"ui_button","z":"94afeb23.054898","name":"","group":"97e4a5c1.956978","order":12,"width":7,"height":1,"passthru":false,"label":"Detect","tooltip":"","color":"","bgcolor":"","icon":"search","payload":"","payloadType":"str","topic":"","topicType":"str","x":70,"y":240,"wires":[["842caf62.82d98"]]},{"id":"842caf62.82d98","type":"function","z":"94afeb23.054898","name":"Get filename","func":"// Get the filename from the flow context\nlet filename = flow.get(\"fileselected\");\n\n// check, if the filename is undefined that means it does not exist yet, nothing is selected yet\n// return: do not output anything\nif (filename===undefined) {\n    return;\n}\n\n// return the filename to the file-in node to delete\nmsg.filename = filename;\n\nif (msg.filename.replace(/^.*(\\\\|\\/|\\:)/, '')[0]!==\".\") {\n    // Only do this if this is a file, we don't delete folders\n    return msg;\n}","outputs":1,"noerr":0,"x":310,"y":260,"wires":[["1fa3eae4.8f3c85"]]},{"id":"1fa3eae4.8f3c85","type":"file in","z":"94afeb23.054898","name":"","filename":"","format":"","chunk":false,"sendError":false,"encoding":"none","x":450,"y":260,"wires":[["c8ba58c4.bbf278","91819385.69657","29b894654bf6b42a"]]},{"id":"be23964b.9b1878","type":"function","z":"94afeb23.054898","name":"Folder handling","func":"let folder = context.get(\"folder\");\nif (folder===undefined) {\n    folder=\"/\";\n    context.set(\"folder\", folder);\n}\n\nlet hidden = context.get(\"hidden\");\nif (hidden===undefined) {\n    hidden=false;\n    context.set(\"hidden\", hidden);\n}\n\nif (msg.topic===\"up\") {\n    var the_arr = folder.split('/');\n    the_arr.pop();\n    folder=the_arr.join('/'); \n    context.set(\"folder\", folder);\n}\nif (msg.topic===\"change\") {\n    folder=msg.payload;    \n    context.set(\"folder\", folder);\n}\nif (msg.topic===\"hidden\") {\n    hidden=msg.payload;    \n    context.set(\"hidden\", hidden);\n}\n\nmsg.payload = {\"start\":folder, \"hidden\": hidden};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":100,"wires":[["687e66e5.f5f0e8","11ab2161.446f1f","95dcb257.7ba6f"]]},{"id":"11ab2161.446f1f","type":"ui_text","z":"94afeb23.054898","group":"97e4a5c1.956978","order":13,"width":7,"height":1,"name":"","label":"Folder:","format":"{{msg.payload.start}}","layout":"row-left","x":520,"y":60,"wires":[]},{"id":"3865ad30.a235d2","type":"ui_button","z":"94afeb23.054898","name":"","group":"97e4a5c1.956978","order":8,"width":3,"height":1,"passthru":false,"label":"Upload files","tooltip":"","color":"","bgcolor":"","icon":"arrow_upwards","payload":"","payloadType":"str","topic":"up","topicType":"str","x":90,"y":100,"wires":[["be23964b.9b1878"]]},{"id":"290c457.ba291ba","type":"ui_button","z":"94afeb23.054898","name":"","group":"97e4a5c1.956978","order":10,"width":3,"height":1,"passthru":false,"label":"Open","tooltip":"","color":"","bgcolor":"","icon":"folder_open","payload":"","payloadType":"str","topic":"","topicType":"str","x":70,"y":180,"wires":[["8b75fd63.759cc"]]},{"id":"8b75fd63.759cc","type":"function","z":"94afeb23.054898","name":"Change folder","func":"// Get the filename from the flow context\nlet folderselected = flow.get(\"folderselected\");\n\n// check, if the filename is undefined that means it does not exist yet, nothing is selected yet\n// return: do not output anything\nif (folderselected===undefined) {\n    return;\n}\n\nmsg.topic = \"change\";\nmsg.payload = folderselected;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":180,"wires":[["be23964b.9b1878"]]},{"id":"def0aeae.4cb5e","type":"ui_dropdown","z":"94afeb23.054898","name":"Folder Selector","label":"","tooltip":"","place":"Select a folder","group":"97e4a5c1.956978","order":9,"width":4,"height":1,"passthru":false,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","topicType":"str","x":920,"y":200,"wires":[["d62a4a52.758c88"]]},{"id":"33f4f8cd.af0ee8","type":"function","z":"94afeb23.054898","name":"Format data","func":"// format the data for the dropdown\nmsg.options = [];\nfor (var i=0; i<msg.payload.length; i++) {\n    // This is a foler\n    obj = {};\n    obj [\"[\"+msg.payload[i].name.replace(/^.*(\\\\|\\/|\\:)/, '')+\"]\"]=msg.payload[i].name;\n    msg.options.push(obj);\n}\nmsg.payload={};\nreturn msg;","outputs":1,"noerr":0,"x":710,"y":200,"wires":[["def0aeae.4cb5e"]]},{"id":"ccfb1644.317238","type":"change","z":"94afeb23.054898","name":"Save selection","rules":[{"t":"set","p":"fileselected","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1140,"y":100,"wires":[[]]},{"id":"d62a4a52.758c88","type":"change","z":"94afeb23.054898","name":"Save selection","rules":[{"t":"set","p":"folderselected","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1120,"y":200,"wires":[[]]},{"id":"687e66e5.f5f0e8","type":"fs-file-lister","z":"94afeb23.054898","name":"Files","start":"/home/pi","pattern":"*.*","folders":"*","hidden":false,"lstype":"files","path":true,"single":true,"depth":0,"stat":true,"showWarnings":false,"x":510,"y":120,"wires":[["4d729f97.d07b4","df773472.6ea0c8"]]},{"id":"95dcb257.7ba6f","type":"fs-file-lister","z":"94afeb23.054898","name":"Folders","start":"/home/pi","pattern":"*.*","folders":"*","hidden":false,"lstype":"directories","path":true,"single":true,"depth":0,"stat":true,"showWarnings":false,"x":520,"y":200,"wires":[["33f4f8cd.af0ee8"]]},{"id":"c5968dbaee8bd706","type":"fileinject","z":"94afeb23.054898","name":"","x":210,"y":420,"wires":[["29b894654bf6b42a"]]},{"id":"29b894654bf6b42a","type":"jimp-image","z":"94afeb23.054898","name":"","data":"payload","dataType":"msg","ret":"buf","parameter1":"","parameter1Type":"msg","parameter2":"","parameter2Type":"msg","parameter3":"","parameter3Type":"msg","parameter4":"","parameter4Type":"msg","parameter5":"","parameter5Type":"msg","parameter6":"","parameter6Type":"msg","parameter7":"","parameter7Type":"msg","parameter8":"","parameter8Type":"msg","sendProperty":"payload","sendPropertyType":"msg","parameterCount":0,"jimpFunction":"none","selectedJimpFunction":{"name":"none","fn":"none","description":"Just loads the image.","parameters":[]},"x":380,"y":440,"wires":[["a5030e68fa6327be"]]},{"id":"a5030e68fa6327be","type":"tf-function","z":"94afeb23.054898","name":"","func":"const image = tf.tidy(() => {\n  return tf.node.decodeImage(msg.payload, 3).expandDims(0);\n});\n\nmsg.image = msg.payload;\nmsg.payload = { image_tensor: image }\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":480,"wires":[["049cd179eace8f80"]]},{"id":"a4b2119e842d9883","type":"post-object-detection","z":"94afeb23.054898","classesURL":"file:///home/pi/Downloads/model_web4/class.json","iou":"0.5","minScore":"0.5","name":"","x":1060,"y":440,"wires":[["42e4dd7d.64bed4"]]},{"id":"ec0cbd7ddd9a7fea","type":"debug","z":"94afeb23.054898","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":920,"y":500,"wires":[]},{"id":"049cd179eace8f80","type":"tf-model","z":"94afeb23.054898","modelURL":"file:///home/pi/Downloads/model_web4/model.json","outputNode":"","name":"","x":670,"y":440,"wires":[["ec0cbd7ddd9a7fea","74e2c1381a8b461a"]]},{"id":"74e2c1381a8b461a","type":"delay","z":"94afeb23.054898","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":860,"y":440,"wires":[["a4b2119e842d9883"]]},{"id":"97e4a5c1.956978","type":"ui_group","name":"Detekcija /Detection","tab":"1ebe0164.fd16ff","order":1,"disp":false,"width":7,"collapse":false},{"id":"1ebe0164.fd16ff","type":"ui_tab","name":"Detekcija slika/ Data detection","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Does anyone know how I could solve this problem? I would be very grateful. :smiley:

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.