MicroPython for K210 RISC-V, let's play with edge AI easier
1.68k
stars
439
forks
source link
MemoryError: Out of Memory! Please reduce the resolution of the image you are running this algorithm on to bypass this issue! #482
Open
adelinawong opened 1 year ago
Board: m5stickv
Code:
import sensor import image import lcd import KPU as kpu
lcd.init() lcd.rotation(2) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.set_windowing((224, 224)) sensor.set_vflip(0) sensor.set_hmirror(0) sensor.run(1) lcd.clear()
lcd.draw_string(135, 0, "MobileNetDemo")
f = open('labels.txt', 'r') labels = f.readlines() f.close()
print(labels)
task = kpu.load("/sd/model.kmodel")
for image capturing
path = "/sd/images/" ext=".jpg" cnt=0 img=image.Image()
while(True): img = sensor.snapshot() fmap = kpu.forward(task, img) plist = fmap[:] pmax = max(plist) max_index = plist.index(pmax)
a = lcd.display(img, roi=(0, 0, 135, 135), oft=(0, 0))
a=lcd.display(img)
lcd.draw_string(135, 100, "%s" % (labels[max_index].strip()))
lcd.draw_string(135, 119, "%.2f" % (pmax))
if max_index==1: lcd.draw_string(135,0,"Person",lcd.RED) cnt+=1 fname=path+str(cnt)+ext img.save(fname,quality=95) print("image saved as", fname) a = kpu.deinit(task)
May I know how to reduce the resolution of the image? I tried using img.resize() but it does not work. Thank you and hope to hear from you soon!