logo

OpenMV H7 Plus 运行报错:AttributeError: 'Model' object has no attribute 'classify'

2026-03-16 13:28
3
vp15

OpenMV H7 Plus 运行报错:AttributeError: 'Model' object has no attribute 'classify'

问题概述

用户在 OpenMV H7 Plus 上运行基于 Edge Impulse 的图像分类示例代码时,出现 AttributeError:'Model' object has no attribute 'classify' 错误。该错误发生在调用 net.classify() 方法时。

关键信息

  • 硬件型号:OpenMV H7 Plus
  • 固件版本:未提供(需补充)
  • 使用模型:trained20230518.tflite
  • 标签文件:labels.txt
  • 图像格式:GRAYSCALE + QVGA + windowing (240,240)
  • 代码中尝试调用 net.classify(...),但 Model 实例无此方法

相关代码片段

for obj in net.classify(img, min_scale=1.0, scale_mul=0.8, x_overlap=0.5, y_overlap=0.5):
    print("**********\nPredictions at [x=%d,y=%d,w=%d,h=%d]" % obj.rect())
    img.draw_rectangle(obj.rect())
    # This combines the labels and confidence values into a list of tuples
    predictions_list = list(zip(labels, obj.output()))

可能原因分析(供社区参考)

  • OpenMV 固件版本过低,不支持 Model.classify() —— 该方法在较新固件(如 v4.3+)中才引入
  • 误用了 ml.Model 而非 tf.load() 加载模型(旧版 API 中 classify 是 tf 模块方法,非 Model 实例方法)
  • 混淆了 Edge Impulse 官方 OpenMV 示例与 OpenMV 原生 API 的差异

用户备注

注释中提到“5.18加载人脸识别haar算子降低识别率”,说明当前流程是先做人脸检测(Haar),再对整图或 ROI 执行分类;但报错发生在 classify 调用阶段,与 Haar 无关。

2026-03-16 17:10
Z
星小瞳xs

net在新版本固件中早已弃用,现已更改为使用ml模块:ml — 机器学习 — MicroPython 1.22 文档