def test_StandardTransformer(self): config = { 'raw': [{ 'name': 'Normalize' }, { 'name': 'RandomContrast', 'execution_probability': 0.5 }, { 'name': 'RandomFlip' }, { 'name': 'RandomRotate90' }, { 'name': 'ToTensor', 'expand_dims': True }], 'label': [{ 'name': 'RandomFlip' }, { 'name': 'RandomRotate90' }, { 'name': 'ToTensor', 'expand_dims': False, 'dtype': 'long' }] } base_config = {'mean': 0, 'std': 1} transformer = Transformer(config, base_config) raw_transforms = transformer.raw_transform().transforms assert raw_transforms[0].mean == 0 assert raw_transforms[0].std == 1 assert raw_transforms[1].execution_probability == 0.5 assert raw_transforms[4].expand_dims label_transforms = transformer.label_transform().transforms assert len(label_transforms) == 3
def test_AnisotropicRotationTransformer(self): config = { 'raw': [ {'name': 'Normalize'}, {'name': 'RandomContrast', 'execution_probability': 0.5}, {'name': 'RandomFlip'}, {'name': 'RandomRotate90'}, {'name': 'RandomRotate', 'angle_spectrum': 17, 'axes': [[2, 1]]}, {'name': 'ToTensor', 'expand_dims': True} ], 'label': [ {'name': 'RandomFlip'}, {'name': 'RandomRotate90'}, {'name': 'RandomRotate', 'angle_spectrum': 17, 'axes': [[2, 1]]}, {'name': 'ToTensor', 'expand_dims': False, 'dtype': 'long'} ] } transformer = Transformer(config, 0, 1) raw_transforms = transformer.raw_transform().transforms assert raw_transforms[0].mean == 0 assert raw_transforms[0].std == 1 assert raw_transforms[1].execution_probability == 0.5 assert raw_transforms[4].angle_spectrum == 17 assert raw_transforms[4].axes == [[2, 1]] label_transforms = transformer.label_transform().transforms assert len(label_transforms) == 4
def test_BaseTransformer(self): config = { 'raw': [{ 'name': 'Normalize' }, { 'name': 'ToTensor', 'expand_dims': True }], 'label': [{ 'name': 'ToTensor', 'expand_dims': False, 'dtype': 'long' }], 'weight': [{ 'name': 'ToTensor', 'expand_dims': False }] } base_config = {'mean': 0, 'std': 1} transformer = Transformer(config, base_config) raw_transforms = transformer.raw_transform().transforms assert raw_transforms[0].mean == 0 assert raw_transforms[0].std == 1 assert raw_transforms[1].expand_dims label_transforms = transformer.label_transform().transforms assert not label_transforms[0].expand_dims assert label_transforms[0].dtype == 'long' weight_transforms = transformer.weight_transform().transforms assert not weight_transforms[0].expand_dims
def test_LabelToBoundaryTransformer(self): config = { 'raw': [ {'name': 'Normalize'}, {'name': 'RandomContrast', 'execution_probability': 0.5}, {'name': 'RandomFlip'}, {'name': 'RandomRotate90'}, {'name': 'RandomRotate', 'angle_spectrum': 17, 'axes': [[2, 1]], 'mode': 'reflect'}, {'name': 'ToTensor', 'expand_dims': True} ], 'label': [ {'name': 'RandomFlip'}, {'name': 'RandomRotate90'}, {'name': 'RandomRotate', 'angle_spectrum': 17, 'axes': [[2, 1]], 'mode': 'reflect'}, {'name': 'LabelToBoundary', 'offsets': [2, 4, 6, 8]}, {'name': 'ToTensor', 'expand_dims': False, 'dtype': 'long'} ] } transformer = Transformer(config, 0, 1) raw_transforms = transformer.raw_transform().transforms assert raw_transforms[0].mean == 0 assert raw_transforms[0].std == 1 assert raw_transforms[1].execution_probability == 0.5 assert raw_transforms[4].angle_spectrum == 17 assert raw_transforms[4].axes == [[2, 1]] assert raw_transforms[4].mode == 'reflect' label_transforms = transformer.label_transform().transforms assert label_transforms[2].angle_spectrum == 17 assert label_transforms[2].axes == [[2, 1]] assert label_transforms[2].mode == 'reflect' # 3 conv kernels per offset assert len(label_transforms[3].kernels) == 12