def _test_augmenter(cls, augmenter_name, func_expected, dependent_on_seed): # this test verifies: # - called function seems to be the expected function # - images produced by augmenter match images produced by function # - a different seed (and sometimes severity) will lead to a # different image # - augmenter can be pickled severity = 5 aug_cls = getattr(iaa.imgcorruptlike, augmenter_name) image = np.mod( np.arange(32*32*3), 256 ).reshape((32, 32, 3)).astype(np.uint8) with iap.no_prefetching(): rng = iarandom.RNG(1) # Replay sampling of severities. # Even for deterministic values this is required as currently # there is an advance() at the end of each draw_samples(). _ = iap.Deterministic(1).draw_samples((1,), rng) # As for the functions above, we can't just change the seed value # to get different augmentations as many functions are dependend # only on the severity. So we change only for some functions only # the seed and for the others severity+seed. image_aug1 = aug_cls(severity=severity, seed=1)(image=image) image_aug2 = aug_cls(severity=severity, seed=1)(image=image) if dependent_on_seed: image_aug3 = aug_cls(severity=severity, seed=2)( image=image) else: image_aug3 = aug_cls(severity=severity-1, seed=2)( image=image) image_aug_exp = func_expected( image, severity=severity, seed=rng.generate_seed_()) assert aug_cls(severity=severity).func is func_expected assert np.array_equal(image_aug1, image_aug_exp) assert np.array_equal(image_aug2, image_aug_exp) assert not np.array_equal(image_aug3, image_aug2) # pickling test aug = aug_cls(severity=(1, 5)) runtest_pickleable_uint8_img(aug, shape=(32, 32, 3))
def test_pickleable(self): aug = iaa.Cartoon(seed=1) runtest_pickleable_uint8_img(aug, iterations=6)
def test_pickleable(self): aug = iaa.Rain(random_state=1) runtest_pickleable_uint8_img(aug, iterations=3, shape=(20, 20, 3))
def test_pickleable(self): aug = iaa.FastSnowyLandscape(lightness_threshold=(50, 150), lightness_multiplier=(1.0, 3.0), random_state=1) runtest_pickleable_uint8_img(aug)
def test_pickleable(self): aug = self.augmenter((1, 7), random_state=1) runtest_pickleable_uint8_img(aug, iterations=10, shape=(25, 25, 1))
def test_pickleable(self): aug = iaa.Emboss(alpha=(0.0, 1.0), strength=(1, 3), seed=1) runtest_pickleable_uint8_img(aug, iterations=20)
def test_pickleable(self): aug = iaa.Sharpen(alpha=(0.0, 1.0), lightness=(1, 3), seed=1) runtest_pickleable_uint8_img(aug, iterations=20)
def test_pickleable__callback_function(self): aug = iaa.Convolve(_convolve_pickleable_matrix_generator, seed=1) runtest_pickleable_uint8_img(aug, iterations=20)
def test_pickleable__identity_matrix(self): identity_matrix = np.int64([[1]]) aug = iaa.Convolve(identity_matrix, seed=1) runtest_pickleable_uint8_img(aug, iterations=20)
def test_pickleable(self): aug = iaa.Canny(random_state=1) runtest_pickleable_uint8_img(aug, iterations=20)
def test_pickleable(self): aug = self.create_aug(0.5) runtest_pickleable_uint8_img(aug, iterations=20)
def test_pickleable(self): aug = iaa.Snowflakes(seed=1) runtest_pickleable_uint8_img(aug, iterations=3, shape=(20, 20, 3))
def test_pickleable(self): aug = iaa.RandAugment(m=(0, 10), n=(1, 2)) runtest_pickleable_uint8_img(aug, iterations=50)