Esempio n. 1
0
 def test_scale(self):
   boxlist = np_box_list.BoxList(
       np.array(
           [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=
           np.float32))
   boxlist_scaled = np_box_list_ops.scale(boxlist, 2.0, 3.0)
   expected_boxlist_scaled = np_box_list.BoxList(
       np.array(
           [[0.5, 0.75, 1.5, 2.25], [0.0, 0.0, 1.0, 2.25]], dtype=np.float32))
   self.assertAllClose(expected_boxlist_scaled.get(), boxlist_scaled.get())
Esempio n. 2
0
 def test_scale(self):
   boxlist = np_box_list.BoxList(
       np.array(
           [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75]], dtype=
           np.float32))
   boxlist_scaled = np_box_list_ops.scale(boxlist, 2.0, 3.0)
   expected_boxlist_scaled = np_box_list.BoxList(
       np.array(
           [[0.5, 0.75, 1.5, 2.25], [0.0, 0.0, 1.0, 2.25]], dtype=np.float32))
   self.assertAllClose(expected_boxlist_scaled.get(), boxlist_scaled.get())
def _extract_groundtruth_values(example):
    _fields = fields.TfExampleFields

    result_dict = {'image_id': example[_fields.source_id].bytes_list.value[0]}

    height = example[_fields.height].int64_list.value[0]
    width = example[_fields.width].int64_list.value[0]

    y_mins = [
        y_min for y_min in example[_fields.object_bbox_ymin].float_list.value
    ]
    x_mins = [
        x_min for x_min in example[_fields.object_bbox_xmin].float_list.value
    ]
    y_maxs = [
        y_max for y_max in example[_fields.object_bbox_ymax].float_list.value
    ]
    x_maxs = [
        x_max for x_max in example[_fields.object_bbox_xmax].float_list.value
    ]
    object_bboxes = np.asarray(zip(y_mins, x_mins, y_maxs, x_maxs))

    if object_bboxes.size == 0:
        groundtruth_boxes = object_bboxes.reshape([0, 4])
    else:
        normalized_gt_boxlist = np_box_list.BoxList(object_bboxes)
        gt_boxlist = np_box_list_ops.scale(normalized_gt_boxlist, height,
                                           width)
        groundtruth_boxes = gt_boxlist.get()
    result_dict['groundtruth_boxes'] = groundtruth_boxes
    result_dict['groundtruth_classes'] = \
        np.asarray([label for label in example[_fields.object_class_label].int64_list.value])
    result_dict['area'] = \
        np.asarray([area for area in example[_fields.object_segment_area].float_list.value])
    result_dict['difficult'] = \
        np.asarray([difficult for difficult in example[_fields.object_difficult].int64_list.value])

    # subset annotations
    if _fields.object_subset in example:
        result_dict['groundtruth_subset'] = \
            np.asarray([subset for subset in example[_fields.object_subset].bytes_list.value])
    return result_dict