现象:第一次调用模型预测成功,第二次就报check img format err!
固件:v0.5.0-22-g7ac6b09
测试的模型来自 https://blog.sipeed.com/p/680.html ,已使用convert_le.py 转为bin烧到板子(bits with mic)里,使用的是kpu.load_flash命令
测试代码:
from fpioa_manager import fm
from machine import UART
import KPU as kpu
import sensor, image, lcd, time
import time
count = 0
lcd.init()
lcd.clear()
a = kpu.deinit(task)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing((224, 224))
sensor.set_vflip(1)
sensor.run(1)
task = kpu.load_flash(0x300000, 0, 0,80000000)
while(True):
img = sensor.snapshot()
time.sleep(1)
fmap = kpu.forward(task, img)
count += 1 #计数kpu.forward运行的次数
print("kpu.forward运行的次数:"+str(count))
plist=fmap[:]
pmax=max(plist)
max_index=plist.index(pmax)
print("预测结果"+str(max_index))
输出结果:
init i2c2
[MAIXPY]: find ov2640
True
True
True
SPI freq 80166666 Hz
kpu.forward运行的次数:1
预测结果769
[MAIXPY]kpu: img w=224,h=224, but model w=268,h=69
Traceback (most recent call last):
File "<stdin>", line 20, in <module>
ValueError: [MAIXPY]kpu: check img format err!
MicroPython v0.5.0-22-g7ac6b09 on 2020-03-04; Sipeed_M1 with kendryte-k210
Type "help()" for more information.
上一次使用了自己训练的模型,发现 img format err!,以为是模型的问题,后来测试了hub训练的模型,也报这个错误,就换了官方的mbnet模型,同样是这个问题,就怀疑是我写的代码的问题,后来看run flash的例程都是只跑一次,我就测试,就发现模型跑一次都是可以的,但是跑第二次就会报这个format err错误。