2025-05-16 4:10 PM
I am attempting to deploy an sklearn RandomForestClassifier on a STM32H7 using ST Edge AI.
I am using the following function to export the RandomForestClassifier to ONNX:
My call to the stedgeai cli is:
`network_val_m_outputs_2.csv`
Next, I repeated the above experiment using a sklearn DecisionTreeClassifier. I found that the ouputs in c matched the original model both compiled by stedgeai and in python.
I am looking for support to successfully convert and deploy the RandomForestClassifier to my stm32h7 device. If anyone has experience with this deployment I would appreciate the help.
Solved! Go to Solution.
2025-05-21 5:38 AM
Hello @djvodasafe,
The ONNX model and the C version coming from the ST Edge AI Core are not byte to byte exact.
When you run your validate on host (PC) you compare the execution of the ONNX model (python) and the C version. You probably will see differences because the kernels are not the exact same for optimization purposes I believe.
If you do a validate on target (your STM32), it compares the C code on the pc (x86) and C code for STM32 (cortexM). Here also you may see differences because of compilation flags and optimization done by arm.
The goal here is to check the COS metric that you should have when running a validate and have a value close to 1 (meaning around 0.99, 0.9 is bad). If you have that it means that the results are very close.
The results you will get depends on the model you use and how it is converted to C.
In your case, the DecisionTreeClassifier probably gives a COS of 1 if you see the exact same results.
For your RandomForestClassifier, you want to test ,with real data if possible, if you get a similar accuracy/a good COS. If you do, then it is fine, even if the results are not identical. If you don't, you probably need to retrain/change model.
Have a good day,
Julian
2025-05-21 5:38 AM
Hello @djvodasafe,
The ONNX model and the C version coming from the ST Edge AI Core are not byte to byte exact.
When you run your validate on host (PC) you compare the execution of the ONNX model (python) and the C version. You probably will see differences because the kernels are not the exact same for optimization purposes I believe.
If you do a validate on target (your STM32), it compares the C code on the pc (x86) and C code for STM32 (cortexM). Here also you may see differences because of compilation flags and optimization done by arm.
The goal here is to check the COS metric that you should have when running a validate and have a value close to 1 (meaning around 0.99, 0.9 is bad). If you have that it means that the results are very close.
The results you will get depends on the model you use and how it is converted to C.
In your case, the DecisionTreeClassifier probably gives a COS of 1 if you see the exact same results.
For your RandomForestClassifier, you want to test ,with real data if possible, if you get a similar accuracy/a good COS. If you do, then it is fine, even if the results are not identical. If you don't, you probably need to retrain/change model.
Have a good day,
Julian