def __getitem__(self, index): input = self.images[index % self.len] if self.augmentations is not None: input = self.augmentations(input) if self.crop_size != -1: # For training, take random crop. if input.size[0] < self.crop_size or input.size[1] < self.crop_size: input = input.resize((self.crop_size, self.crop_size), Image.BICUBIC) else: input = RandomCrop(self.crop_size)(input) else: # For testing, we want to take the whole image. width, height = input.size[:2] width = width - (width % self.upscale_factor) height = height - (height % self.upscale_factor) input = CenterCrop((height, width))(input) # Make a high-resolution copy. target = input.copy() # Downsample to create image at low-res. # We already make sure that crop_size divides upscale_factor. input = input.resize( (input.size[0]//self.upscale_factor, input.size[1]//self.upscale_factor), Image.BICUBIC) # Upsample using bicubic interpolation. input = input.resize(target.size, Image.BICUBIC) input = ToTensor()(input) target = ToTensor()(target) return input, target
def __getitem__(self, index): input = self.images[index % self.len] if self.augmentations is not None: input = self.augmentations(input) if self.crop_size != -1: # For training, take random crop. if input.size[0] < self.crop_size or input.size[1] < self.crop_size: input = input.resize((self.crop_size, self.crop_size), Image.BICUBIC) else: input = RandomCrop(self.crop_size)(input) else: # For testing, we want to take the whole image. width, height = input.size[:2] width = width - (width % self.upscale_factor) height = height - (height % self.upscale_factor) input = CenterCrop((height, width))(input) # LapSRN employs deep supervision, so there will be multiple targets # (one target at each level). targets = [input.copy()] input = input.resize((input.size[0] // 2, input.size[1] // 2), Image.BICUBIC) n_levels = int(np.log2(self.upscale_factor)) for i in range(n_levels - 1): targets = [input] + targets input = input.resize((input.size[0] // 2, input.size[1] // 2), Image.BICUBIC) input = ToTensor()(input) for i in range(n_levels): targets[i] = ToTensor()(targets[i]) return input, targets