Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ImageDataset(Dataset):
- def __init__(self, highres, transform=None):
- """
- highres(list): high resolution np image list
- transform(callable, optional): Optional transform to be applied to a sample
- """
- self.highres = highres
- self.transform = transform
- def __len__(self):
- return len(self.highres)
- def __getitem__(self, idx):
- image_hr = self.highres[idx]
- rc = transforms.RandomCrop([41,41])
- toPIL = transforms.ToPILImage()
- toTens = transforms.ToTensor()
- #don't convert to tensor then .numpy()
- image_hr = np.array(rc(toPIL(image_hr)))
- image_lr2 = cv2.resize(image_hr, (0, 0), fx=0.5, fy=0.5, interpolation = cv2.INTER_CUBIC)
- image_lr2 = cv2.resize(image_lr2, (41, 41), interpolation = cv2.INTER_CUBIC)
- image_lr3 = cv2.resize(image_hr, (0, 0), fx=0.33, fy=0.33, interpolation = cv2.INTER_CUBIC)
- image_lr3 = cv2.resize(image_lr3, (41, 41), interpolation = cv2.INTER_CUBIC)
- image_lr4 = cv2.resize(image_hr, (0, 0), fx=0.25, fy=0.25, interpolation = cv2.INTER_CUBIC)
- image_lr4 = cv2.resize(image_lr4, (41, 41), interpolation = cv2.INTER_CUBIC)
- sample = {'hr': image_hr, 'lr2': image_lr2, 'lr3': image_lr3, 'lr4': image_lr4}
- if self.transform:
- sample['hr'] = self.transform(sample['hr'])
- sample['lr2'] = self.transform(sample['lr2'])
- sample['lr3'] = self.transform(sample['lr3'])
- sample['lr4'] = self.transform(sample['lr4'])
- return sample
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement