def test_invert_subselect_rows_by_indices__two_of_three_selected(self): images = np.zeros((3, 3, 4, 1), dtype=np.uint8) images[0, ...] = 0 images[1, ...] = 1 images[2, ...] = 2 batch = _BatchInAugmentation( images=images, keypoints=[ ia.KeypointsOnImage([ia.Keypoint(0, 0)], shape=(3, 4, 1)), ia.KeypointsOnImage([ia.Keypoint(1, 1)], shape=(3, 4, 1)), ia.KeypointsOnImage([ia.Keypoint(2, 2)], shape=(3, 4, 1)) ]) batch_sub = batch.subselect_rows_by_indices([0, 2]) batch_sub.images[0, ...] = 10 batch_sub.images[1, ...] = 20 batch_sub.keypoints[0].keypoints[0].x = 10 batch_inv = batch.invert_subselect_rows_by_indices_([0, 2], batch_sub) assert batch_inv.images.shape == (3, 3, 4, 1) assert np.max(batch_inv.images[0]) == 10 assert np.max(batch_inv.images[1]) == 1 assert np.max(batch_inv.images[2]) == 20 assert batch_inv.keypoints[0].keypoints[0].x == 10 assert batch_inv.keypoints[0].keypoints[0].y == 0 assert batch_inv.keypoints[1].keypoints[0].x == 1 assert batch_inv.keypoints[1].keypoints[0].y == 1 assert batch_inv.keypoints[2].keypoints[0].x == 2 assert batch_inv.keypoints[2].keypoints[0].y == 2
def test_to_batch(self): batch_before_aug = ia.Batch() batch_before_aug.images_unaug = 0 batch_before_aug.heatmaps_unaug = 1 batch_before_aug.segmentation_maps_unaug = 2 batch_before_aug.keypoints_unaug = 3 batch_before_aug.bounding_boxes_unaug = 4 batch_before_aug.polygons_unaug = 5 batch_before_aug.line_strings_unaug = 6 batch_inaug = _BatchInAugmentation(images=10, heatmaps=20, segmentation_maps=30, keypoints=40, bounding_boxes=50, polygons=60, line_strings=70) batch = batch_inaug.to_batch(batch_before_aug) assert batch.images_unaug == 0 assert batch.heatmaps_unaug == 1 assert batch.segmentation_maps_unaug == 2 assert batch.keypoints_unaug == 3 assert batch.bounding_boxes_unaug == 4 assert batch.polygons_unaug == 5 assert batch.line_strings_unaug == 6 assert batch.images_aug == 10 assert batch.heatmaps_aug == 20 assert batch.segmentation_maps_aug == 30 assert batch.keypoints_aug == 40 assert batch.bounding_boxes_aug == 50 assert batch.polygons_aug == 60 assert batch.line_strings_aug == 70
def test_propagation_hooks_ctx(self): def propagator(images, augmenter, parents, default): if ia.is_np_array(images): return False else: return True hooks = ia.HooksImages(propagator=propagator) batch = _BatchInAugmentation( images=np.zeros((3, 3, 4, 1), dtype=np.uint8), keypoints=[ ia.KeypointsOnImage([ia.Keypoint(0, 0)], shape=(3, 4, 1)), ia.KeypointsOnImage([ia.Keypoint(1, 1)], shape=(3, 4, 1)), ia.KeypointsOnImage([ia.Keypoint(2, 2)], shape=(3, 4, 1)) ]) with batch.propagation_hooks_ctx(iaa.Identity(), hooks, []) \ as batch_prop: assert batch_prop.images is None assert batch_prop.keypoints is not None assert len(batch_prop.keypoints) == 3 batch_prop.keypoints[0].keypoints[0].x = 10 assert batch.images is not None assert batch.keypoints is not None assert batch.keypoints[0].keypoints[0].x == 10
def test_deepcopy(self): batch = _BatchInAugmentation(images=np.full((1, ), 0, dtype=np.uint8), heatmaps=np.full((1, ), 1, dtype=np.uint8), segmentation_maps=np.full((1, ), 2, dtype=np.uint8), keypoints=np.full((1, ), 3, dtype=np.uint8), bounding_boxes=np.full((1, ), 4, dtype=np.uint8), polygons=np.full((1, ), 5, dtype=np.uint8), line_strings=np.full((1, ), 6, dtype=np.uint8)) batch_copy = batch.deepcopy() assert np.max(batch_copy.images) == 0 assert np.max(batch_copy.heatmaps) == 1 assert np.max(batch_copy.segmentation_maps) == 2 assert np.max(batch_copy.keypoints) == 3 assert np.max(batch_copy.bounding_boxes) == 4 assert np.max(batch_copy.polygons) == 5 assert np.max(batch_copy.line_strings) == 6
def test_fill_from_batch_in_augmentation(self): batch = _BatchInAugmentation(images=1) batch_inaug = _BatchInAugmentation(images=2, heatmaps=3, segmentation_maps=4, keypoints=5, bounding_boxes=6, polygons=7, line_strings=8) batch = batch.fill_from_batch_in_augmentation_(batch_inaug) assert batch.images == 2 assert batch.heatmaps == 3 assert batch.segmentation_maps == 4 assert batch.keypoints == 5 assert batch.bounding_boxes == 6 assert batch.polygons == 7 assert batch.line_strings == 8
def test_columns__with_two_columns(self): batch = _BatchInAugmentation(images=[0, 0], keypoints=[1, 1]) columns = batch.columns assert len(columns) == 2 assert columns[0].name == "images" assert columns[1].name == "keypoints" assert columns[0].value == [0, 0] assert columns[1].value == [1, 1]
def test_subselect_rows_by_indices__none_selected(self): batch = _BatchInAugmentation( images=np.zeros((3, 3, 4, 1)), keypoints=[ ia.KeypointsOnImage([ia.Keypoint(0, 0)], shape=(3, 4, 1)), ia.KeypointsOnImage([ia.Keypoint(1, 1)], shape=(3, 4, 1)), ia.KeypointsOnImage([ia.Keypoint(2, 2)], shape=(3, 4, 1)) ]) batch_sub = batch.subselect_rows_by_indices([]) assert batch_sub.images is None assert batch_sub.keypoints is None
def test_subselect_rows_by_indices__two_of_three_selected(self): batch = _BatchInAugmentation( images=np.zeros((3, 3, 4, 1)), keypoints=[ ia.KeypointsOnImage([ia.Keypoint(0, 0)], shape=(3, 4, 1)), ia.KeypointsOnImage([ia.Keypoint(1, 1)], shape=(3, 4, 1)), ia.KeypointsOnImage([ia.Keypoint(2, 2)], shape=(3, 4, 1)) ]) batch_sub = batch.subselect_rows_by_indices([0, 2]) assert batch_sub.images.shape == (2, 3, 4, 1) assert batch_sub.keypoints[0].keypoints[0].x == 0 assert batch_sub.keypoints[0].keypoints[0].y == 0 assert batch_sub.keypoints[1].keypoints[0].x == 2 assert batch_sub.keypoints[1].keypoints[0].y == 2
def test_empty__with_columns_set(self): kwargs = [{ "images": [2] }, { "heatmaps": [3] }, { "segmentation_maps": [4] }, { "keypoints": [5] }, { "bounding_boxes": [6] }, { "polygons": [7] }, { "line_strings": [8] }] for kwargs_i in kwargs: batch = _BatchInAugmentation(**kwargs_i) assert not batch.empty
def test_nb_rows__with_columns_set(self): kwargs = [{ "images": [0] }, { "heatmaps": [0] }, { "segmentation_maps": [0] }, { "keypoints": [0] }, { "bounding_boxes": [0] }, { "polygons": [0] }, { "line_strings": [0] }] for kwargs_i in kwargs: batch = _BatchInAugmentation(**kwargs_i) assert batch.nb_rows == 1
def test_columns__with_columns_set(self): kwargs = [{ "images": [0] }, { "heatmaps": [0] }, { "segmentation_maps": [0] }, { "keypoints": [0] }, { "bounding_boxes": [0] }, { "polygons": [0] }, { "line_strings": [0] }] for kwargs_i in kwargs: batch = _BatchInAugmentation(**kwargs_i) columns = batch.columns assert len(columns) == 1 assert columns[0].name == list(kwargs_i.keys())[0]
def test_get_rowwise_shapes__nonimages(self): heatmaps = [ ia.HeatmapsOnImage(np.zeros((1, 2, 1), dtype=np.float32), shape=(1, 2, 3)) ] segmaps = [ ia.SegmentationMapsOnImage(np.zeros((1, 2, 1), dtype=np.int32), shape=(1, 2, 3)) ] keypoints = [ia.KeypointsOnImage([ia.Keypoint(0, 0)], shape=(1, 2, 3))] bounding_boxes = [ ia.BoundingBoxesOnImage([ia.BoundingBox(0, 1, 2, 3)], shape=(1, 2, 3)) ] polygons = [ ia.PolygonsOnImage([ia.Polygon([(0, 0), (1, 0), (1, 1)])], shape=(1, 2, 3)) ] line_strings = [ ia.LineStringsOnImage([ia.LineString([(0, 0), (1, 0)])], shape=(1, 2, 3)) ] kwargs = [{ "heatmaps": heatmaps }, { "segmentation_maps": segmaps }, { "keypoints": keypoints }, { "bounding_boxes": bounding_boxes }, { "polygons": polygons }, { "line_strings": line_strings }] for kwargs_i in kwargs: batch = _BatchInAugmentation(**kwargs_i) shapes = batch.get_rowwise_shapes() assert shapes == [(1, 2, 3)]
def test_get_column_names__with_two_columns(self): batch = _BatchInAugmentation(images=[0, 0], keypoints=[1, 1]) assert batch.get_column_names() == ["images", "keypoints"]
def test_to_batch_in_augmentation(self): batch = _BatchInAugmentation(images=1) batch_inaug = batch.to_batch_in_augmentation() assert batch_inaug is batch
def test_nb_rows__when_empty(self): batch = _BatchInAugmentation() assert batch.nb_rows == 0
def test_nb_rows__with_empty_column(self): batch = _BatchInAugmentation(images=[]) assert batch.nb_rows == 0
def test_get_rowwise_shapes__images_is_multiple_arrays(self): batch = _BatchInAugmentation( images=[np.zeros((3, 4, 1)), np.zeros((4, 5, 1))]) shapes = batch.get_rowwise_shapes() assert shapes == [(3, 4, 1), (4, 5, 1)]
def test_columns__with_empty_column(self): batch = _BatchInAugmentation(images=[]) columns = batch.columns assert len(columns) == 0
def test_columns__when_empty(self): batch = _BatchInAugmentation() assert len(batch.columns) == 0
def test_nb_rows__with_two_columns(self): batch = _BatchInAugmentation(images=[0, 0], keypoints=[0, 0]) assert batch.nb_rows == 2
def test_get_rowwise_shapes__images_is_single_array(self): batch = _BatchInAugmentation(images=np.zeros((2, 3, 4, 1))) shapes = batch.get_rowwise_shapes() assert shapes == [(3, 4, 1), (3, 4, 1)]
def test_empty__all_columns_none(self): batch = _BatchInAugmentation() assert batch.empty