Exemplo n.º 1
0
    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 = ia.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
Exemplo n.º 2
0
    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 = ia.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
Exemplo n.º 3
0
    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 = ia.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
Exemplo n.º 4
0
    def test_deepcopy(self):
        batch = ia.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
Exemplo n.º 5
0
    def test_fill_from_batch_in_augmentation(self):
        batch = ia.BatchInAugmentation(images=1)
        batch_inaug = ia.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
Exemplo n.º 6
0
    def test_columns__with_two_columns(self):
        batch = ia.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]
Exemplo n.º 7
0
    def test_subselect_rows_by_indices__none_selected(self):
        batch = ia.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
Exemplo n.º 8
0
    def test_subselect_rows_by_indices__two_of_three_selected(self):
        batch = ia.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
Exemplo n.º 9
0
 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 = ia.BatchInAugmentation(**kwargs_i)
         assert not batch.empty
Exemplo n.º 10
0
 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 = ia.BatchInAugmentation(**kwargs_i)
         assert batch.nb_rows == 1
Exemplo n.º 11
0
 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 = ia.BatchInAugmentation(**kwargs_i)
         columns = batch.columns
         assert len(columns) == 1
         assert columns[0].name == list(kwargs_i.keys())[0]
Exemplo n.º 12
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 = ia.BatchInAugmentation(**kwargs_i)
            shapes = batch.get_rowwise_shapes()
            assert shapes == [(1, 2, 3)]
Exemplo n.º 13
0
 def test_get_column_names__with_two_columns(self):
     batch = ia.BatchInAugmentation(images=[0, 0], keypoints=[1, 1])
     assert batch.get_column_names() == ["images", "keypoints"]
Exemplo n.º 14
0
 def test_to_batch_in_augmentation(self):
     batch = ia.BatchInAugmentation(images=1)
     batch_inaug = batch.to_batch_in_augmentation()
     assert batch_inaug is batch
Exemplo n.º 15
0
 def test_nb_rows__when_empty(self):
     batch = ia.BatchInAugmentation()
     assert batch.nb_rows == 0
Exemplo n.º 16
0
 def test_nb_rows__with_empty_column(self):
     batch = ia.BatchInAugmentation(images=[])
     assert batch.nb_rows == 0
Exemplo n.º 17
0
 def test_get_rowwise_shapes__images_is_multiple_arrays(self):
     batch = ia.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)]
Exemplo n.º 18
0
    def test_columns__with_empty_column(self):
        batch = ia.BatchInAugmentation(images=[])

        columns = batch.columns

        assert len(columns) == 0
Exemplo n.º 19
0
 def test_columns__when_empty(self):
     batch = ia.BatchInAugmentation()
     assert len(batch.columns) == 0
Exemplo n.º 20
0
 def test_nb_rows__with_two_columns(self):
     batch = ia.BatchInAugmentation(images=[0, 0], keypoints=[0, 0])
     assert batch.nb_rows == 2
Exemplo n.º 21
0
 def test_get_rowwise_shapes__images_is_single_array(self):
     batch = ia.BatchInAugmentation(images=np.zeros((2, 3, 4, 1)))
     shapes = batch.get_rowwise_shapes()
     assert shapes == [(3, 4, 1), (3, 4, 1)]
Exemplo n.º 22
0
 def test_empty__all_columns_none(self):
     batch = ia.BatchInAugmentation()
     assert batch.empty