本文整理匯總了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)