Custom create kmodel file not loading

I get tine yolo v3 .h5 file from here - https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/yolo-tiny.h5

After I get I followed this Train, Convert, Run MobileNet on Sipeed MaixPy and MaixDuino ! article steps and I created kmodel file.

Then I use the following 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 = ['person',  'bicycle',  'car', 'motorcycle', 'airplane', 'bus', 'train',  'truck',  'boat',  'traffic light',  'fire hydrant', 'stop_sign', 'parking meter',   'bench',   'bird',   'cat',   'dog',   'horse',   'sheep',   'cow',   'elephant',   'bear',   'zebra', 'giraffe',   'backpack',   'umbrella',   'handbag',   'tie',   'suitcase',   'frisbee',   'skis',   'snowboard', 'sports ball',  'kite',   'baseball bat',   'baseball glove',   'skateboard',   'surfboard',   'tennis racket', 'bottle',   'wine glass',   'cup',   'fork',   'knife',   'spoon',   'bowl',   'banana',   'apple',   'sandwich',   'orange', 'broccoli',   'carrot',   'hot dog',   'pizza',   'donot',   'cake',   'chair',   'couch',   'potted plant',   'bed', 'dining table',   'toilet',   'tv',   'laptop',   'mouse',   'remote',   'keyboard',   'cell phone',   'microwave',   'oven', 'toaster',   'sink',   'refrigerator',   'book',   'clock',   'vase',   'scissors',   'teddy bear',   'hair dryer',   'toothbrush']
task = kpu.load("/sd/yolot.kmodel")
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)

when I run the code it says

Traceback (most recent call last):
File “”, line 13, in
ValueError: b>>>

The error message also aspire

image

What is the problem with it? Is it a problem with .h5 file?

Also, above mentioned Train, Convert, Run MobileNet on Sipeed MaixPy and MaixDuino ! article kmodel also not working for me. Some other yolo 20 class, yolo face detection, MNIST kmodels are working for me.

What is the problem?

can you run demo code correctly? it seems camera not init ok

Hi, please try changing the path from “/sd/yolot.kmodel” to “yolot.kmodel”. This seemed to work for me

I was having the same problem. The most interesting thing is, I can run the script well with the original 20class.kmodel file but I can’t get any image from the camera when I flashed my custom model. Also, it does not have any error messages generated. Why is that?

can you show the code and run message?

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

lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing((224, 224))
sensor.set_vflip(1)
sensor.set_hmirror(1)
sensor.run(1)
clock=time.clock()
classes = [“car”]
task = kpu.load(0x600000)
anchor = (0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828)
a = kpu.init_yolo2(task, 0.3, 0.3, 5, anchor)
while(True):
clock.tick()
img = sensor.snapshot()
#.rotation_corr(z_rotation=90.0)
#a = img.pix_to_ai()
code = kpu.run_yolo2(task, img)
if code:
for i in code:
a=img.draw_rectangle(i.rect(),color = (0, 255, 0))
a = img.draw_string(i.x(),i.y(), classes[i.classid()], color=(255,0,0), scale=3)
a = lcd.display(img)
else:
a = lcd.display(img)
a = kpu.deinit(task)

The run message is:

init i2c2
[MAIXPY]: find ov7740
True
True
True

But there is no images captured.
No error code is generated

you can add print to debug which line it stuck at

tips: you can type ‘~~~’, before and after code, it will let code format readable

print("hello world")

Ok I’ll try

I have tried and I have found that it is stucked in line
task = kpu.load(0x600000)

Any ideas why this would happened? Is my kmodel corrupted?

it is strange, if it is OOM, it will have msg
what’s your kmodel size?
and kpu.memtest() result?
or you can post kmodel, and we will try it

The model size is 1859kb.

How can I send the kmodel to you? I can’t send it here.

I can’t perform the memtest since it is stucked on the loading command and cannot enter the loop

Now it has been solved.

I think it is due to the libraries of the firmware is excessive for the RAM, which also needs to handle the data of my kmodel and so it stucked in the step loading the model.

I then replace the firmware with the minimum one found here: http://cn.dl.sipeed.com/MAIX/MaixPy/release/master/

I chose one of the version and download the one with ‘minimal’ written on the filename and it works.

I hope this could help