在使用OpenMV4 H7 Plus进行图像识别项目时,遇到了ml模块导入错误的问题。项目需要加载tflite模型进行椰子识别,但在运行代码时出现模块导入失败。
硬件信息:
故障现象:
参考文章:
故障代码:
import sensor, image, tf,time
import ml
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing((240, 240))
sensor.skip_frames(time=2000)
model=False
while not model:
try:
model = ml.load("openmv_coconut_model.tflite", load_to_fb=True)
model=True
except Exception as e:
print(f"模型加载出错: {e},2 秒后重试...")
time.sleep(2)
labels = [line.rstrip() for line in open("labels.txt")]
while True:
img = sensor.snapshot()
scores = model.predict(img)[0].flatten().tolist()
for i, score in enumerate(scores):
print(f"{labels[i]} = {score}")






pc的代码
ml模块的使用具体见:
使用openmv官方的训练器尝试:
或者使用edge impulse进行训练: