# Tf-model problem of undefined in object detection

**URL:** <https://discourse.nodered.org/t/tf-model-problem-of-undefined-in-object-detection/71268>\
**Category:** General\
**Tags:** function-node\
**Created:** [25 November 2022 22:20 UTC](https://discourse.nodered.org/t/tf-model-problem-of-undefined-in-object-detection/71268 "2022-11-25T22:20:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gtova](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gtova/32/101947_2.png) [@Gtova](https://discourse.nodered.org/u/Gtova)\
**Post date:** [25 November 2022 22:20 UTC](https://discourse.nodered.org/t/tf-model-problem-of-undefined-in-object-detection/71268/1 "2022-11-25T22:20:34Z")

</div>

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

> [@Post object detection - Tf model](https://discourse.nodered.org/t/post-object-detection-tf-model/49661):
>
> 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": "Pincet…

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

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [26 November 2022 08:03 UTC](https://discourse.nodered.org/t/tf-model-problem-of-undefined-in-object-detection/71268/2 "2022-11-26T08:03:12Z")

</div>

> [@Gtova](#):
>
> ""TypeError: Cannot read properties of undefined (reading 'backend')"

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 November 2022 09:26 UTC](https://discourse.nodered.org/t/tf-model-problem-of-undefined-in-object-detection/71268/3 "2022-11-26T09:26:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Gtova](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gtova/32/101947_2.png) [@Gtova](https://discourse.nodered.org/u/Gtova)\
**Post date:** [28 November 2022 18:55 UTC](https://discourse.nodered.org/t/tf-model-problem-of-undefined-in-object-detection/71268/4 "2022-11-28T18:55:26Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/5/1547974708e5bb872286e4bae19a3684fb594608.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/b/5bdae5058f4205f3fe3cfd805a41959c46d057c1.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/d/2d561a7c060120c1e3617b75172fd13ebd395da1.png)

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

---

<div class="post-metadata">

**Author:** ![Gtova](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gtova/32/101947_2.png) [@Gtova](https://discourse.nodered.org/u/Gtova)\
**Post date:** [28 November 2022 19:15 UTC](https://discourse.nodered.org/t/tf-model-problem-of-undefined-in-object-detection/71268/6 "2022-11-28T19:15:06Z")

</div>

here is my flow

```auto
[
    {
        "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": [
            []
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![Gtova](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gtova/32/101947_2.png) [@Gtova](https://discourse.nodered.org/u/Gtova)\
**Post date:** [28 November 2022 19:57 UTC](https://discourse.nodered.org/t/tf-model-problem-of-undefined-in-object-detection/71268/7 "2022-11-28T19:57:00Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [28 November 2022 22:25 UTC](https://discourse.nodered.org/t/tf-model-problem-of-undefined-in-object-detection/71268/8 "2022-11-28T22:25:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gtova](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gtova/32/101947_2.png) [@Gtova](https://discourse.nodered.org/u/Gtova)\
**Post date:** [30 November 2022 07:53 UTC](https://discourse.nodered.org/t/tf-model-problem-of-undefined-in-object-detection/71268/9 "2022-11-30T07:53:39Z")

</div>

@Colin do you need any additional information ?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 November 2022 09:23 UTC](https://discourse.nodered.org/t/tf-model-problem-of-undefined-in-object-detection/71268/10 "2022-11-30T09:23:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 January 2023 09:24 UTC](https://discourse.nodered.org/t/tf-model-problem-of-undefined-in-object-detection/71268/11 "2023-01-29T09:24:08Z")

</div>

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