OpenMV4 H7 Plus 加载 trained.tflite 失败:'module' object has no attribute 'load'
故障概述
用户在 OpenMV4 H7 Plus(固件 4.5.9)上运行 Edge Impulse 导出的 TFLite 模型测试代码时,报错:
Exception: Failed to load "trained.tflite", did you copy the .tflite and labels.txt file onto the mass-storage device? ('module' object has no attribute 'load')
该错误表明 tf 模块不支持 .load() 方法,属于固件 API 兼容性问题。
关键信息汇总
- 问题类型:代码报错
- 硬件型号:OpenMV4 H7 Plus
- 固件版本:4.5.9
- 错误核心:tf.load() 方法不存在 —— 旧版固件中 tf 模块使用的是 tf.classify() / tf.detect() 等直接调用方式,不提供 .load() 接口
- 代码环境:Edge Impulse 导出的 OpenMV 示例代码(适配新版固件 ≥4.6.0),与当前固件不兼容
- 文件存在性:trained.tflite 和 labels.txt 已确认存于 U 盘根目录
建议下一步操作
- 升级固件至 ≥4.6.0(推荐 4.7.0),以支持 tf.load() 及完整 TFLite 解析能力
- 若无法升级,需改用旧版 API:将模型以 .tflite 文件名硬编码方式传入 tf.classify() 或 tf.detect(),无需显式 load
- 确认模型量化格式为 int8(Edge Impulse 默认导出为 int8),且输入尺寸与 sensor.set_windowing() 一致(如 240×240)