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

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.

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

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

I Flashed: maixpy_20class.bin

yes, and then burn the kmodel inside

Minor code adjustment, formatting for float draw_string:

‘%1.2f’

Dear Zepan,

Do you mean I have to replace maixpy_v0.3.2_full.bin by maixpy_20class.bin?

He says you have to flash the stripped down version of MaixPy to make room for the model (openmv is eliminated)

The same stripped down version works with 2 other demos, Face detect and the 1000 class MobileNet demo.

The 20class.kmodel can be stored on SD card with a little code change, Allowing 2 different demos, with the Face detect demo model living in Flash.

Is there any source code available how this model was trained, and quantised to run on the K210 for these 20 classes?

How could i change the model to count objects, like cars?