k230自训练YOLO模型转换后识别精度降低

Viewed 68

重现步骤
经过训练,获取yolo11模型,使用在测试图片中,识别准确率可以达到0.9以上,置信度也高,但转换为kmodle之后,在开发板上对相同图片进行测试,置信度只有0.5多。且yolo11,640*640下,只要有识别到,置信度一直都是0.503418。320*320下,

YOLO原模型识别与kmodel识别对比
image.png image.png

kmodel识别图像代码

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

if __name__=="__main__":
    # 这里仅为示例,自定义场景请修改为您自己的测试图片、模型路径、标签名称、模型输入大小
    img_path="/data/271.jpg"
    kmodel_path="/data/best3.kmodel"
    labels = ['Crane','Jeep','Car','Bus']
    model_input_size=[640,640]

    confidence_threshold = 0.5
    nms_threshold=0.45
    img,img_ori=read_image(img_path)
    rgb888p_size=[img.shape[2],img.shape[1]]
    # 初始化YOLO11实例
    yolo=YOLO11(task_type="detect",mode="image",kmodel_path=kmodel_path,labels=labels,rgb888p_size=rgb888p_size,model_input_size=model_input_size,conf_thresh=confidence_threshold,nms_thresh=nms_threshold,max_boxes_num=50,debug_mode=0)
    yolo.config_preprocess()
    res=yolo.run(img)
    print(res,img_ori)
    yolo.draw_result(res,img_ori)
    yolo.deinit()
    gc.collect()
1 Answers

你好,可能是模型量化后存在损失,你可以在转换kmodel时将量化选项ptq_option设置为1试试

量化选项ptq_option设置为1之后,置信度达到了0.89,确实效果不错,这个选项设置的效果是?平时应该如何选择

置信度低的话就换成1,默认是uint8量化,换成1后,模型权重量化精度变为int16

好的,了解,谢谢