Need help to speed up my flow

Hi all!

I´ve been playing around with the picamera and tensorflow recently. Technically it works fine but is pretty slow. The whole procedure (Taking image, saving image, reading back the image, evaluation) takes around 20-30s. I tried decreasing the camera-resolution but I think the bottleneck is saving the image to the sd-card and then read that file again into tensorflow.

Any ideas on how I could decrease the processing time?

[
    {
        "id": "f4b1c46ead32be2d",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "0cdf4353160d5b6b",
        "type": "image viewer",
        "z": "f4b1c46ead32be2d",
        "name": "",
        "width": "320",
        "data": "payload",
        "dataType": "msg",
        "active": true,
        "x": 750,
        "y": 80,
        "wires": [
            []
        ]
    },
    {
        "id": "306b36debe375050",
        "type": "inject",
        "z": "f4b1c46ead32be2d",
        "name": "trigger photo",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 110,
        "y": 20,
        "wires": [
            [
                "d2e26697e0fa52d4"
            ]
        ]
    },
    {
        "id": "d2e26697e0fa52d4",
        "type": "exec",
        "z": "f4b1c46ead32be2d",
        "command": "libcamera-still --width 1536 --height 1024 -q 80 -o newtest.JPEG",
        "addpay": "",
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "capture setting",
        "x": 120,
        "y": 120,
        "wires": [
            [
                "3689dbb728c6e8ec"
            ],
            [],
            []
        ]
    },
    {
        "id": "4847c7c7a3402623",
        "type": "jimp-image",
        "z": "f4b1c46ead32be2d",
        "name": "",
        "data": "payload",
        "dataType": "msg",
        "ret": "img",
        "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": 610,
        "y": 80,
        "wires": [
            [
                "0cdf4353160d5b6b"
            ]
        ]
    },
    {
        "id": "497e047f9db6eb7c",
        "type": "debug",
        "z": "f4b1c46ead32be2d",
        "name": "Result",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 630,
        "y": 340,
        "wires": []
    },
    {
        "id": "3689dbb728c6e8ec",
        "type": "change",
        "z": "f4b1c46ead32be2d",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "/home/pi/newtest.JPEG",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 430,
        "y": 80,
        "wires": [
            [
                "4847c7c7a3402623",
                "db8542bf22386caf"
            ]
        ]
    },
    {
        "id": "b4c71952e3216ba8",
        "type": "teachable machine",
        "z": "f4b1c46ead32be2d",
        "name": "",
        "mode": "local",
        "modelUri": "/home/pi/Pictures/tm-my-image-model/",
        "localModel": "teachable_model",
        "output": "best",
        "activeThreshold": false,
        "threshold": 80,
        "activeMaxResults": false,
        "maxResults": 3,
        "passThrough": false,
        "x": 390,
        "y": 340,
        "wires": [
            [
                "497e047f9db6eb7c"
            ]
        ]
    },
    {
        "id": "dadfc08cdd5e1b27",
        "type": "inject",
        "z": "f4b1c46ead32be2d",
        "name": "retest",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 170,
        "y": 220,
        "wires": [
            [
                "3689dbb728c6e8ec"
            ]
        ]
    },
    {
        "id": "db8542bf22386caf",
        "type": "file in",
        "z": "f4b1c46ead32be2d",
        "name": "",
        "filename": "payload",
        "filenameType": "msg",
        "format": "",
        "chunk": false,
        "sendError": false,
        "encoding": "base64",
        "allProps": false,
        "x": 440,
        "y": 160,
        "wires": [
            [
                "b4c71952e3216ba8"
            ]
        ]
    }
]

Sorry, but:

You may need to share more information:

What machine? Raspi ......?????

Which O/S?

Just that your flow can't just be looked at as many/most people won't have those nodes/hardware.

I am using a pi4 2gb ram version running Raspberry Pi OS(bullseye).
I was hoping that somebody played around with this aswell :slight_smile:
Basically it would already help, if someone could explain to me how to output a buffer object of the taken picture from the execute-node. This way I could get rid of saving and then parsing the file to the tensorflow node.

Try this...

libcamera-still --width 1536 --height 1024 -q 80 -o -

This should send the output to stdout of the exec node.
meaning you can plug the image viewer/tensorflow directly after it, and skip the IO involved with the SD Card

Dsiclaimer.
This is just from searching

1 Like

Works like a charm! Thank you :grin:

1 Like

Also you may find reducing the image size helps as most models are trained on smaller images anyway.

2 Likes

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