Skip to content

Commit d5e62dd

Browse files
author
Taesung Park
committed
fixed mismatch between torchvision.transforms and PIL in interpolation method types
1 parent 877d931 commit d5e62dd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Diff for: data/base_dataset.py

+10
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,16 @@ def get_transform(opt, params=None, grayscale=False, method=transforms.Interpola
112112
return transforms.Compose(transform_list)
113113

114114

115+
def __transforms2pil_resize(method):
116+
mapper = {transforms.InterpolationMode.BILINEAR: Image.BILINEAR,
117+
transforms.InterpolationMode.BICUBIC: Image.BICUBIC,
118+
transforms.InterpolationMode.NEAREST: Image.NEAREST,
119+
transforms.InterpolationMode.LANCZOS: Image.LANCZOS,}
120+
return mapper[method]
121+
122+
115123
def __make_power_2(img, base, method=transforms.InterpolationMode.BICUBIC):
124+
method = __transforms2pil_resize(method)
116125
ow, oh = img.size
117126
h = int(round(oh / base) * base)
118127
w = int(round(ow / base) * base)
@@ -124,6 +133,7 @@ def __make_power_2(img, base, method=transforms.InterpolationMode.BICUBIC):
124133

125134

126135
def __scale_width(img, target_size, crop_size, method=transforms.InterpolationMode.BICUBIC):
136+
method = __transforms2pil_resize(method)
127137
ow, oh = img.size
128138
if ow == target_size and oh >= crop_size:
129139
return img

0 commit comments

Comments
 (0)