2024-11-14 07:44 AM
Hi all, I'm playing around with STM32H747I-DISCO eval board and the stm32ai-modelzoo demo.
I've managed to train and evaluate a model with my custom dataset using the script in "image_classification\src\stm32ai_main.py"
Now I'm struggling with the deployment of the model. I tried using the deploy script in "image_classification\deployment\deploy.py" but I get the following error:
ModuleNotFoundError: No module named 'models_utils'
Any ideas what's going wrong here? The error isn't very descriptive (to me at least) so I'm a bit stuck.
Sorry if this is a simple question, coming from a Hardware and FPGA design background using VHDL where everything is very explicit and strongly typed, I really struggle with the layers of abstraction that Python libraries bring.
2024-11-14 08:34 AM - edited 2024-11-14 08:40 AM
Hello @croto ,
No worries, there are no wrong questions ^^
Just to put some context, the idea behind model zoo is to configurate the user_config.yaml to do a lot of things:
So the idea is to edit the user_config.yaml and use the python script stm32ai_main.py, not to use the deploy.py.
If you still get errors when using the stm32ai_main.py, you may consider re installing model zoo from the start:
GitHub - STMicroelectronics/stm32ai-modelzoo: AI Model Zoo for STM32 devices
Before deployment, you should consider quantizing the model (reducing the weight from float32 to int8) to gain a lot in terms of memory footprint and inference time (and lose a little in accuracy generally).
Because you retrained your own model, you should have a best_model.h5 in the /experiment_ouputs/saved_models folder.
To quantize your model, you need to edit the user_config.yaml to set the operation mode to quantize and set some other things: your model path, quantization dataset path (advised to put the training data) etc
By default, the quantization is made using the cloud, you will need to log to your ST account.
The process is explained here:
After quantization, in the experiment_output, you will get a .tflite model (tflite is tensorflow lite models, or quantized models, .h5 is tensorflow models).
Then you can look for the documentation to deploy your quantized model to the board:
Make sure to plug your board on the ST-Link-V3 plug to the PC before running the python script as it will deploy it directly on your board.
Here is the full documentation for the image_classification: stm32ai-modelzoo/image_classification at main · STMicroelectronics/stm32ai-modelzoo · GitHub
Note that with the other operation modes. You can benchmark and evaluate your model before quantization, then after to compare them for example. There are also chains operation modes to do multiple things in one go...
Do not hesitate if you have any other questions.
Have a good day,
Julian