Can not get correct inference result

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Can not get correct inference result

跳至解决方案
2,667 次查看
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 项奖励
1 解答
2,653 次查看
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 项奖励
3 回复数
2,650 次查看
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 项奖励
2,656 次查看
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 项奖励
2,654 次查看
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 项奖励