本文整理汇总了Python中object_detection.metrics.coco_tools.ExportDetectionsToCOCO方法的典型用法代码示例。如果您正苦于以下问题:Python coco_tools.ExportDetectionsToCOCO方法的具体用法?Python coco_tools.ExportDetectionsToCOCO怎么用?Python coco_tools.ExportDetectionsToCOCO使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类object_detection.metrics.coco_tools
的用法示例。
在下文中一共展示了coco_tools.ExportDetectionsToCOCO方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testExportDetectionsToCOCO
# 需要导入模块: from object_detection.metrics import coco_tools [as 别名]
# 或者: from object_detection.metrics.coco_tools import ExportDetectionsToCOCO [as 别名]
def testExportDetectionsToCOCO(self):
image_ids = ['first', 'second']
detections_boxes = [np.array([[100, 100, 200, 200]], np.float),
np.array([[50, 50, 100, 100]], np.float)]
detections_scores = [np.array([.8], np.float), np.array([.7], np.float)]
detections_classes = [np.array([1], np.int32), np.array([1], np.int32)]
categories = [{'id': 0, 'name': 'person'},
{'id': 1, 'name': 'cat'},
{'id': 2, 'name': 'dog'}]
output_path = os.path.join(tf.test.get_temp_dir(), 'detections.json')
result = coco_tools.ExportDetectionsToCOCO(
image_ids,
detections_boxes,
detections_scores,
detections_classes,
categories,
output_path=output_path)
self.assertListEqual(result, self._detections_list)
with tf.gfile.GFile(output_path, 'r') as f:
written_result = f.read()
# The json output should have floats written to 4 digits of precision.
matcher = re.compile(r'"bbox":\s+\[\n\s+\d+.\d\d\d\d,', re.MULTILINE)
self.assertTrue(matcher.findall(written_result))
written_result = json.loads(written_result)
self.assertAlmostEqual(result, written_result)