Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Errors and Improper Inference for Patch-Based Inference #102

Open
goats-9 opened this issue Apr 16, 2024 · 7 comments
Open

Build Errors and Improper Inference for Patch-Based Inference #102

goats-9 opened this issue Apr 16, 2024 · 7 comments

Comments

@goats-9
Copy link

goats-9 commented Apr 16, 2024

I am trying to run the inference tutorial on STM32Cube IDE 1.5.0 as documented in the repo. However, on generating code using the script examples/vww_patchbased.py and moving the generated folder codegen to the inference project folder tutorial/TinyEngine_vww_tutorial/Src/TinyEngine, the following errors are seen in the IDE.

Description	Resource	Path	Location	Type
make: *** [makefile:88: TTE_demo_mcunet.elf] Error 1	TTE_demo_mcunet		 	C/C++ Problem
more undefined references to `arm_nn_requantize' follow	depthwise_kernel3x3_stride2_inplace_CHW.c	/TTE_demo_mcunet/Src/TinyEngine/codegen/Source	line 139	C/C++ Problem
undefined reference to `arm_nn_mat_mult_kernel_s8_s16_reordered'	convolve_1x1_s8.c	/TTE_demo_mcunet/Src/TinyEngine/src/kernels/int_forward_op	line 69	C/C++ Problem
undefined reference to `arm_nn_requantize'	depthwise_kernel3x3_stride1_inplace_CHW.c	/TTE_demo_mcunet/Src/TinyEngine/codegen/Source	line 110	C/C++ Problem
undefined reference to `arm_nn_requantize'	depthwise_kernel3x3_stride1_inplace_CHW.c	/TTE_demo_mcunet/Src/TinyEngine/codegen/Source	line 116	C/C++ Problem
undefined reference to `arm_nn_requantize'	depthwise_kernel3x3_stride1_inplace_CHW.c	/TTE_demo_mcunet/Src/TinyEngine/codegen/Source	line 139	C/C++ Problem
undefined reference to `arm_nn_requantize'	depthwise_kernel3x3_stride2_inplace_CHW.c	/TTE_demo_mcunet/Src/TinyEngine/codegen/Source	line 110	C/C++ Problem
undefined reference to `arm_nn_requantize'	depthwise_kernel3x3_stride2_inplace_CHW.c	/TTE_demo_mcunet/Src/TinyEngine/codegen/Source	line 116	C/C++ Problem

IDE console output is below.

image

Do let me know if any other data is required.

@goats-9
Copy link
Author

goats-9 commented Apr 19, 2024

There is a workaround to build the patch-based inference codebase.

Note: The following steps have to be done after cloning the repo and installing the python packages necessary.

  1. Copy arm_nn_mat_mult_kernel_s8_s16_reordered.c from the CMSIS library to TinyEngine/src. Execute the below command from the root of the repo.
cp TinyEngine/third_party/CMSIS/CMSIS/NN/Source/ConvolutionFunctions/arm_nn_mat_mult_kernel_s8_s16_reordered.c TinyEngine/src/kernels/int_forward_op/
  1. Modify tinyengine_function.h as shown below.
diff --git a/TinyEngine/include/tinyengine_function.h b/TinyEngine/include/tinyengine_function.h
index 55f379c..bb4ed0b 100644
--- a/TinyEngine/include/tinyengine_function.h
+++ b/TinyEngine/include/tinyengine_function.h
@@ -17,6 +17,9 @@
  * Target ISA:  ARMv7E-M
  * -------------------------------------------------------------------- */

+#include "arm_nnfunctions.h"
+#include "arm_nnsupportfunctions.h"
+
 #include <math.h>
 #include <stdbool.h>
 #include <stdint.h>

However, on running the code on the board, I am unable to get an inference result (using mcunet-vww1), with the network always predicting No Person even when a person is displayed to the camera. I am unsure if these changes are the cause of wrong inference.

@rahulvigneswaran
Copy link

@goats-9

Copy arm_nn_mat_mult_kernel_s8_s16_reordered.c from the CMSIS library to TinyEngine/src. Execute the below command from the root of the repo.

Simply renaming the function arm_nn_mat_mult_kernel_s8_s16_reordered in convolve_1x1_s8.c to arm_nn_mat_mult_kernel_s8_s16_reordered_8mul does the trick.

@goats-9
Copy link
Author

goats-9 commented Apr 23, 2024

@rahulvigneswaran

Thanks for the reply. We tried renaming the function to both _8mul and oddch prefixes already, but inference results did not improve. We believe the issue may be among the following.

  1. Code generation for patch-based inference (in examples/vww_patchbased.py)
  2. Models are not pretrained (which is very unlikely looking at the results published by the authors).

Nevertheless, I will add these inputs to the workarounds stated above.

@goats-9 goats-9 changed the title Build Errors for Patch-Based Inference Build Errors and Improper Inference for Patch-Based Inference Apr 23, 2024
@rahulvigneswaran
Copy link

@goats-9

Building upon your insights, we've explored additional strategies, yet encountered persistent issues. Here's a summary:

  • Experimented with diverse patch grid configurations.
  • Set the 'inplace' parameter to False.

While these adjustments occasionally impact prediction outcomes, the issue of classifying 'person' and 'no person' as the same remains consistent.

@Oslomayor
Copy link

Oslomayor commented Oct 3, 2024

@meenchen I am trying the tutorial(vww patchbased) and also getting the same build errors.
I do as @goats-9 shown above,

  1. Modify tinyengine_function.h
+#include "arm_nnfunctions.h"
+#include "arm_nnsupportfunctions.h"

 #include <math.h>
 #include <stdbool.h>
 #include <stdint.h>
  1. Renaming the function arm_nn_mat_mult_kernel_s8_s16_reordered in convolve_1x1_s8.c to arm_nn_mat_mult_kernel_s8_s16_reordered_8mul.

Finally, I build the project successfully but get wrong inference result as shown in the picture below.
inference_error_20241003155606

@winffke
Copy link

winffke commented Oct 28, 2024

@Oslomayor
I would like to know if you have fully resolved the build issue mentioned there. I have encountered the same problem, I hope to get your guidance on this issue. I would appreciate any further details you can provide.

Thank you for your assistance!

Best regards

@Oslomayor
Copy link

@winffke I have no solution, good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants