Can not get correct inference result

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Can not get correct inference result

ソリューションへジャンプ
2,664件の閲覧回数
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,650件の閲覧回数
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,647件の閲覧回数
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,653件の閲覧回数
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,651件の閲覧回数
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 件の賞賛