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

ML-examples/cmsisnn-cifar10 is a bad prediction #30

Open
EdgeAI-Lab opened this issue Nov 26, 2019 · 0 comments
Open

ML-examples/cmsisnn-cifar10 is a bad prediction #30

EdgeAI-Lab opened this issue Nov 26, 2019 · 0 comments

Comments

@EdgeAI-Lab
Copy link

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;
}

but the Prediction is "Plane", I tried a lot of pictures and the predictions were not correct.

Please help me, thanks.

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

1 participant