-
Notifications
You must be signed in to change notification settings - Fork 1
/
GoProDataset.py
47 lines (36 loc) · 1.66 KB
/
GoProDataset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from collections import Counter
import os
import re
from PIL import Image
import torch
from torch.utils.data import Dataset
from torchvision import transforms
class GoProDataset(Dataset):
def __init__(self, image_dir, image_filename_pattern, length=224, width = 224):
self._image_dir = image_dir
self._image_filename_pattern = image_filename_pattern
self._blur_image_dir = self._image_dir + "blur"
self._sharp_image_dir = self._image_dir + "sharp"
self.length = length ## Resize size
self.width = width
def __len__(self):
return len([entry for entry in os.listdir(self._blur_image_dir) if os.path.isfile(os.path.join(self._blur_image_dir, entry))])
def __getitem__(self, idx):
name = str(idx)
if len(name) < 6:
name = '0' * (6 - len(name)) + name
img_name = self._image_filename_pattern.format(name)
_img_blur = Image.open(os.path.join(self._blur_image_dir, img_name)).convert('RGB')
_img_sharp = Image.open(os.path.join(self._sharp_image_dir, img_name)).convert('RGB')
width, height = _img_blur.size
max_dim = max(width, height)
preprocessing = transforms.Compose([
transforms.CenterCrop((672, 672)),
# transforms.Pad((0, 0, max_dim - width, max_dim - height)),
transforms.Resize((self.length, self.width)),
transforms.ToTensor(),
# transforms.Normalize([0.4332, 0.4223, 0.4177],[0.2337, 0.2298, 0.2323])
])
img_blur = preprocessing(_img_blur)
img_sharp = preprocessing(_img_sharp)
return (img_blur,img_sharp)