ML-examples/cmsisnn-cifar10 is a bad prediction
EdgeAI-Lab opened this issue · comments
I use the code to convert the dog image to an array.
from PIL import Image, ImageOps
import numpy as np
np.set_printoptions(threshold=np.inf)
def resize_image(image, _width=32, _height=32):
new_image = Image.open(image)
new_image = ImageOps.fit(new_image , (_width, _height), Image.ANTIALIAS)
new_image_rgb = new_image.convert('RGB')
return np.asarray(new_image_rgb).flatten()
def print_array_for_c(_array):
print("{",end="")
for pixel in _array:
print(pixel,end=",")
print("}")
print_array_for_c(resize_image('dog.jpg'))
and then input NN
/* from the dog image conversion */
#define IMG_DATA {255,255, ... ,255,}
uint8_t image_data[3 * 32 * 32] = IMG_DATA;
q7_t output_data[10];
char const *class_names[10] = {"airplane", "automobile", "bird", "cat", "deer",
"dog", "frog", "horse", "ship", "truck"};
uint8_t get_max_index(q7_t *array,uint8_t len)
{
int max = -128;
int max_index;
for (int i = 0; i < len; i++)
{
if(max<array[i])
{
max = array[i];
max_index = i;
}
}
return max_index;
}
int main()
{
printf("start execution, wait for the result...\n");
/* start the execution */
run_nn((q7_t*)image_data,output_data);
arm_softmax_q7(output_data, 10, output_data);
for (uint8_t i = 0; i < 10; i++)
{
printf("%d: %d\n", i, output_data[i]);
}
printf("It is %s.\n",class_names[get_max_index(output_data,sizeof(output_data)/sizeof(output_data[0]))]);
return 0;
}