You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google AutoML Edge目标检测导出的TFLite模型调用invoke时崩溃

Google AutoML Edge目标检测导出的TFLite模型调用invoke时崩溃

嘿,我一眼就发现你代码里的问题啦——输入张量维度不匹配,这就是invoke()崩溃的核心原因!

先对照你的输入细节来看:模型要求的输入shape是[1, 192, 192, 3],意味着需要4维张量(包含batch维度,batch size为1)。但你在调用set_tensor的时候,传的是test_image,它的形状是(192, 192, 3),是3维的,少了最关键的batch维度!

有意思的是,你其实已经做了正确的操作:用data = np.expand_dims(test_image, axis=0)生成了符合要求的4维输入张量,但你根本没把它传给模型,反而误用了原始的3维图像数据。

修正后的关键代码片段:

data = np.expand_dims(test_image, axis=0)
# 把这里的test_image改成data,传入符合维度要求的4维张量
interpreter.set_tensor(input_details[0]["index"], data)
interpreter.invoke() # 现在应该可以正常执行了

另外再帮你确认了其他细节:

  • 图像尺寸(192,192)完全匹配模型输入要求
  • 数据类型uint8也和输入的dtype一致,这部分你做的没问题

修正之后再运行,应该就能正常调用模型并获取检测结果了!

备注:内容来源于stack exchange,提问作者Krisna Gita

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 12:13:03