Tf-model problem of undefined in object detection

sorry to bother you guys but i face a similar problem when i pass the image to the tf-model
""TypeError: Cannot read properties of undefined (reading 'backend')"

i don't know why i got this error i think its because of the preprocessing node i got another error before this one which is " Cannot read property 'length' of undefined"
all help are apreciated

i have the same problem as this guy except i don't use the same pre-processing code

Try to dissect this line.

It tries to read a property called 'backend' - does 'backend' exist ? Probably not, because it is "undefined".

Same applies to "Cannot read property 'length' of undefined"

If something does not exist, it cannot read from it, nor can it determine the length.

You will need to tell us what node is generating that error. Is it a contrib node or something else?
Also show us what you are sending to that node and how you have configured it.



image

The node where I have the problem is the tf model node. You can see it
Any help are appreciated
I use the resize because I construct my model with an input of (30,30,3) that’s why

here is my flow

[
    {
        "id": "e6ed8a49.34ead",
        "type": "tab",
        "label": "Traffic sign",
        "disabled": false,
        "info": ""
    },
    {
        "id": "30a983c6.f15eac",
        "type": "camera",
        "z": "e6ed8a49.34ead",
        "name": "Camera",
        "x": 90,
        "y": 120,
        "wires": [
            [
                "b7ab82ff.b1a338"
            ]
        ]
    },
    {
        "id": "be443e0d.18f9d",
        "type": "jimp-image",
        "z": "e6ed8a49.34ead",
        "name": "load the image",
        "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",
        "parameterCount": 0,
        "jimpFunction": "none",
        "selectedJimpFunction": {
            "name": "none",
            "fn": "none",
            "description": "Just loads the image.",
            "parameters": []
        },
        "x": 340,
        "y": 60,
        "wires": [
            [
                "b7ab82ff.b1a338",
                "9d9a08561d941b12",
                "990f49cc.99ebf8"
            ]
        ]
    },
    {
        "id": "abda13e6.303bb8",
        "type": "inject",
        "z": "e6ed8a49.34ead",
        "name": "Inject",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "https://raw.githubusercontent.com/tensorflow/tfjs-models/master/coco-ssd/demo/image1.jpg",
        "payloadType": "str",
        "x": 90,
        "y": 80,
        "wires": [
            [
                "be443e0d.18f9d"
            ]
        ]
    },
    {
        "id": "b7ab82ff.b1a338",
        "type": "image viewer",
        "z": "e6ed8a49.34ead",
        "name": "Original Image viewer",
        "width": "100",
        "data": "payload",
        "dataType": "msg",
        "active": true,
        "x": 680,
        "y": 40,
        "wires": [
            []
        ]
    },
    {
        "id": "e0a513ae.0c3ff8",
        "type": "image viewer",
        "z": "e6ed8a49.34ead",
        "name": "With bounding boxes",
        "width": "320",
        "data": "payload",
        "dataType": "msg",
        "active": true,
        "x": 680,
        "y": 340,
        "wires": [
            []
        ]
    },
    {
        "id": "26d5c369.1e4fc4",
        "type": "fileinject",
        "z": "e6ed8a49.34ead",
        "name": "select an image file",
        "x": 130,
        "y": 40,
        "wires": [
            [
                "be443e0d.18f9d"
            ]
        ]
    },
    {
        "id": "41a6b3d.e80f0cc",
        "type": "bbox-image",
        "z": "e6ed8a49.34ead",
        "strokeWidth": "4",
        "fontSize": "16",
        "objectsProp": "payload",
        "objectsPropType": "msg",
        "imageProp": "image",
        "imagePropType": "msg",
        "name": "bounding-box",
        "x": 340,
        "y": 360,
        "wires": [
            [
                "e0a513ae.0c3ff8"
            ]
        ]
    },
    {
        "id": "dd280bb2.d6681",
        "type": "post-object-detection",
        "z": "e6ed8a49.34ead",
        "classesURL": "file:///home/pi/mymodel/classes.json",
        "iou": "0.5",
        "minScore": "0.5",
        "name": "post-processing",
        "x": 120,
        "y": 360,
        "wires": [
            [
                "41a6b3d.e80f0cc"
            ]
        ]
    },
    {
        "id": "990f49cc.99ebf8",
        "type": "tf-function",
        "z": "e6ed8a49.34ead",
        "name": "pre-processing",
        "func": "const image = tf.tidy(() => {\n  return tf.image.resizeBilinear(tf.node.decodeImage(msg.payload, 3), [30, 30]).expandDims(0)\n    .toFloat().div(tf.scalar(127)).sub(tf.scalar(1));\n});\nmsg.image = msg.payload;\nmsg.payload = [image]\n\nreturn msg;",
        "outputs": 1,
        "noerr": 5,
        "x": 140,
        "y": 200,
        "wires": [
            [
                "d7528f2297e13795",
                "995f6de8.b48258"
            ]
        ]
    },
    {
        "id": "995f6de8.b48258",
        "type": "tf-model",
        "z": "e6ed8a49.34ead",
        "modelURL": "file:///home/pi/mymodel/model.json",
        "outputNode": "",
        "name": "Traffic sign recognition",
        "x": 140,
        "y": 300,
        "wires": [
            [
                "dd280bb2.d6681",
                "d6444996cec934a9"
            ]
        ]
    },
    {
        "id": "d6444996cec934a9",
        "type": "debug",
        "z": "e6ed8a49.34ead",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 380,
        "y": 280,
        "wires": []
    },
    {
        "id": "d7528f2297e13795",
        "type": "debug",
        "z": "e6ed8a49.34ead",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 380,
        "y": 200,
        "wires": []
    },
    {
        "id": "9d9a08561d941b12",
        "type": "debug",
        "z": "e6ed8a49.34ead",
        "name": "debug 6",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 220,
        "wires": []
    },
    {
        "id": "ab7b41fa0c5780ce",
        "type": "tf-function",
        "z": "e6ed8a49.34ead",
        "name": "pre-processing",
        "func": "const image = tf.tidy(() => {\n  //return tf.node.decodePng(msg.payload, 0).expandDims(0);\n  return tf.node.decodeImage(msg.payload, 0).expandDims(0);\n});\n//msg.payload = tf.reshape(image, [1, 30, 30, 3])\nmsg.image = msg.payload;\n\n//msg.image = tf.reshape(image, [1,30,30,3]);\nmsg.payload = image;\nmsg.payload = tf.slice(msg.payload, [0, 0, 0, 1],[1,30, 30, 3])\n//msg.payload = { image_tensor: image };\n//msg.payload = tf.tensor(msg.payload).reshape([1, 512, 512, 2]);\nreturn msg; ",
        "outputs": 1,
        "noerr": 3,
        "x": 360,
        "y": 600,
        "wires": [
            []
        ]
    },
    {
        "id": "b8bf37ab85451ec9",
        "type": "tf-function",
        "z": "e6ed8a49.34ead",
        "name": "",
        "func": "const image = tf.tidy(() => {\n    return tf.node.decodeImage(msg.payload, 3).expandDims(0)\n    .div(tf.scalar(127)).sub(tf.scalar(1));\n});\n//msg.payload.dataSync()[0]\nmsg.image = msg.payload;\nmsg.payload = [image]\nreturn msg;",
        "outputs": 1,
        "noerr": 4,
        "x": 860,
        "y": 640,
        "wires": [
            []
        ]
    }
]

update!!!
i reboot my raspberry pi and now it give me this error in the post-processing node

TypeError: Cannot read properties of undefined (reading 'dataSync')

i uploaded my classes in my raspberry pi this way
{
"1":"limit speed 20",
"2" :"stop sign",
..etc
}
i have 43 class and i did the same thing for all of them but it give me the error that you have seen

I have no idea about most of this but the problem in your function node is the fact that Object tf is not defined

@Colin do you need any additional information ?

You still have not told us what node-type you have installed. It is probably node-red-contrib-????

I see on an earlier image that the pre-processing function is showing an error. Have you fixed that?

In future when posting code please copy/paste rather than screenshot. When pasting use the </> button in the forum entry window.

Show us the message you are passing into the post-processing node. Hover over it in the debug window and click the copy value button that pops up and paste that here. Again use the the </> button when pasting.

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