logo

OpenMV N6 烧录YOLO识别代码后频繁断连重启

2026-06-16 19:45
6
6wc4a4nty8rv

OpenMV N6 烧录YOLO识别代码后频繁断连重启

故障概述

用户使用 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 波动等异常现象,疑似硬件资源超限或固件兼容性问题。

关键信息汇总

  • 故障类型:硬件故障
  • 设备型号:OpenMV N6(非官方 OpenMV4 系列,基于 STM32N657X0)
  • 固件版本:v4.8.1(高于官方最新版 4.7.0)
  • 复现操作:烧录含 YOLO 模型推理的 main.py 后,IDE 点击运行即触发 USB 断连 → 重连 → 重启循环
  • 错误特征:无稳定报错堆栈,偶发 IndexError;模型可加载但 predict() 返回空结果;系统在 model.predict([img]) 行附近崩溃
  • 参考资料:无(用户未参考外部文档)
  • 硬件状态:仅通过 Type-C 直连电脑,无外设干扰

附:用户提供的故障代码(main.py)

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)