tensorflow - TensorFlow Object Detection API 导出模型不一致
问题描述
简而言之:导出的模型返回的结果不一致,具体取决于导出的位置。
我们有两个使用TensorFlow API训练的对象检测模型。为简单起见,我将它们称为 A 型和 B 型。
我们对模型 A 没有任何问题。我们使用model_main_tf2.py对其进行了训练,并使用相同的环境 (TensorFlow 2.6) 使用exporter_main_v2.py导出了最佳检查点。之后,我们能够加载导出的模型并获得预期的结果。
模型 B 是在相同的环境(TensorFlow 2.6)中训练的,但在导出它之前,环境出现了问题,我们不得不将模型工件(检查点等)移动到另一台也有 TensorFlow 2.6 的机器上,以便运行在那里导出脚本。
这就是问题所在。在新环境中导出的模型在我们加载并尝试使用它后会显示不一致的行为。我们预计模型 B 会检测到 12 个,但它只返回 1 个。
这是获得的检测结果。请记住,我们预计有 12 次检测,因为该精确图像在导出之前由同一模型处理,然后返回 12 次检测。
{'detection_multiclass_scores': array([[1.9824505e-04, 3.9569736e-03, 4.6455562e-03, 4.9173832e-04,
5.0777197e-04, 2.5947261e-01, 3.1823516e-03, 3.3535659e-03,
4.5810342e-03, 3.6034614e-02, 4.6887398e-03, 1.3771057e-03]],
dtype=float32),
'raw_detection_scores': array([[0.00889182, 0.00935337, 0.00695416, 0.00348121, 0.00440842,
0.00418016, 0.00230229, 0.00314716, 0.00373328, 0.00261161,
0.0018006 , 0.00297052]], dtype=float32),
'detection_classes': array([6]),
'detection_anchor_indices': array([49079.], dtype=float32),
'detection_scores': array([0.2594726], dtype=float32),
'detection_boxes': array([[0.79609746, 0. , 1. , 1. ]], dtype=float32),
'raw_detection_boxes': array([[-0.01518888, -0.01413308, 0.0324419 , 0.04361729]],
dtype=float32),
'num_detections': 1}
更糟糕的是,我们在另一个环境中测试了导出模型 B,但这种情况下的结果也不同:该模型对同一图像返回 0 次检测。我们还尝试在同一环境中再次导出模型 A,以查看问题是否与模型 B 相关,但似乎并非如此,因为在此新环境中导出模型 A 现在也返回 0 检测。
什么可能导致这种差异?
解决方案
推荐阅读
- java - 弹簧控制器路径不被视为常数
- git - 如何使用 ajoberstar/reckon 和 Bitbucket Pipelines 配置自动语义版本控制?
- javascript - 我在轮播中显示图像的功能有一个额外的空白图像
- java - 如何在 Struts2 中导出 CSV 文件
- c# - 浮点精度中double和float的区别
- angular - 打字稿将接口描述的类型转换为另一种类型?
- javascript - 如何展平多对象数据并映射到 JSON 模式 uisng reactJS?
- java - java - 如何使用java从Mongodb集合中检索arraylist的元素?
- android - 如何从编程线性布局项中获取 id
- swift - 为什么我在比较两个日期时出错