def test_keypoint_jitter_does_not_change_img_mask_or_target(img_3x3, mask_3x3): trf = slc.Stream([slt.KeypointsJitter(p=1, dx_range=(-0.2, 0.2), dy_range=(-0.2, 0.2))]) dc_res = trf({"image": img_3x3.copy(), "mask": mask_3x3.copy(), "label": 1}, return_torch=False) assert np.array_equal(dc_res.data[0], img_3x3) assert np.array_equal(dc_res.data[1], mask_3x3) assert np.array_equal(dc_res.data[2], 1)
def test_keypoint_jitter_does_not_change_img_mask_or_target(img_3x3, mask_3x3): dc = sld.DataContainer((img_3x3.copy(), mask_3x3.copy(), 1), 'IML') trf = slc.Stream( [slt.KeypointsJitter(p=1, dx_range=(-0.2, 0.2), dy_range=(-0.2, 0.2))]) dc_res = trf(dc) assert np.array_equal(dc_res.data[0], img_3x3) assert np.array_equal(dc_res.data[1], mask_3x3) assert np.array_equal(dc_res.data[2], 1)
def test_keypoint_jitter_works_correctly(jitter_x, jitter_y, exp_x, exp_y): kpts_data = np.array([[1, 1],]).reshape((1, 2)) kpts = slc.Keypoints(kpts_data.copy(), 2, 2) dc = slc.DataContainer((kpts,), "P") trf = slc.Stream([slt.KeypointsJitter(p=1, dx_range=(jitter_x, jitter_x), dy_range=(jitter_y, jitter_y))]) dc_res = trf(dc, return_torch=False) assert np.array_equal(dc_res.data[0].data, np.array([exp_x, exp_y]).reshape((1, 2)))
def init_augs(): kvs = GlobalKVS() args = kvs['args'] cutout = slt.ImageCutOut(cutout_size=(int(args.cutout * args.crop_x), int(args.cutout * args.crop_y)), p=0.5) # plus-minus 1.3 pixels jitter = slt.KeypointsJitter(dx_range=(-0.003, 0.003), dy_range=(-0.003, 0.003)) ppl = tvt.Compose([ jitter if args.use_target_jitter else slc.Stream(), slc.SelectiveStream([ slc.Stream([ slt.RandomFlip(p=0.5, axis=1), slt.RandomProjection(affine_transforms=slc.Stream([ slt.RandomScale(range_x=(0.8, 1.3), p=1), slt.RandomRotate(rotation_range=(-90, 90), p=1), slt.RandomShear( range_x=(-0.1, 0.1), range_y=(-0.1, 0.1), p=0.5), ]), v_range=(1e-5, 2e-3), p=0.5), slt.RandomScale(range_x=(0.5, 2.5), p=0.5), ]), slc.Stream() ], probs=[0.7, 0.3]), slc.Stream([ slt.PadTransform((args.pad_x, args.pad_y), padding='z'), slt.CropTransform((args.crop_x, args.crop_y), crop_mode='r'), ]), slc.SelectiveStream([ slt.ImageSaltAndPepper(p=1, gain_range=0.01), slt.ImageBlur(p=1, blur_type='g', k_size=(3, 5)), slt.ImageBlur(p=1, blur_type='m', k_size=(3, 5)), slt.ImageAdditiveGaussianNoise(p=1, gain_range=0.5), slc.Stream([ slt.ImageSaltAndPepper(p=1, gain_range=0.05), slt.ImageBlur(p=0.5, blur_type='m', k_size=(3, 5)), ]), slc.Stream([ slt.ImageBlur(p=0.5, blur_type='m', k_size=(3, 5)), slt.ImageSaltAndPepper(p=1, gain_range=0.01), ]), slc.Stream() ], n=1), slt.ImageGammaCorrection(p=0.5, gamma_range=(0.5, 1.5)), cutout if args.use_cutout else slc.Stream(), partial(solt2torchhm, downsample=None, sigma=None), ]) kvs.update('train_trf', ppl)
def get_landmark_transform_kneel(config): cutout = slt.ImageCutOut(cutout_size=(int(config.dataset.cutout * config.dataset.augs.crop.crop_x), int(config.dataset.cutout * config.dataset.augs.crop.crop_y)), p=0.5) # plus-minus 1.3 pixels jitter = slt.KeypointsJitter(dx_range=(-0.003, 0.003), dy_range=(-0.003, 0.003)) ppl = transforms.Compose([ ColorPaddingWithSide(p=0.05, pad_size=10, side=SIDES.RANDOM, color=(50,100)), TriangularMask(p=0.025, arm_lengths=(100, 50), side=SIDES.RANDOM, color=(50,100)), TriangularMask(p=0.025, arm_lengths=(50, 100), side=SIDES.RANDOM, color=(50,100)), LowVisibilityTransform(p=0.05, alpha=0.15, bgcolor=(50,100)), SubSampleUpScale(p=0.01), jitter if config.dataset.augs.use_target_jitter else slc.Stream(), slc.SelectiveStream([ slc.Stream([ slt.RandomFlip(p=0.5, axis=1), slt.RandomProjection(affine_transforms=slc.Stream([ slt.RandomScale(range_x=(0.9, 1.1), p=1), slt.RandomRotate(rotation_range=(-90, 90), p=1), slt.RandomShear(range_x=(-0.1, 0.1), range_y=(-0.1, 0.1), p=0.5), ]), v_range=(1e-5, 2e-3), p=0.5), # slt.RandomScale(range_x=(0.5, 2.5), p=0.5), ]), slc.Stream() ], probs=[0.7, 0.3]), slc.Stream([ slt.PadTransform((config.dataset.augs.pad.pad_x, config.dataset.augs.pad.pad_y), padding='z'), slt.CropTransform((config.dataset.augs.crop.crop_x, config.dataset.augs.crop.crop_y), crop_mode='r'), ]), slc.SelectiveStream([ slt.ImageSaltAndPepper(p=1, gain_range=0.01), slt.ImageBlur(p=1, blur_type='g', k_size=(3, 5)), slt.ImageBlur(p=1, blur_type='m', k_size=(3, 5)), slt.ImageAdditiveGaussianNoise(p=1, gain_range=0.5), slc.Stream([ slt.ImageSaltAndPepper(p=1, gain_range=0.05), slt.ImageBlur(p=0.5, blur_type='m', k_size=(3, 5)), ]), slc.Stream([ slt.ImageBlur(p=0.5, blur_type='m', k_size=(3, 5)), slt.ImageSaltAndPepper(p=1, gain_range=0.01), ]), slc.Stream() ], n=1), slt.ImageGammaCorrection(p=0.5, gamma_range=(0.5, 1.5)), cutout if config.dataset.use_cutout else slc.Stream(), partial(solt2torchhm, downsample=None, sigma=None), ]) return ppl