Can not get correct inference result

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can not get correct inference result

Jump to solution
1,561 Views
lixianghan
Contributor I

I try to follow this tutorial: Getting Started with TensorFlow Lite for Microcontrollers on i.MX RT to deploy flowers classification model in i.MX RT1050-EVKB. I test the generated .tflite model following the tutorial, and get correct inference result. But I can not get correct inference result after converted .tflite to .h with xxd, and deploy it in i.MX RT1050-EVKB.

lixianghan_0-1631700697262.pnglixianghan_1-1631700720760.png

 

 

0 Kudos
1 Solution
1,547 Views
lixianghan
Contributor I

Thank you for your help! I solved this problem.

The correct python script:

------------------------------------------------------------------------------------------

import cv2
import numpy as np
img = cv2.imread('daisy.bmp')
img = cv2.resize(img, (128, 128))
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
with open('daisy.h', 'w') as fout:
    print('#define STATIC_IMAGE_NAME "daisy"', file=fout)
    print('const char daisy_bmp[] = {', file=fout)
    img.tofile(fout, '', '0x%02X')
    print('};\n', file=fout)
------------------------------------------------------------------------------------------
 
The ; in the last is important.

View solution in original post

0 Kudos
3 Replies
1,544 Views
david_piskula
NXP Employee
NXP Employee

Great! Sorry about the missing semicolon. We will make sure to update the lab guide conversion, thanks for trying it out and letting us know about it.

Have fun with eIQ.

Best Regards,

David

0 Kudos
1,550 Views
david_piskula
NXP Employee
NXP Employee

Hello @lixianghan,

thank you for your interest in eIQ. Could you please try converting your flower image with the following python script instead of xxd?:

    import cv2
    import numpy as np
    img = cv2.imread('flower.bmp')
    img = cv2.resize(img, (128, 128))
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    with open('image_data.h', 'w') as fout:
      print('static const uint8_t image_data[] = {', file=fout)
      img.tofile(fout, ', ', '0x%02X')
      print('}\n', file=fout)

 

Thanks,

David

0 Kudos
1,548 Views
lixianghan
Contributor I

Thank you for your help! I solved this problem.

The correct python script:

------------------------------------------------------------------------------------------

import cv2
import numpy as np
img = cv2.imread('daisy.bmp')
img = cv2.resize(img, (128, 128))
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
with open('daisy.h', 'w') as fout:
    print('#define STATIC_IMAGE_NAME "daisy"', file=fout)
    print('const char daisy_bmp[] = {', file=fout)
    img.tofile(fout, '', '0x%02X')
    print('};\n', file=fout)
------------------------------------------------------------------------------------------
 
The ; in the last is important.
0 Kudos