用户使用 OpenMV N6(非标准型号,固件版本 v4.8.1,MicroPython v1.26.0-77)运行 YOLOv8 模型识别代码时,每次点击 IDE 绿色运行按钮,设备即断开 USB 连接并自动重连,表现为反复重启。代码包含 CSI 摄像头初始化、TFLite 模型加载(192×192 输入)、YoloV8 后处理及实时推理循环。多次尝试中出现 IndexError: tuple index out of range、模型加载成功但 results 长度为 0、FPS 波动等异常现象,疑似硬件资源超限或固件兼容性问题。
import csi
import time
import ml
import gc
from ml.postprocessing.ultralytics import YoloV8
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.QVGA)
csi0.window((192, 192))
csi0.snapshot(time=2000)
model = ml.Model(
"/rom/yolov8n_192.tflite",
postprocess=YoloV8(threshold=0.6, nms_threshold=0.3)
)
print("开始测试内置 YOLO 模型")
clock = time.clock()
count = 0
while True:
clock.tick()
img = csi0.snapshot()
boxes = model.predict([img])
detected = False
for class_id, class_dets in enumerate(boxes):
for rect, score in class_dets:
detected = True
img.draw_rectangle(rect)
if count % 30 == 0:
print("内置模型运行中", "detected:", detected, "fps:", clock.fps())
count += 1
if count % 10 == 0:
gc.collect()
time.sleep_ms(50)