MaixPy Run 20-classes object detection based on tiny-yolov2 in 30 lines~


#1

Here is the demo run tiny-yolo v2 to do 20-class classifier
Firmware and kmodel: (the model is half-cooked)
maixpy_20class.zip (2.8 MB)

Flash the firmware and model, run the code:

import sensor,image,lcd,time
import KPU as kpu

lcd.init(freq=15000000)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_vflip(1)
sensor.run(1)
clock = time.clock()
classes = ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor']
task = kpu.load(0x500000) 
anchor = (1.08, 1.19, 3.42, 4.41, 6.63, 11.38, 9.42, 5.11, 16.62, 10.52)
a = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor)
while(True):
    clock.tick()
    img = sensor.snapshot()
    code = kpu.run_yolo2(task, img)
    print(clock.fps())
    if code:
        for i in code:
            a=img.draw_rectangle(i.rect())
            a = lcd.display(img)
            for i in code:
                lcd.draw_string(i.x(), i.y(), classes[i.classid()], lcd.RED, lcd.WHITE)
                lcd.draw_string(i.x(), i.y()+12, '%f1.3'%i.value(), lcd.RED, lcd.WHITE)
    else: 	
        a = lcd.display(img)
a = kpu.deinit(task)

Default fps is about 19fps, turbo CPU/KPU freq to get higher performance.


#2

Errors I experienced: (using: maixpy_v0.3.1_full)

task = kpu.load(0x500000) # “ValueError: [MAIXPY]kpu: load error -2”

v=-1, flag=-1, arch=-1, layer len=-1, mem=-1, out cnt=-1
err: we only support V3 now, get V-1 ???

I Flashed: maixpy_20class.bin


#3

please use the firmware in this post, we didn’t merge it to github now


#4

I Flashed: maixpy_20class.bin


#5

yes, and then burn the kmodel inside


#6

Minor code adjustment, formatting for float draw_string:

‘%1.2f’