cancel
Showing results for 
Search instead for 
Did you mean: 

STM32MPU25 object detection model failing to run python scripts

akr1
Associate II

Hi

I am using STM32MPU25 to evaluate object detection, when i use stai_mpu_object_detection binary to run default ssd_mobilenet_v2 models , i can see object detection works.

when i run python scripts to launch application( example : launch_bin_object_detection_testdata.sh) i see below error.

root@stm32mp25-discounknownunknown:/usr/local/x-linux-ai/object-detection# sh launch_python_object_detection.sh
stai_mpu wrapper used :
machine used = stm32mp2x with GPU/NPU
user : weston
-sh: /usr/local/x-linux-ai/object-detection/stai_mpu_object_detection.py: Permission denied

 

i assume it may be due to weston user and root user.

so i copied all objection detection samples to /home/weston and gave appropriate permissions and change user to weston and launch application, i see below errors.

^^^^^^^^^^^^^^^^^^^^^
File "/home/weston/test/Application/ssd_mobilenet_pp.py", line 129, in get_results
return locations, classes, scores
^^^^^^^^^
UnboundLocalError: cannot access local variable 'locations' where it is not associated with a value
Traceback (most recent call last):
File "/home/weston/test//Application/object_detection.py", line 336, in new_sample
self.app.nn_result_locations, self.app.nn_result_classes, self.app.nn_result_scores = self.nn.get_results()
^^^^^^^^^^^^^^^^^^^^^
File "/home/weston/test/Application/ssd_mobilenet_pp.py", line 129, in get_results
return locations, classes, scores

can you point to environment where i can evaluate object detection models ( i followed procedure at https://github.com/STMicroelectronics/stm32ai-modelzoo-services/tree/main/object_detection  to create object detection model  with custom data set and deploy into stm32mpu25)

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions

Adding background class started detecting objects properly in stm32mpu257.

couple of questions i have 

1) while running launch_python_object_detection.sh  i see below error

while running  File "/home/weston/object-detection//Application/object_detection.py", line 679, in drawing
y0 = int(self.app.nn_result_locations[0][i][1] * preview_height)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: index 3 is out of bounds for axis 0 with size 3
Traceback (most recent call last):
File "/home/weston/object-detection//Application/object_detection.py", line 679, in drawing
y0 = int(self.app.nn_result_locations[0][i][1] * preview_height)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: index 3 is out of bounds for axis 0 with size 3
Traceback (most recent call last):
File "/home/weston/object-detection//Application/object_detection.py", line 679, in drawing
y0 = int(self.app.nn_result_locations[0][i][1] * preview_height)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: index 3 is out of bounds for axis 0 with size 3 

 

2) does tiny yolo work in stm32mpu25 for object detection , if it works can you point to README or any documentation ?

View solution in original post

16 REPLIES 16
Julian E.
ST Employee

Hello @akr1,

 

Could you share your OSTL and X linux AI version please?

 

have a good day,

Julian


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi ,

 

I am able to run objection detection now  . when i use deployment script  to deploy into target and changing scripts permissions accordingly in target.

but while running objection detection model i see below error and bounding boxes are not accurate.

Is input_shape: (224, 224, 3) is good for ssd_mobilenet_v2_fpnlite for object detection?

Same custom model runs fine when doing prediction in host pc with test images and all bounding boxes are shown correctly.

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: index 2 is out of bounds for axis 0 with size 1
Traceback (most recent call last):
File "/home/weston/object-detection//Application/object_detection.py", line 679, in drawing
y0 = int(self.app.nn_result_locations[0][i][1] * preview_height)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: index 2 is out of bounds for axis 0 with size 2
Traceback (most recent call last):
File "/home/weston/object-detection//Application/object_detection.py", line 679, in drawing
y0 = int(self.app.nn_result_locations[0][i][1] * preview_height)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: index 2 is out of bounds for axis 0 with size 2

Hello @akr1,

 

We need your OSTL and X linux AI version to help you.

Are you using the provided model or your own?

 

Have a good day,

Julian


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi,

Below are details.

root@stm32mp25-discounknownunknown:~# cat /etc/os-release
ID=openstlinux-weston
NAME="ST OpenSTLinux - Weston - (A Yocto Project Based Distro)"
VERSION="5.0.8-snapshot-20250811 (scarthgap)"
VERSION_ID=5.0.8-snapshot-20250811
VERSION_CODENAME="scarthgap"
PRETTY_NAME="ST OpenSTLinux - Weston - (A Yocto Project Based Distro) 5.0.8-snapshot-20250811 (scarthgap)"
CPE_NAME="cpe:/o:openembedded:openstlinux-weston:5.0.8-snapshot-20250811"

 

root@stm32mp25-discounknownunknown:~# x-linux-ai -v
X-LINUX-AI package repo is already set.

X-LINUX-AI version: v6.1.0

i am using  model_type: ssd_mobilenet_v2_fpnlite  with custom dataset , 

Object detection works well when i run prediction on host PC, when i am deploying using deployment script into target and run model i am seeing above issue.

let me know if you require more information.

akr1
Associate II

Hi,

Just follow up question.

WARNING: Attempting to use a delegate that only supports static-sized tensors with a graph that has dynamic-sized tensors (tensor#346 is a dynamic-sized tensor).

How to fix the above, do i miss something in configuration , when i run objection detection model with static images or live feed from camera on STM32MPU257 i see above warning.

Hello @akr1,

 

It looks like the issue you are facing comes from two separate points:

 

1. Model compatibility on MPU

  • Unlike STM32 MCUs, not all models from the Model Zoo are currently supported on STM32MPUs.
  • For object detection on MPU, only one specific model was validated internally, with a dedicated post-process coded for it. If you are using a different model (e.g. retrained or re-exported), you need to adapt the post-process to match the model’s outputs (number/order of outputs and input shape).

  • The files of interest are:
    • ssd_mobilenet_pp.py → post-process logic
    • stai_mpu_object_detection.py → main application (usually no changes needed).

 

2. Dynamic shapes not supported

  • The warning you reported (delegate that only supports static-sized tensors ... dynamic-sized tensors) indicates that your model includes dynamic tensor shapes, which are not supported on STM32MPU2 hardware.
  • All layers in the model must have static/fixed shapes. You may need to re-export your model from the Model Zoo or adjust the export scripts to ensure static dimensions.

Additional note:

The default Model Zoo object detection model for MPU is quantized per-channel. Internally, we tested per-tensor quantization (faster on MPU), but this is not available publicly. This only affects performance, not functionality.

 

Try with the official object detection model provided for MPU to confirm your setup works.

If you use a different model, re-export it with static shapes and update the ssd_mobilenet_pp.py post-process accordingly.

 

If this information does not help and you suspect it is purely a bug on our side, please let me know so that I can expose the issue to the model zoo team.

 

Have a good day,

Julian


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi Thanks for information.

I am using ssd_mobilenet_v2_fpnlite model to pretrain custom dataset.

attached user_config.yaml  used to train , preprocessing,post processing and quantization.

if i run same model (tflite) on host with prediction i don't see any issue. but if i deploy same on stm32mpu275(nbg or tflite) , i see bounding boxes are not accurate.

we are evaluating stm32mpu257 to use for object detection.

can you check attached config file and let me know if i am doing something wrong. 

Let me know if you need any additional information.

 

akr1
Associate II

Hi can you also suggest how to configure static-sized tensors?

Julian E.
ST Employee

Hello @akr1,

 

Could you share your model (in .zip), so that I can ask the dev team to look at the issue here.

 

Have a good day,

Julian


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.