MCPcopy Create free account
hub / github.com/NVlabs/SPADE / get_transform

Function get_transform

data/base_dataset.py:47–78  ·  view source on GitHub ↗
(opt, params, method=Image.BICUBIC, normalize=True, toTensor=True)

Source from the content-addressed store, hash-verified

45
46
47def get_transform(opt, params, method=Image.BICUBIC, normalize=True, toTensor=True):
48 transform_list = []
49 if 'resize' in opt.preprocess_mode:
50 osize = [opt.load_size, opt.load_size]
51 transform_list.append(transforms.Resize(osize, interpolation=method))
52 elif 'scale_width' in opt.preprocess_mode:
53 transform_list.append(transforms.Lambda(lambda img: __scale_width(img, opt.load_size, method)))
54 elif 'scale_shortside' in opt.preprocess_mode:
55 transform_list.append(transforms.Lambda(lambda img: __scale_shortside(img, opt.load_size, method)))
56
57 if 'crop' in opt.preprocess_mode:
58 transform_list.append(transforms.Lambda(lambda img: __crop(img, params['crop_pos'], opt.crop_size)))
59
60 if opt.preprocess_mode == 'none':
61 base = 32
62 transform_list.append(transforms.Lambda(lambda img: __make_power_2(img, base, method)))
63
64 if opt.preprocess_mode == 'fixed':
65 w = opt.crop_size
66 h = round(opt.crop_size / opt.aspect_ratio)
67 transform_list.append(transforms.Lambda(lambda img: __resize(img, w, h, method)))
68
69 if opt.isTrain and not opt.no_flip:
70 transform_list.append(transforms.Lambda(lambda img: __flip(img, params['flip'])))
71
72 if toTensor:
73 transform_list += [transforms.ToTensor()]
74
75 if normalize:
76 transform_list += [transforms.Normalize((0.5, 0.5, 0.5),
77 (0.5, 0.5, 0.5))]
78 return transforms.Compose(transform_list)
79
80
81def normalize():

Callers 1

__getitem__Method · 0.90

Calls 6

__scale_widthFunction · 0.85
__scale_shortsideFunction · 0.85
__cropFunction · 0.85
__make_power_2Function · 0.85
__resizeFunction · 0.85
__flipFunction · 0.85

Tested by

no test coverage detected