Python源码示例:imgaug.augmenters.Augmenter()

示例1
def test_augment_images(self):
        class _DummyAugmenter(meta.Augmenter):
            def __init__(self):
                super(_DummyAugmenter, self).__init__()
                self.call_count = 0

            def _augment_batch_(self, batch, random_state, parents, hooks):
                assert batch.images[0].dtype.name == "int16"
                self.call_count += 1
                return batch

            def get_parameters(self):
                return []

        aug_dummy = _DummyAugmenter()
        aug = iaa.WithHueAndSaturation(aug_dummy)

        image = np.zeros((4, 4, 3), dtype=np.uint8)
        image_aug = aug.augment_images([image])[0]
        assert image_aug.dtype.name == "uint8"
        assert np.array_equal(image_aug, image)
        assert aug_dummy.call_count == 1 
示例2
def test_augment_heatmaps(self):
        from imgaug.augmentables.heatmaps import HeatmapsOnImage

        class _DummyAugmenter(meta.Augmenter):
            def __init__(self):
                super(_DummyAugmenter, self).__init__()
                self.call_count = 0

            def _augment_batch_(self, batch, random_state, parents, hooks):
                self.call_count += 1
                return batch

            def get_parameters(self):
                return []

        aug_dummy = _DummyAugmenter()
        hm = np.ones((8, 12, 1), dtype=np.float32)
        hmoi = HeatmapsOnImage(hm, shape=(16, 24, 3))

        aug = iaa.WithHueAndSaturation(aug_dummy)
        hmoi_aug = aug.augment_heatmaps(hmoi)
        assert hmoi_aug.shape == (16, 24, 3)
        assert hmoi_aug.arr_0to1.shape == (8, 12, 1)

        assert aug_dummy.call_count == 1 
示例3
def _init_augmenter(self, augmenter):
        if isinstance(augmenter, type(None)):
            self.augmenter = augmenter
        elif isinstance(augmenter, iaa.Augmenter):
            self.augmenter = augmenter
        elif isinstance(augmenter, list):
            if isinstance(augmenter[0], iaa.Augmenter):
                self.augmenter = iaa.Sequential(augmenter)
            else:
                raise TypeError(
                    """`augmenter` must be class Augmenter
                            (imgaug.augmenters.Augmenter)
                            or list of Augmenters"""
                )
        else:
            raise ValueError(
                """augmenter must be class
                             Augmenter, list of Augmenters, or None"""
            ) 
示例4
def test___init___defaults(self):
        aug = iaa.WithBrightnessChannels()
        assert isinstance(aug.children, iaa.Augmenter)
        assert len(aug.to_colorspace.a) == len(self.valid_colorspaces)
        for cspace in self.valid_colorspaces:
            assert cspace in aug.to_colorspace.a
        assert aug.from_colorspace == iaa.CSPACE_RGB 
示例5
def test___init___to_colorspace_is_all(self):
        aug = iaa.WithBrightnessChannels(to_colorspace=ia.ALL)
        assert isinstance(aug.children, iaa.Augmenter)
        assert len(aug.to_colorspace.a) == len(self.valid_colorspaces)
        for cspace in self.valid_colorspaces:
            assert cspace in aug.to_colorspace.a
        assert aug.from_colorspace == iaa.CSPACE_RGB 
示例6
def test___init___to_colorspace_is_cspace(self):
        aug = iaa.WithBrightnessChannels(to_colorspace=iaa.CSPACE_YUV)
        assert isinstance(aug.children, iaa.Augmenter)
        assert aug.to_colorspace.value == iaa.CSPACE_YUV
        assert aug.from_colorspace == iaa.CSPACE_RGB 
示例7
def test___init___to_colorspace_is_stochastic_parameter(self):
        aug = iaa.WithBrightnessChannels(
            to_colorspace=iap.Deterministic(iaa.CSPACE_YUV))
        assert isinstance(aug.children, iaa.Augmenter)
        assert aug.to_colorspace.value == iaa.CSPACE_YUV
        assert aug.from_colorspace == iaa.CSPACE_RGB 
示例8
def test___init___defaults(self):
        aug = iaa.MultiplyBrightness()
        assert isinstance(aug.children, iaa.Augmenter)
        assert isinstance(aug.children[0], iaa.Multiply)
        assert len(aug.to_colorspace.a) == len(self.valid_colorspaces)
        for cspace in self.valid_colorspaces:
            assert cspace in aug.to_colorspace.a
        assert aug.from_colorspace == iaa.CSPACE_RGB 
示例9
def test_augment_keypoints(self):
        from imgaug.augmentables.kps import KeypointsOnImage

        class _DummyAugmenter(meta.Augmenter):
            def __init__(self):
                super(_DummyAugmenter, self).__init__()
                self.call_count = 0

            def _augment_batch_(self, batch, random_state, parents, hooks):
                self.call_count += 1
                return batch

            def get_parameters(self):
                return []

        aug_dummy = _DummyAugmenter()
        kpsoi = KeypointsOnImage.from_xy_array(np.float32([
            [0, 0],
            [5, 1]
        ]), shape=(16, 24, 3))

        aug = iaa.WithHueAndSaturation(aug_dummy)
        kpsoi_aug = aug.augment_keypoints(kpsoi)
        assert kpsoi_aug.shape == (16, 24, 3)
        assert kpsoi.keypoints[0].x == 0
        assert kpsoi.keypoints[0].y == 0
        assert kpsoi.keypoints[1].x == 5
        assert kpsoi.keypoints[1].y == 1

        assert aug_dummy.call_count == 1