コード例 #1
0
ファイル: visualization_utils.py プロジェクト: kjs95/project
def draw_side_by_side_evaluation_image(eval_dict,
                                       category_index,
                                       max_boxes_to_draw=20,
                                       min_score_thresh=0.2):
    detection_fields = fields.DetectionResultFields()
    input_data_fields = fields.InputDataFields()
    instance_masks = None
    if detection_fields.detection_masks in eval_dict:
        instance_masks = tf.cast(
            tf.expand_dims(eval_dict[detection_fields.detection_masks],
                           axis=0), tf.uint8)
    keypoints = None
    if detection_fields.detection_keypoints in eval_dict:
        keypoints = tf.expand_dims(
            eval_dict[detection_fields.detection_keypoints], axis=0)
    groundtruth_instance_masks = None
    if input_data_fields.groundtruth_instance_masks in eval_dict:
        groundtruth_instance_masks = tf.cast(
            tf.expand_dims(
                eval_dict[input_data_fields.groundtruth_instance_masks],
                axis=0), tf.uint8)
    images_with_detections = draw_bounding_boxes_on_image_tensors(
        eval_dict[input_data_fields.original_image],
        tf.expand_dims(eval_dict[detection_fields.detection_boxes], axis=0),
        tf.expand_dims(eval_dict[detection_fields.detection_classes], axis=0),
        tf.expand_dims(eval_dict[detection_fields.detection_scores], axis=0),
        category_index,
        instance_masks=instance_masks,
        keypoints=keypoints,
        max_boxes_to_draw=max_boxes_to_draw,
        min_score_thresh=min_score_thresh)
    images_with_groundtruth = draw_bounding_boxes_on_image_tensors(
        eval_dict[input_data_fields.original_image],
        tf.expand_dims(eval_dict[input_data_fields.groundtruth_boxes], axis=0),
        tf.expand_dims(eval_dict[input_data_fields.groundtruth_classes],
                       axis=0),
        tf.expand_dims(
            tf.ones_like(eval_dict[input_data_fields.groundtruth_classes],
                         dtype=tf.float32),
            axis=0),
        category_index,
        instance_masks=groundtruth_instance_masks,
        keypoints=None,
        max_boxes_to_draw=None,
        min_score_thresh=0.0)
    return tf.concat([images_with_detections, images_with_groundtruth], axis=2)
コード例 #2
0
def draw_side_by_side_evaluation_image(eval_dict,
                                       category_index,
                                       max_boxes_to_draw=20,
                                       min_score_thresh=0.2,
                                       use_normalized_coordinates=True):
    """Creates a side-by-side image with detections and groundtruth.

  Bounding boxes (and instance masks, if available) are visualized on both
  subimages.

  Args:
    eval_dict: The evaluation dictionary returned by
      eval_util.result_dict_for_single_example().
    category_index: A category index (dictionary) produced from a labelmap.
    max_boxes_to_draw: The maximum number of boxes to draw for detections.
    min_score_thresh: The minimum score threshold for showing detections.
    use_normalized_coordinates: Whether to assume boxes and kepoints are in
      normalized coordinates (as opposed to absolute coordiantes).
      Default is True.

  Returns:
    A [1, H, 2 * W, C] uint8 tensor. The subimage on the left corresponds to
      detections, while the subimage on the right corresponds to groundtruth.
  """
    detection_fields = fields.DetectionResultFields()
    input_data_fields = fields.InputDataFields()
    instance_masks = None
    if detection_fields.detection_masks in eval_dict:
        instance_masks = tf.cast(
            tf.expand_dims(eval_dict[detection_fields.detection_masks],
                           axis=0), tf.uint8)
    keypoints = None
    if detection_fields.detection_keypoints in eval_dict:
        keypoints = tf.expand_dims(
            eval_dict[detection_fields.detection_keypoints], axis=0)
    groundtruth_instance_masks = None
    if input_data_fields.groundtruth_instance_masks in eval_dict:
        groundtruth_instance_masks = tf.cast(
            tf.expand_dims(
                eval_dict[input_data_fields.groundtruth_instance_masks],
                axis=0), tf.uint8)
    images_with_detections = draw_bounding_boxes_on_image_tensors(
        eval_dict[input_data_fields.original_image],
        tf.expand_dims(eval_dict[detection_fields.detection_boxes], axis=0),
        tf.expand_dims(eval_dict[detection_fields.detection_classes], axis=0),
        tf.expand_dims(eval_dict[detection_fields.detection_scores], axis=0),
        category_index,
        instance_masks=instance_masks,
        keypoints=keypoints,
        max_boxes_to_draw=max_boxes_to_draw,
        min_score_thresh=min_score_thresh,
        use_normalized_coordinates=use_normalized_coordinates)
    images_with_groundtruth = draw_bounding_boxes_on_image_tensors(
        eval_dict[input_data_fields.original_image],
        tf.expand_dims(eval_dict[input_data_fields.groundtruth_boxes], axis=0),
        tf.expand_dims(eval_dict[input_data_fields.groundtruth_classes],
                       axis=0),
        tf.expand_dims(
            tf.ones_like(eval_dict[input_data_fields.groundtruth_classes],
                         dtype=tf.float32),
            axis=0),
        category_index,
        instance_masks=groundtruth_instance_masks,
        keypoints=None,
        max_boxes_to_draw=None,
        min_score_thresh=0.0,
        use_normalized_coordinates=use_normalized_coordinates)
    return tf.concat([images_with_detections, images_with_groundtruth], axis=2)