Skip to content

Incompatibility TensorFlow Lite model converted from Keras Sequential model #1350

@HGSvienna

Description

@HGSvienna

TensorFlow is installed on my Windows notebook running a WSL Linux environment.
Following the instructions at https://www.tensorflow.org/tutorials/images/classification, I successfully performed an image classification (tested with some test images).
I converted the Keras Sequential model to a TensorFlow Lite model according to the instructions above.
TensorFlow Lite is installed on a Raspberry Pi 5 (8 GB), and the command python3 real_time_with_labels.py --model mobilenet_v2.tflite --label coco_labels.txt works as expected.
(https://github.com/raspberrypi/picamera2/blob/main/examples/tensorflow/real_time_with_labels.py)

If I now replace the model file and the label file with the TensorFlow Lite model I created
(python3 real_time_with_labels.py --model model.tflite --label clothes_types.txt), I get the following error message:

pi@raspberrypi:~/tflite1/Test $ python3 real_time_with_labels.py --model model.tflite --label clothes_types.txt
[4:16:53.908876168] [67265] INFO Camera camera_manager.cpp:330 libcamera v0.5.2+99-bfd68f78
[4:16:53.915920072] [67271] INFO RPI pisp.cpp:720 libpisp version v1.2.1 981977ff21f3 29-04-2025 (14:13:50)
[4:16:53.918585514] [67271] INFO IPAProxy ipa_proxy.cpp:180 Using tuning file /usr/share/libcamera/ipa/rpi/pisp/imx477.json
[4:16:53.925416739] [67271] INFO Camera camera_manager.cpp:220 Adding camera '/base/axi/pcie@1000120000/rp1/i2c@88000/imx477@1a' for pipeline handler rpi/pisp
[4:16:53.925453334] [67271] INFO RPI pisp.cpp:1179 Registered camera /base/axi/pcie@1000120000/rp1/i2c@88000/imx477@1a to CFE device /dev/media0 and ISP device /dev/media1 using PiSP variant BCM2712_C0
QStandardPaths: wrong permissions on runtime directory /run/user/1000, 0770 instead of 0700
[4:16:54.308823124] [67265] INFO Camera camera.cpp:1215 configuring streams: (0) 640x480-XBGR8888/sRGB (1) 320x240-YUV420/sYCC (2) 2028x1520-BGGR_PISP_COMP1/RAW
[4:16:54.308982633] [67271] INFO RPI pisp.cpp:1483 Sensor: /base/axi/pcie@1000120000/rp1/i2c@88000/imx477@1a - Selected sensor format: 2028x1520-SBGGR12_1X12/RAW - Selected CFE format: 2028x1520-PC1B/RAW
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Traceback (most recent call last):
File "/home/pi/tflite1/Test/real_time_with_labels.py", line 151, in
main()
File "/home/pi/tflite1/Test/real_time_with_labels.py", line 147, in main
_ = InferenceTensorFlow(grey, args.model, output_file, label_file)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/tflite1/Test/real_time_with_labels.py", line 93, in InferenceTensorFlow
detected_classes = interpreter.get_tensor(output_details[1]['index'])

IndexError: list index out of range

There must be an incompatibility with the TensorFlow Lite model.
I would appreciate any suggestions.
Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions