Skip to content

Commit 46924c0

Browse files
committed
Updates:
- Added print log for external tools used - Removed old parts of code related to STEDGEAI 9.0, which is no longer supported - Implemented missing evaluation on target functionality - Updated documentation and added a "how-to" guide for evaluation on target Signed-off-by: khaoula boutiche <[email protected]>
1 parent 1dc52d8 commit 46924c0

File tree

27 files changed

+1202
-232
lines changed

27 files changed

+1202
-232
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Please find below some tutorials for a quick ramp up!
116116
* [How can I fine tune a pretrained model on my own dataset?](./image_classification/deployment/doc/tuto/how_to_finetune_a_model_zoo_model_on_my_own_dataset.md)
117117
* [How can I check the accuracy after quantization of my model?](./image_classification/deployment/doc/tuto/how_to_compare_the_accuracy_after_quantization_of_my_model.md)
118118
* [How can I quickly check the performance of my model using the dev cloud?](./image_classification/deployment/doc/tuto/how_to_quickly_benchmark_the_performances_of_a_model.md)
119-
119+
* [How can I evaluate my model on STM32N6 target?](./image_classification/deployment/doc/tuto/how_to_evaluate_my_model_on_stm32n6_target.md)
120120

121121
Image Classification top readme **[here](./image_classification/README.md)**
122122

@@ -137,7 +137,7 @@ Object detection is used to detect, locate and estimate the occurrences probabil
137137
| [SSD MobileNet v2 fpn lite 1.0](https://github.com/STMicroelectronics/stm32ai-modelzoo/blob/master/object_detection/ssd_mobilenet_v2_fpnlite/README.md) | 256x256x3<br> 416x416x3 | Full OD Services | [STM32MP257F-EV1](./application_code/object_detection/STM32MP-LINUX/STM32MP2/README.md) <br> [STM32N6570-DK](https://www.st.com/en/development-tools/stm32n6-ai.html)<br> |
138138
| [ST Yolo LC v1](https://github.com/STMicroelectronics/stm32ai-modelzoo/blob/master/object_detection/st_yolo_lc_v1/README.md) | 192x192x3<br> 224x224x3<br> 256x256x3<br> | Full OD Services | [STM32H747I-DISCO](application_code/object_detection/STM32H7/Application/STM32H747I-DISCO) with B-CAMS-OMV camera daughter board<br> |
139139
| [Tiny Yolo v2](https://github.com/STMicroelectronics/stm32ai-modelzoo/blob/master/object_detection/tiny_yolo_v2/README.md) | 224x224x3<br> 416x416x3<br> | Full OD Services | [STM32N6570-DK](https://www.st.com/en/development-tools/stm32n6-ai.html)<br> |
140-
| [ST Yolo X](https://github.com/STMicroelectronics/stm32ai-modelzoo/blob/master/object_detection/st_yolo_x/README.md) | 256x256x3<br> 416x416x3<br> | Full OD Services | [STM32N6570-DK](https://www.st.com/en/development-tools/stm32n6-ai.html)<br> |
140+
| [ST Yolo X](https://github.com/STMicroelectronics/stm32ai-modelzoo/blob/master/object_detection/st_yolo_x/README.md) | 256x256x3<br> 320x320x3<br> 416x416x3<br> 480x480x3<br> | Full OD Services | [STM32N6570-DK](https://www.st.com/en/development-tools/stm32n6-ai.html)<br> |
141141
| [Yolo v8](https://github.com/stm32-hotspot/ultralytics/tree/main/examples/YOLOv8-STEdgeAI/stedgeai_models/object_detection) <br> Yolo v5u | 192x192x3<br> 256x256x3<br> 320x320x3<br> 416x416x3<br> | Evaluation / Benchmarking / Prediction / Deployment | [STM32N6570-DK](https://www.st.com/en/development-tools/stm32n6-ai.html)<br> |
142142

143143

@@ -157,6 +157,7 @@ Please find below some tutorials for a quick ramp up!
157157
* [How can I check the accuracy after quantization of my model?](./object_detection/deployment/doc/tuto/how_to_compare_the_accuracy_after_quantization_of_my_model.md)
158158
* [How can I quickly check the performance of my model using the dev cloud?](./object_detection/deployment/doc/tuto/how_to_quickly_benchmark_the_performances_of_a_model.md)
159159
* [How can I quantize, evaluate and deploy an Ultralytics Yolov8 model?](./object_detection/deployment/doc/tuto/How_to_deploy_yolov8_yolov5_object_detection.md)
160+
* [How can I evaluate my model on STM32N6 target?](./object_detection/deployment/doc/tuto/how_to_evaluate_my_model_on_stm32n6_target.md)
160161

161162
Object Detection top readme **[here](./object_detection/README.md)**
162163

@@ -194,6 +195,7 @@ Please find below some tutorials for a quick ramp up!
194195
* [How can I check the accuracy after quantization of my model?](./pose_estimation/deployment/doc/tuto/how_to_compare_the_accuracy_after_quantization_of_my_model.md)
195196
* [How can I quickly check the performance of my model using the dev cloud?](./pose_estimation/deployment/doc/tuto/how_to_quickly_benchmark_the_performances_of_a_model.md)
196197
* [How can I deploy an Ultralytics Yolov8 pose estimation model?](./pose_estimation/deployment/doc/tuto/How_to_deploy_yolov8_pose_estimation.md)
198+
* [How can I evaluate my model on STM32N6 target?](./pose_estimation/deployment/doc/tuto/how_to_evaluate_my_model_on_stm32n6_target.md)
197199

198200
Pose Estimation top readme **[here](./pose_estimation/README.md)**
199201

@@ -227,6 +229,7 @@ Please find below some tutorials for a quick ramp up!
227229
* [How can I fine tune a pretrained model on my own dataset?](./semantic_segmentation/deployment/doc/tuto/how_to_finetune_a_model_zoo_model_on_my_own_dataset.md)
228230
* [How can I check the accuracy after quantization of my model?](./semantic_segmentation/deployment/doc/tuto/how_to_compare_the_accuracy_after_quantization_of_my_model.md)
229231
* [How can I quickly check the performance of my model using the dev cloud?](./semantic_segmentation/deployment/doc/tuto/how_to_quickly_benchmark_the_performances_of_a_model.md)
232+
* [How can I evaluate my model on STM32N6 target?](./semantic_segmentation/deployment/doc/tuto/how_to_evaluate_my_model_on_stm32n6_target.md)
230233

231234
Semantic Segmentation top readme **[here](./semantic_segmentation/README.md)**
232235

@@ -286,6 +289,7 @@ Please find below some tutorials for a quick ramp up!
286289
* [How can I evaluate my model before and after quantization?](./audio_event_detection/deployment/doc/tuto/how_to_compare_the_accuracy_after_quantization_of_my_model.md)
287290
* [How can I quickly check the performance of my model using the dev cloud?](./audio_event_detection/deployment/doc/tuto/how_to_quickly_benchmark_the_performances_of_a_model.md)
288291
* [How can I deploy my model?](./audio_event_detection/deployment/doc/tuto/how_to_deploy_a_model_on_a_target.md)
292+
* [How can I evaluate my model on STM32N6 target?](./audio_event_detection/deployment/doc/tuto/how_to_evaluate_my_model_on_stm32n6_target.md)
289293

290294
Audio Event Detection top readme **[here](./audio_event_detection/README.md)**
291295

audio_event_detection/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ Don't forget to follow our tuto below for a quick ramp up :
3939
* [How can I evaluate my model before and after quantization?](../audio_event_detection/deployment/doc/tuto/how_to_compare_the_accuracy_after_quantization_of_my_model.md)
4040
* [How can I quickly check the performance of my model using the dev cloud?](../audio_event_detection/deployment/doc/tuto/how_to_quickly_benchmark_the_performances_of_a_model.md)
4141
* [How can I deploy my model?](../audio_event_detection/deployment/doc/tuto/how_to_deploy_a_model_on_a_target.md)
42+
* [How can I evaluate my model on STM32N6 target?](../audio_event_detection/deployment/doc/tuto/how_to_evaluate_my_model_on_stm32n6_target.md)
4243

4344
Remember that minimalistic yaml files are available [here](./src/config_file_examples/) to play with specific services, and that all pre-trained models in the [STM32 model zoo](https://github.com/STMicroelectronics/stm32ai-modelzoo/) are provided with their configuration .yaml file used to generate them. These are very good starting points to start playing with!
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# How to evaluate my model on STM32N6 target?
2+
3+
The evaluation of a model consists in running several inferences on a representative test set in order to get a quality metric of the model, like the accuracy, the mAP, the OKS or any other depending on the UC. This evaluation can be done on :
4+
- "host" using TensorFlow or ONNX Run Times and executed on the host machine.
5+
- "stedgeai_host" using a DLL containing emulated STM32 kernels implementation and executed on the host machine
6+
- "stedgeai_n6" using a generic test application and executed on the STM32N6 target
7+
8+
9+
## Environment setup:
10+
The evaluation on the target requires installation and configuration of ST Edge AI Core you can find here :
11+
- [ST Edge AI Core](https://www.st.com/en/development-tools/stedgeai-core.html)
12+
- [STM32CubeIDE](https://www.st.com/en/development-tools/stm32cubeide.html)
13+
14+
A few configurations are required, please find below an example following a standard installation of STEdgeAI_Core v2.0.
15+
16+
- The 'C:/ST/STEdgeAI_Core/2.0/scripts/N6_scripts/config_n6.json' file should be updated to configure the N6 loader.
17+
```json
18+
{
19+
// The 2lines below are _only used if you call n6_loader.py ALONE (memdump is optional and will be the parent dir of network.c by default)
20+
"network.c": "C:/ST/STEdgeAI_Core/2.0/script/N6_scripts/st_ai_output/network.c",
21+
//"memdump_path": "C:/Users/foobar/CODE/stm.ai/stm32ai_output",
22+
// Location of the "validation" project + build config name to be built (if applicable)
23+
// If using the provided project, valid build_conf names are "N6-DK" (CR5 boards), "N6-DK-legacy" (older-than-CR5-boards); "N6-Nucleo" can also be used for IAR project.
24+
"project_path": "C:/ST/STEdgeAI_Core/2.0/Projects/STM32N6570-DK/Applications/NPU_Validation",
25+
"project_build_conf": "N6-DK",
26+
// Skip programming weights to earn time (but lose accuracy) -- useful for performance tests
27+
"skip_external_flash_programming": false,
28+
"skip_ram_data_programming": false
29+
}
30+
```
31+
- The 'C:/ST/STEdgeAI_Core/2.0/scripts/N6_scripts/config.json' file should be updated to indicate the paths to find the external tools.
32+
```json
33+
{
34+
// Set Compiler_type to either gcc or iar
35+
"compiler_type": "iar",
36+
// Set Compiler_binary_path to your bin/ directory where IAR or GCC can be found
37+
// If "Compiler_type" == gcc, then gdb_server_path shall point to where ST-LINK_gdbserver.exe can be found
38+
"gdb_server_path": "C:/ST/STM32CubeIDE_1.17.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.2.0.202409170845/tools/bin/",
39+
"gcc_binary_path": "C:/ST/STM32CubeIDE_1.17.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.12.3.rel1.win32_1.1.0.202410251130/tools/bin/",
40+
"iar_binary_path": "C:/Program Files/IAR Systems/Embedded Workbench 9.1/common/bin/",
41+
// Full path to arm-none-eabi-objcopy.exe
42+
"objcopy_binary_path": "C:/ST/STM32CubeIDE_1.17.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.12.3.rel1.win32_1.1.0.202410251130/tools/bin/arm-none-eabi-objcopy.exe",
43+
// Cube Programmer binary path
44+
"cubeProgrammerCLI_binary_path": "C:/Program Files/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI.exe",
45+
"cubeide_path":"C:/ST/STM32CubeIDE_1.17.0/STM32CubeIDE"
46+
}
47+
```
48+
Please refer to [stedge ai core getting started on how to evaluate a model on STM32N6 board](https://stedgeai-dc.st.com/assets/embedded-docs/stneuralart_getting_started.html#ref_tools_config_n6l_json) for more information on how it works and on the setup.
49+
50+
51+
## Before launching the stm32ai_eval_on_target.py script:
52+
The script to be used for the evaluation on target is taking as parameter a configuration file. The one to use and to adapt is [evaluation_on_target_config.yaml](../../../src/config_file_examples/evaluation_on_target_config.yaml) in config_file_examples folder.
53+
Below are the main parameters to define.
54+
In the general section:
55+
* The `model_path` : path to the model you want to evaluate.
56+
* The `config_path` : yaml configurationof the model you want to evaluate as it contains some information of the model itself, on the pre-processing or other required informations.
57+
* The `dataset_path` : path to the representative dataset for the evaluation. When running on the target, it should be of reasonable size because the inputs are transfered from the host to the target so the evaluation could take time.
58+
59+
In the parameters section:
60+
* `profile` : This relates to the user_neuralart.json file that contains various profiles the memory mapping and the compiler options. This is for advanced users and `profile_O3` is very good to start with. More information in [this article](https://stedgeai-dc.st.com/assets/embedded-docs/stneuralart_neural_art_compiler.html#ref_built_in_tool_profiles).
61+
* `input_type` : This is the input type provided by the pipeline, before entering the model. In this use case, this can be set to int8 as this is the expected audio input format.
62+
* `output_type` : This is the output type expected for the post processing, after model execution. This can be set to float32 here.
63+
* `input_chpos` : This refers to the input data layout (NHWC vs NCHW). As this is an onnx model and don't want to change the layout, this can be set to chfirst.
64+
* `output_chpos` : This refers to the output data layout (NHWC vs NCHW). Here as well, for consistency this should be set to chfirst.
65+
* `evaluation_target` : This is to set the type of evaluation (host, STM32 emulated on host, or on STM32N6 HW)
66+
67+
Please refer to the online documentation on the [I/O data type or layout changes](https://stedgeai-dc.st.com/assets/embedded-docs/how_to_change_io_data_type_format.html) for more information.
68+
In the Tools section:
69+
* `path_to_stedgeai` : This the path of the stedgeai core executable
70+
* `path_to_loader` : This is the path to the loader in charge of initializing the memories and loading the model and FW on the N6 device.
71+
72+
```yaml
73+
general:
74+
model_path: ../../stm32ai-modelzoo/audio_event_detection/yamnet/ST_pretrainedmodel_public_dataset/esc10/yamnet_1024_64x96_tl/yamnet_1024_64x96_tl_qdq_int8.onnx
75+
config_path: ../../stm32ai-modelzoo/audio_event_detection/yamnet/ST_pretrainedmodel_public_dataset/esc10/yamnet_1024_64x96_tl/yamnet_1024_64x96_tl.yaml
76+
training_audio_path: ../../stm32ai-modelzoo-services/audio_event_detection/datasets/ESC-50-master/audio
77+
training_csv_path: ../../stm32ai-modelzoo-services/audio_event_detection/datasets/ESC-50-master/meta/esc50.csv
78+
79+
parameters:
80+
profile: profile_O3
81+
input_type: int8 # int8 / uint8 / float32
82+
output_type: float32 # int8 / uint8 / float32
83+
input_chpos: chfirst # chlast / chfirst
84+
output_chpos: chfirst # chlast / chfirst
85+
evaluation_target: stedgeai_n6 # host, stedgeai_host, stedgeai_n6
86+
87+
tools:
88+
stedgeai:
89+
path_to_stedgeai: C:/ST/STEdgeAI_Core/2.0/Utilities/windows/stedgeai.exe
90+
path_to_loader: C:/ST/STEdgeAI_Core/2.0/scripts/N6_scripts/n6_loader.py
91+
92+
hydra:
93+
verbose: false
94+
job_logging:
95+
level: ERROR
96+
output_subdir: null
97+
run:
98+
dir: ./experiments_outputs
99+
```
100+
101+
102+
## Run the script:
103+
Edit the evaluation_on_target_config.yaml as explained above then open a CMD (make sure to be in the application folder containing the stm32ai_eval_on_target.py script). Finally, run the command:
104+
105+
```powershell
106+
python stm32ai_eval_on_target.py --config-path ./src/config_file_examples --config-name evaluation_on_target_config.yaml
107+
```
108+
You can also use any .yaml file using command below:
109+
```powershell
110+
python stm32ai_eval_on_target.py --config-path=path_to_the_folder_of_the_yaml --config-name=name_of_your_yaml_file
111+
```
112+
113+
## Script outcome:
114+
Close to the end of the log, you will see patch and clip accuracy results for the evaluation of your model, based on the dataset you used.
115+
116+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
general:
2+
model_path: ../../stm32ai-modelzoo/audio_event_detection/yamnet/ST_pretrainedmodel_public_dataset/esc10/yamnet_1024_64x96_tl/yamnet_1024_64x96_tl_qdq_int8.onnx
3+
config_path: ../../stm32ai-modelzoo/audio_event_detection/yamnet/ST_pretrainedmodel_public_dataset/esc10/yamnet_1024_64x96_tl/yamnet_1024_64x96_tl.yaml
4+
training_audio_path: ../../stm32ai-modelzoo-services/audio_event_detection/datasets/ESC-50-master/audio
5+
training_csv_path: ../../stm32ai-modelzoo-services/audio_event_detection/datasets/ESC-50-master/meta/esc50.csv
6+
7+
parameters:
8+
profile: profile_O3
9+
input_type: int8 # int8 / uint8 / float32
10+
output_type: float32 # int8 / uint8 / float32
11+
input_chpos: chfirst # chlast / chfirst
12+
output_chpos: chfirst # chlast / chfirst
13+
evaluation_target: stedgeai_n6 # host, stedgeai_host, stedgeai_n6
14+
15+
tools:
16+
stedgeai:
17+
path_to_stedgeai: C:/ST/STEdgeAI_Core/2.0/Utilities/windows/stedgeai.exe
18+
path_to_loader: C:/ST/STEdgeAI_Core/2.0/scripts/N6_scripts/n6_loader.py
19+
20+
hydra:
21+
verbose: false
22+
job_logging:
23+
level: ERROR
24+
output_subdir: null
25+
run:
26+
dir: ./experiments_outputs
27+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# /*---------------------------------------------------------------------------------------------
2+
# * Copyright (c) 2022 STMicroelectronics.
3+
# * All rights reserved.
4+
# * This software is licensed under terms that can be found in the LICENSE file in
5+
# * the root directory of this software component.
6+
# * If no LICENSE file comes with this software, it is provided AS-IS.
7+
# *--------------------------------------------------------------------------------------------*/
8+
9+
10+
import hydra
11+
from omegaconf import DictConfig
12+
import os
13+
import sys
14+
#SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
15+
#sys.path.append(os.path.dirname(SCRIPT_DIR))
16+
sys.path.append(os.path.join(os.path.dirname(__file__), '../common/evaluation'))
17+
from on_target_evaluation import gen_load_val
18+
19+
20+
@hydra.main(config_path="./src/config_file_examples", config_name="evaluation_on_target_config", version_base=None)
21+
def main(cfg: DictConfig) -> None:
22+
"""
23+
Generates the model to be flashed on the stm32n6 device using stedgeai core,
24+
then loads it and validates in on the device if required.
25+
26+
Args:
27+
cfg: Configuration dictionary.
28+
29+
Returns:
30+
None
31+
"""
32+
33+
# Configuration information extraction
34+
model_path = os.path.realpath(cfg.general.model_path)
35+
yaml_path = os.path.dirname(os.path.realpath(cfg.general.config_path))
36+
yaml_name = os.path.basename(os.path.realpath(cfg.general.config_path))
37+
training_audio_path = os.path.realpath(cfg.general.training_audio_path)
38+
training_csv_path = os.path.realpath(cfg.general.training_csv_path)
39+
evaluation_target = cfg.parameters.evaluation_target
40+
41+
# Generates the model to be loaded on the stm32n6 device using stedgeai core,
42+
# then loads it and validates in on the device if required.
43+
gen_load_val(cfg)
44+
45+
# Launches evaluation on the target through the model zoo evaluation service
46+
os.chdir(os.path.dirname(os.path.realpath(__file__)))
47+
os.chdir('./src')
48+
main_exec_command = f'python stm32ai_main.py --config-path {yaml_path} --config-name {yaml_name}'
49+
os.system(f'{main_exec_command} ++operation_mode=evaluation ++general.num_threads_tflite=8 ++general.gpu_memory_limit=2 ++general.display_figures=False ++evaluation.target={evaluation_target.lower()} ++general.model_path={model_path} ++dataset.training_audio_path={training_audio_path} ++dataset.training_csv_path={training_csv_path} ')
50+
51+
52+
if __name__ == '__main__':
53+
main()
54+
55+

0 commit comments

Comments
 (0)