Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    def __getitem__(self, index):
        input = load_img(self.image_filenames[index])
        #加数据增强
        if self.crop:
            input = RandomCrop(64)(input)
            input = RandomHorizontalFlip()(input)
            input = RandomVerticalFlip()(input)
            input = RandomRotation(180)(input)
        target = input.copy()
        if self.convert_L:
            input = input.convert('L')
            target = target.convert('L')
        if self.add_noise:
            input = noisy(input)
            input = ToPILImage()(input)
        input = ToTensor()(input)
        target = ToTensor()(target)
        guide = input.clone()
        input = torch.cat((input, guide), 0)

        return input, target
Exemplo n.º 3
0
    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