2.11版本的yolo检测异常

Viewed 73

问题描述


自行编译得固件(CanMV_K230_LCKFB_micropython_local_nncase_v2.11.0_ota.kdimg)
运行demo里的yolov5_det_video检测效果很好

自己训练的pt文件转kmodel就乱检测且几秒后卡死

image.png

sensor(0), mode 0, buffer_num 4, buffer_size 0
total took 307.74 ms
total took 48.20 ms
total took 46.02 ms
total took 57.47 ms
total took 47.77 ms
total took 64.22 ms
total took 57.81 ms
total took 84.17 ms
(之后就卡死了,复位后才能连上)

复现步骤


pip install E:\Download\nncase-2.11.0-cp310-cp310-win_amd64.whl
pip install E:\Download\nncase_kpu-2.11.0-py2.py3-none-win_amd64.whl

        model = YOLO("yolov5n.pt")
        results = model.train(
            data=r"E:\DeskTop\X50out\dataset.yaml",
            epochs=100,
            patience=50,
            batch=8,
            imgsz=320,
            lr0=0.01,  
            lrf=0.01,
            save_period=200,
            plots=True
        )
        success = model.export(format="onnx", imgsz=320, opset=11)
        print(f"Success: {success}")

yolov5_det_video只改了模型路径、标签内容和提出了最多检测数量max_box

from libs.PipeLine import PipeLine
from libs.YOLO import YOLOv5
from libs.Utils import *
import os,sys,gc
import ulab.numpy as np
import image

if __name__=="__main__":
    # 这里仅为示例,自定义场景请修改为您自己的模型路径、标签名称、模型输入大小
    kmodel_path="/data/best.kmodel"
    labels = ["classA"]
    model_input_size=[320,320]

    # 添加显示模式,默认hdmi,可选hdmi/lcd/lt9611/st7701/hx8399/nt35516,其中hdmi默认置为lt9611,分辨率1920*1080;lcd默认置为st7701,分辨率800*480
    display_mode="lcd"
    rgb888p_size=[640,360]
    confidence_threshold = 0.8
    nms_threshold=0.45
    max_box = 50
    pl=PipeLine(rgb888p_size=rgb888p_size,display_mode=display_mode)
    pl.create()
    display_size=pl.get_display_size()
    # 初始化YOLOv5实例
    yolo=YOLOv5(task_type="detect",mode="video",kmodel_path=kmodel_path,labels=labels,rgb888p_size=rgb888p_size,model_input_size=model_input_size,display_size=display_size,conf_thresh=confidence_threshold,nms_thresh=nms_threshold,max_boxes_num=max_box,debug_mode=0)
    yolo.config_preprocess()
    while True:
        with ScopedTiming("total",1):
            img=pl.get_frame()
            res=yolo.run(img)
            yolo.draw_result(res,pl.osd_img)
            pl.show_image()
            gc.collect()
    yolo.deinit()
    pl.destroy()


max_box 调小也是卡死,模型转换用的https://github.com/imHuangke/Onnx-to-Kmodel
.To_kmodel.py --target k230 --model "runs/detect/train3/weights/best.onnx" --input_width 320 --input_height 320 --ptq_option 0 --dataset_path "E:\DeskTop\X50out\images\train"

硬件板卡


庐山派

软件版本


CanMV_K230_LCKFB_micropython_local_nncase_v2.11.0

自定义2.11得固件是为了移除example例程和加了几个自定义的py文件,对此应该没有影响吧,之前2.9得时候没有这种问题

1 Answers

你好,你这个看着像是解码的问题,你可以检查一下onnx的yolov5的输出,k230的YOLOv5支持的是一个输出的格式。