cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to get proper output for MNIST digit recognition CNN Implementation using Keras and STM32Cube AI.

MJog.1
Associate II

I'm trying to Implement basic MNIST Handwritten Digit recognition Model on STM32F769 DISC1 kit using STM Cube AI.

Here are the steps I followed.

  1. Took a standard MNIST Digit recognition model from here https://colab.research.google.com/github/trekhleb/machine-learning-experiments/blob/master/experiments/digits_recognition_cnn/digits_recognition_cnn.ipynb

It is provided by google colab.

2. downloaded the .h5 file

3 Created the project using STM32CUBE MX, in that included the STM32 CUBE AI Software pack. Included the core and selected application as 'application template'

4 Using keeping other initializations default and selecting clock frequency 216 MHz, I generated the code.

5 kept main program untouched (where MX_X_CUBE_AI_Process(); is called in while(1) loop.

6 in app_x-cube-ai.c file made the modifications as told in 'Embedded Interface Client API' in documentation.

Here I have no device to actually record the handwritten digit, therefore I copied one of the training dataset sample manually from ipython notebook and saved it in array in app_x-cube-ai.c file. Note that my training was done for the values originally 0 to 255 normalized to 0 to 1.

as stated ,I saved the pixel values for one of the digit in an array called 'imgarray' which is equal to the size 28 x 28. the datatype of 'imgarray' i kept as ai_double.

7 on running the inference in debug mode, I found the output (which were stored in an array out_data[10].) unsatisfactory.

8 moreover, the most concerning this is that even if i changed the value of 'imgarray' with pixel values of different digit, the output result in the 'out_data' array REMAINS EXACTLY THE SAME

Is there anything that I'm doing wrong fundamentally.

Request my fellow developers on STCommunity to guide me.

1 REPLY 1
Bartosz BORYNA
Associate III

Did you use proper input tensor format ? Please see following excerpt of mentioned google colab description:

"In order to use convolution layers we need to reshape our data and add a color channel to it. As you've noticed currently every digit has a shape of `(28, 28)` which means that it is a 28x28 matrix of color values form `0` to `255`. We need to reshape it to `(28, 28, 1)` shape so that each pixel potentially may have multiple channels (like Red, Green and Blue)."

Another, quite common problem is the order of the tensor shape size when feeding the NN.

Best regards,

Bartosz