问题描述
训练的是图像检测,代码运行后可以正常实时拍摄画面也不报错,可是识别到目标物体后不画框也不标注
复现步骤
训练的是图像检测,代码运行后可以正常实时拍摄画面也不报错,可是识别到目标物体后不画框也不标注代码如下
# -*- coding: utf-8 -*-
import os, gc, sys, time
from libs.PlatTasks import DetectionApp
from libs.PipeLine import PipeLine
from libs.Utils import *
display_mode = "lcd"
rgb888p_size = [640, 480]
root_path = "/sdcard/mp_deployment_source/"
deploy_conf = read_json(root_path + "/deploy_config.json")
kmodel_path = root_path + deploy_conf["kmodel_path"]
labels = deploy_conf["categories"]
confidence_threshold = deploy_conf["confidence_threshold"]
nms_threshold = deploy_conf["nms_threshold"]
model_input_size = deploy_conf["img_size"]
model_type = deploy_conf["model_type"]
# 鲁棒性修改:确保 anchors 转换万无一失
anchors = []
if model_type == "AnchorBaseDet":
try:
# 尝试展开成一维列表 [33, 52, 69, ...]
anchors = deploy_conf["anchors"][0] + deploy_conf["anchors"][1] + deploy_conf["anchors"][2]
except:
# 如果报错,直接传入原始结构
anchors = deploy_conf["anchors"]
inference_mode = "video"
debug_mode = 0
os.exitpoint(os.EXITPOINT_ENABLE)
pl = PipeLine(rgb888p_size=rgb888p_size, display_mode=display_mode)
pl.create()
display_size = pl.get_display_size()
det_app = DetectionApp(inference_mode, kmodel_path, labels, model_input_size, anchors, model_type, confidence_threshold, nms_threshold, rgb888p_size, display_size, debug_mode=debug_mode)
det_app.config_preprocess()
try:
while True:
with ScopedTiming("total", 1):
img = pl.get_frame()
if img is None:
continue
if hasattr(pl, "osd_img") and pl.osd_img is not None:
try:
pl.osd_img.clear()
except:
pass
res = det_app.run(img)
# 重点观察这里!!
if res:
print("Detected successfully:", res)
else:
print("Nothing detected")
det_app.draw_result(pl.osd_img, res)
pl.show_image()
gc.collect()
os.exitpoint()
except KeyboardInterrupt as e:
print("User stop", e)
except BaseException as e:
print("Exception", e)
finally:
try:
det_app.deinit()
except:
pass
try:
pl.destroy()
except:
pass
os.exitpoint(os.EXITPOINT_ENABLE_SLEEP)
time.sleep_ms(100)
硬件板卡
K230D
软件版本
CanMV_K230D_ATK_DNK230D_micropython_v1.3-0-g8dd764f_nncase_v2.9.0.img
其他信息
控制台显示