Change downsample_dataset to do no image modification

I'm  preprocessing the images myself now. There's no need to have
the dataset do this processing as well.
This commit is contained in:
James Betker 2020-04-28 11:50:04 -06:00
parent 8ab595e427
commit 46f550e42b

View File

@ -20,6 +20,7 @@ class DownsampleDataset(data.Dataset):
self.paths_LQ, self.paths_GT = None, None self.paths_LQ, self.paths_GT = None, None
self.sizes_LQ, self.sizes_GT = None, None self.sizes_LQ, self.sizes_GT = None, None
self.LQ_env, self.GT_env = None, None # environments for lmdb self.LQ_env, self.GT_env = None, None # environments for lmdb
self.doCrop = self.opt['doCrop']
self.paths_GT, self.sizes_GT = util.get_image_paths(self.data_type, opt['dataroot_GT']) self.paths_GT, self.sizes_GT = util.get_image_paths(self.data_type, opt['dataroot_GT'])
self.paths_LQ, self.sizes_LQ = util.get_image_paths(self.data_type, opt['dataroot_LQ']) self.paths_LQ, self.sizes_LQ = util.get_image_paths(self.data_type, opt['dataroot_LQ'])
@ -75,13 +76,18 @@ class DownsampleDataset(data.Dataset):
H, W, C = img_LQ.shape H, W, C = img_LQ.shape
LQ_size = GT_size // scale LQ_size = GT_size // scale
# randomly crop if self.doCrop:
rnd_h = random.randint(0, max(0, H - LQ_size)) # randomly crop
rnd_w = random.randint(0, max(0, W - LQ_size)) rnd_h = random.randint(0, max(0, H - LQ_size))
img_LQ = img_LQ[rnd_h:rnd_h + LQ_size, rnd_w:rnd_w + LQ_size, :] rnd_w = random.randint(0, max(0, W - LQ_size))
img_Downsampled = img_Downsampled[rnd_h:rnd_h + LQ_size, rnd_w:rnd_w + LQ_size, :] img_LQ = img_LQ[rnd_h:rnd_h + LQ_size, rnd_w:rnd_w + LQ_size, :]
rnd_h_GT, rnd_w_GT = int(rnd_h * scale), int(rnd_w * scale) img_Downsampled = img_Downsampled[rnd_h:rnd_h + LQ_size, rnd_w:rnd_w + LQ_size, :]
img_GT = img_GT[rnd_h_GT:rnd_h_GT + GT_size, rnd_w_GT:rnd_w_GT + GT_size, :] rnd_h_GT, rnd_w_GT = int(rnd_h * scale), int(rnd_w * scale)
img_GT = img_GT[rnd_h_GT:rnd_h_GT + GT_size, rnd_w_GT:rnd_w_GT + GT_size, :]
else:
img_LQ = cv2.resize(img_LQ, (LQ_size, LQ_size), interpolation=cv2.INTER_LINEAR)
img_Downsampled = cv2.resize(img_Downsampled, (LQ_size, LQ_size), interpolation=cv2.INTER_LINEAR)
img_GT = cv2.resize(img_GT, (GT_size, GT_size), interpolation=cv2.INTER_LINEAR)
# augmentation - flip, rotate # augmentation - flip, rotate
img_LQ, img_GT, img_Downsampled = util.augment([img_LQ, img_GT, img_Downsampled], self.opt['use_flip'], img_LQ, img_GT, img_Downsampled = util.augment([img_LQ, img_GT, img_Downsampled], self.opt['use_flip'],