To fully take advantage of the capabilities of our microcontroller, we use the CMSIS-NN optimized libraries, available open source on GitHub. This tutorial uses version CMSIS 5.7.0. You will make use of CMSIS-NN, a collection of efficient neural network kernels developed to maximize the performance and minimize the memory footprint of neural networks on Arm Cortex-M processor cores.
Neural network inference based on CMSIS-NN kernels achieves 4.6X improvement in runtime/throughput and 4.9X improvement in energy efficiency. For a more detailed overview of all the optimizations refer to this article. To use the optimizations in the code you must clone the repository as follows:
cd ~/CMSISNN_Webinar git clone https://github.com/ARM-software/CMSIS_5.git
The functions being called in the
run_nn(input, output) function in the nn.cpp file is calling functions being defined in the CMSIS-NN library. Here are some examples:
arm_convolve_HWC_q7_RGB(input_data, CONV1_IN_DIM, CONV1_IN_CH, conv1_wt, CONV1_OUT_CH, CONV1_KER_DIM, CONV1_PAD, CONV1_STRIDE, conv1_bias, CONV1_BIAS_LSHIFT, CONV1_OUT_RSHIFT, buffer1, CONV1_OUT_DIM, (q15_t*)col_buffer, NULL); arm_maxpool_q7_HWC(buffer1, POOL1_IN_DIM, POOL1_IN_CH, POOL1_KER_DIM, POOL1_PAD, POOL1_STRIDE, POOL1_OUT_DIM, col_buffer, buffer2); arm_relu_q7(buffer2, RELU1_OUT_DIM*RELU1_OUT_DIM*RELU1_OUT_CH);
Now that we have optimized the model and built the complete application it's time to move on to the final step.