当前位置: 首页>>代码示例>>Python>>正文


Python coco_tools.ExportSingleImageDetectionBoxesToCoco方法代码示例

本文整理汇总了Python中object_detection.metrics.coco_tools.ExportSingleImageDetectionBoxesToCoco方法的典型用法代码示例。如果您正苦于以下问题:Python coco_tools.ExportSingleImageDetectionBoxesToCoco方法的具体用法?Python coco_tools.ExportSingleImageDetectionBoxesToCoco怎么用?Python coco_tools.ExportSingleImageDetectionBoxesToCoco使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在object_detection.metrics.coco_tools的用法示例。


在下文中一共展示了coco_tools.ExportSingleImageDetectionBoxesToCoco方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testSingleImageDetectionBoxesExport

# 需要导入模块: from object_detection.metrics import coco_tools [as 别名]
# 或者: from object_detection.metrics.coco_tools import ExportSingleImageDetectionBoxesToCoco [as 别名]
def testSingleImageDetectionBoxesExport(self):
    boxes = np.array([[0, 0, 1, 1],
                      [0, 0, .5, .5],
                      [.5, .5, 1, 1]], dtype=np.float32)
    classes = np.array([1, 2, 3], dtype=np.int32)
    scores = np.array([0.8, 0.2, 0.7], dtype=np.float32)
    coco_boxes = np.array([[0, 0, 1, 1],
                           [0, 0, .5, .5],
                           [.5, .5, .5, .5]], dtype=np.float32)
    coco_annotations = coco_tools.ExportSingleImageDetectionBoxesToCoco(
        image_id='first_image',
        category_id_set=set([1, 2, 3]),
        detection_boxes=boxes,
        detection_classes=classes,
        detection_scores=scores)
    for i, annotation in enumerate(coco_annotations):
      self.assertEqual(annotation['image_id'], 'first_image')
      self.assertEqual(annotation['category_id'], classes[i])
      self.assertAlmostEqual(annotation['score'], scores[i])
      self.assertTrue(np.all(np.isclose(annotation['bbox'], coco_boxes[i]))) 
开发者ID:ahmetozlu,项目名称:vehicle_counting_tensorflow,代码行数:22,代码来源:coco_tools_test.py

示例2: testSingleImageDetectionBoxesExportWithKeypoints

# 需要导入模块: from object_detection.metrics import coco_tools [as 别名]
# 或者: from object_detection.metrics.coco_tools import ExportSingleImageDetectionBoxesToCoco [as 别名]
def testSingleImageDetectionBoxesExportWithKeypoints(self):
    boxes = np.array([[0, 0, 1, 1], [0, 0, .5, .5], [.5, .5, 1, 1]],
                     dtype=np.float32)
    coco_boxes = np.array([[0, 0, 1, 1], [0, 0, .5, .5], [.5, .5, .5, .5]],
                          dtype=np.float32)
    keypoints = np.array([[[0, 0], [0.25, 0.25], [0.75, 0.75]],
                          [[0, 0], [0.125, 0.125], [0.375, 0.375]],
                          [[0.5, 0.5], [0.75, 0.75], [1.0, 1.0]]],
                         dtype=np.float32)
    visibilities = np.array([[2, 2, 2], [2, 2, 2], [2, 2, 2]], dtype=np.int32)

    classes = np.array([1, 2, 3], dtype=np.int32)
    scores = np.array([0.8, 0.2, 0.7], dtype=np.float32)

    # Tests exporting without passing in is_crowd (for backward compatibility).
    coco_annotations = coco_tools.ExportSingleImageDetectionBoxesToCoco(
        image_id='first_image',
        category_id_set=set([1, 2, 3]),
        detection_boxes=boxes,
        detection_scores=scores,
        detection_classes=classes,
        detection_keypoints=keypoints,
        detection_keypoint_visibilities=visibilities)
    for i, annotation in enumerate(coco_annotations):
      self.assertTrue(np.all(np.isclose(annotation['bbox'], coco_boxes[i])))
      self.assertEqual(annotation['image_id'], 'first_image')
      self.assertEqual(annotation['category_id'], classes[i])
      self.assertTrue(np.all(np.isclose(annotation['bbox'], coco_boxes[i])))
      self.assertEqual(annotation['score'], scores[i])
      self.assertEqual(annotation['num_keypoints'], 3)
      self.assertTrue(
          np.all(np.isclose(annotation['keypoints'][0::3], keypoints[i, :, 1])))
      self.assertTrue(
          np.all(np.isclose(annotation['keypoints'][1::3], keypoints[i, :, 0])))
      self.assertTrue(
          np.all(np.equal(annotation['keypoints'][2::3], visibilities[i]))) 
开发者ID:tensorflow,项目名称:models,代码行数:38,代码来源:coco_tools_test.py

示例3: add_single_detected_image_info

# 需要导入模块: from object_detection.metrics import coco_tools [as 别名]
# 或者: from object_detection.metrics.coco_tools import ExportSingleImageDetectionBoxesToCoco [as 别名]
def add_single_detected_image_info(self,
                                     image_id,
                                     detections_dict):
    """Adds detections for a single image to be used for evaluation.

    If a detection has already been added for this image id, a warning is
    logged, and the detection is skipped.

    Args:
      image_id: A unique string/integer identifier for the image.
      detections_dict: A dictionary containing -
        DetectionResultFields.detection_boxes: float32 numpy array of shape
          [num_boxes, 4] containing `num_boxes` detection boxes of the format
          [ymin, xmin, ymax, xmax] in absolute image coordinates.
        DetectionResultFields.detection_scores: float32 numpy array of shape
          [num_boxes] containing detection scores for the boxes.
        DetectionResultFields.detection_classes: integer numpy array of shape
          [num_boxes] containing 1-indexed detection classes for the boxes.

    Raises:
      ValueError: If groundtruth for the image_id is not available.
    """
    if image_id not in self._image_ids:
      raise ValueError('Missing groundtruth for image id: {}'.format(image_id))

    if self._image_ids[image_id]:
      tf.logging.warning('Ignoring detection with image id %s since it was '
                         'previously added', image_id)
      return

    self._detection_boxes_list.extend(
        coco_tools.ExportSingleImageDetectionBoxesToCoco(
            image_id=image_id,
            category_id_set=self._category_id_set,
            detection_boxes=detections_dict[standard_fields.
                                            DetectionResultFields
                                            .detection_boxes],
            detection_scores=detections_dict[standard_fields.
                                             DetectionResultFields.
                                             detection_scores],
            detection_classes=detections_dict[standard_fields.
                                              DetectionResultFields.
                                              detection_classes]))
    self._image_ids[image_id] = True 
开发者ID:ahmetozlu,项目名称:vehicle_counting_tensorflow,代码行数:46,代码来源:coco_evaluation.py

示例4: add_single_detected_image_info

# 需要导入模块: from object_detection.metrics import coco_tools [as 别名]
# 或者: from object_detection.metrics.coco_tools import ExportSingleImageDetectionBoxesToCoco [as 别名]
def add_single_detected_image_info(self,
                                     image_id,
                                     detections_dict):
    """Adds detections for a single image to be used for evaluation.

    If a detection has already been added for this image id, a warning is
    logged, and the detection is skipped.

    Args:
      image_id: A unique string/integer identifier for the image.
      detections_dict: A dictionary containing -
        DetectionResultFields.detection_boxes: float32 numpy array of shape
          [num_boxes, 4] containing `num_boxes` detection boxes of the format
          [ymin, xmin, ymax, xmax] in absolute image coordinates.
        DetectionResultFields.detection_scores: float32 numpy array of shape
          [num_boxes] containing detection scores for the boxes.
        DetectionResultFields.detection_classes: integer numpy array of shape
          [num_boxes] containing 1-indexed detection classes for the boxes.
        DetectionResultFields.detection_masks: optional uint8 numpy array of
          shape [num_boxes, image_height, image_width] containing instance
          masks for the boxes.

    Raises:
      ValueError: If groundtruth for the image_id is not available.
    """
    if image_id not in self._image_ids:
      raise ValueError('Missing groundtruth for image id: {}'.format(image_id))

    if self._image_ids[image_id]:
      tf.logging.warning('Ignoring detection with image id %s since it was '
                         'previously added', image_id)
      return

    self._detection_boxes_list.extend(
        coco_tools.ExportSingleImageDetectionBoxesToCoco(
            image_id=image_id,
            category_id_set=self._category_id_set,
            detection_boxes=detections_dict[standard_fields.
                                            DetectionResultFields
                                            .detection_boxes],
            detection_scores=detections_dict[standard_fields.
                                             DetectionResultFields.
                                             detection_scores],
            detection_classes=detections_dict[standard_fields.
                                              DetectionResultFields.
                                              detection_classes]))
    self._image_ids[image_id] = True 
开发者ID:ShreyAmbesh,项目名称:Traffic-Rule-Violation-Detection-System,代码行数:49,代码来源:coco_evaluation.py

示例5: add_single_detected_image_info

# 需要导入模块: from object_detection.metrics import coco_tools [as 别名]
# 或者: from object_detection.metrics.coco_tools import ExportSingleImageDetectionBoxesToCoco [as 别名]
def add_single_detected_image_info(self, image_id, detections_dict):
    """Add detection results of all frames to the eval pipeline.

    This method overrides the function defined in the base class.

    Args:
      image_id: A unique string/integer identifier for the image.
      detections_dict: A list of dictionary containing -
        DetectionResultFields.detection_boxes: float32 numpy array of shape
          [num_boxes, 4] containing `num_boxes` detection boxes of the format
          [ymin, xmin, ymax, xmax] in absolute image coordinates.
        DetectionResultFields.detection_scores: float32 numpy array of shape
          [num_boxes] containing detection scores for the boxes.
        DetectionResultFields.detection_classes: integer numpy array of shape
          [num_boxes] containing 1-indexed detection classes for the boxes.

    Raises:
      ValueError: If groundtruth for the image_id is not available.
    """
    for idx, det in enumerate(detections_dict):
      if not det:
        continue

      image_frame_id = '{}_{}'.format(image_id, idx)
      if image_frame_id not in self._image_ids:
        raise ValueError(
            'Missing groundtruth for image-frame id: {}'.format(image_frame_id))

      if self._image_ids[image_frame_id]:
        tf.logging.warning(
            'Ignoring detection with image id %s since it was '
            'previously added', image_frame_id)
        continue

      self._detection_boxes_list.extend(
          coco_tools.ExportSingleImageDetectionBoxesToCoco(
              image_id=image_frame_id,
              category_id_set=self._category_id_set,
              detection_boxes=det[
                  standard_fields.DetectionResultFields.detection_boxes],
              detection_scores=det[
                  standard_fields.DetectionResultFields.detection_scores],
              detection_classes=det[
                  standard_fields.DetectionResultFields.detection_classes]))
      self._image_ids[image_frame_id] = True 
开发者ID:generalized-iou,项目名称:g-tensorflow-models,代码行数:47,代码来源:coco_evaluation_all_frames.py

示例6: add_single_detected_image_info

# 需要导入模块: from object_detection.metrics import coco_tools [as 别名]
# 或者: from object_detection.metrics.coco_tools import ExportSingleImageDetectionBoxesToCoco [as 别名]
def add_single_detected_image_info(self,
                                     image_id,
                                     detections_dict):
    """Adds detections for a single image to be used for evaluation.

    If a detection has already been added for this image id, a warning is
    logged, and the detection is skipped.

    Args:
      image_id: A unique string/integer identifier for the image.
      detections_dict: A dictionary containing -
        DetectionResultFields.detection_boxes: float32 numpy array of shape
          [num_boxes, 4] containing `num_boxes` detection boxes of the format
          [ymin, xmin, ymax, xmax] in absolute image coordinates.
        DetectionResultFields.detection_scores: float32 numpy array of shape
          [num_boxes] containing detection scores for the boxes.
        DetectionResultFields.detection_classes: integer numpy array of shape
          [num_boxes] containing 1-indexed detection classes for the boxes.
        DetectionResultFields.detection_keypoints (optional): float numpy array
          of keypoints with shape [num_boxes, num_keypoints, 2].
    Raises:
      ValueError: If groundtruth for the image_id is not available.
    """
    if image_id not in self._image_ids:
      raise ValueError('Missing groundtruth for image id: {}'.format(image_id))

    if self._image_ids[image_id]:
      tf.logging.warning('Ignoring detection with image id %s since it was '
                         'previously added', image_id)
      return

    # Drop optional fields if empty tensor.
    detection_keypoints = detections_dict.get(
        standard_fields.DetectionResultFields.detection_keypoints)
    if detection_keypoints is not None and not detection_keypoints.shape[0]:
      detection_keypoints = None
    self._detection_boxes_list.extend(
        coco_tools.ExportSingleImageDetectionBoxesToCoco(
            image_id=image_id,
            category_id_set=self._category_id_set,
            detection_boxes=detections_dict[
                standard_fields.DetectionResultFields.detection_boxes],
            detection_scores=detections_dict[
                standard_fields.DetectionResultFields.detection_scores],
            detection_classes=detections_dict[
                standard_fields.DetectionResultFields.detection_classes],
            detection_keypoints=detection_keypoints))
    self._image_ids[image_id] = True 
开发者ID:tensorflow,项目名称:models,代码行数:50,代码来源:coco_evaluation.py


注:本文中的object_detection.metrics.coco_tools.ExportSingleImageDetectionBoxesToCoco方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。