-
Notifications
You must be signed in to change notification settings - Fork 53
/
data_loader.py
90 lines (84 loc) · 4.45 KB
/
data_loader.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import torch
import torchvision
import folders
class DataLoader(object):
"""Dataset class for IQA databases"""
def __init__(self, dataset, path, img_indx, patch_size, patch_num, batch_size=1, istrain=True):
self.batch_size = batch_size
self.istrain = istrain
if (dataset == 'live') | (dataset == 'csiq') | (dataset == 'tid2013') | (dataset == 'livec'):
# Train transforms
if istrain:
transforms = torchvision.transforms.Compose([
torchvision.transforms.RandomHorizontalFlip(),
torchvision.transforms.RandomCrop(size=patch_size),
torchvision.transforms.ToTensor(),
torchvision.transforms.Normalize(mean=(0.485, 0.456, 0.406),
std=(0.229, 0.224, 0.225))
])
# Test transforms
else:
transforms = torchvision.transforms.Compose([
torchvision.transforms.RandomCrop(size=patch_size),
torchvision.transforms.ToTensor(),
torchvision.transforms.Normalize(mean=(0.485, 0.456, 0.406),
std=(0.229, 0.224, 0.225))
])
elif dataset == 'koniq-10k':
if istrain:
transforms = torchvision.transforms.Compose([
torchvision.transforms.RandomHorizontalFlip(),
torchvision.transforms.Resize((512, 384)),
torchvision.transforms.RandomCrop(size=patch_size),
torchvision.transforms.ToTensor(),
torchvision.transforms.Normalize(mean=(0.485, 0.456, 0.406),
std=(0.229, 0.224, 0.225))])
else:
transforms = torchvision.transforms.Compose([
torchvision.transforms.Resize((512, 384)),
torchvision.transforms.RandomCrop(size=patch_size),
torchvision.transforms.ToTensor(),
torchvision.transforms.Normalize(mean=(0.485, 0.456, 0.406),
std=(0.229, 0.224, 0.225))])
elif dataset == 'bid':
if istrain:
transforms = torchvision.transforms.Compose([
torchvision.transforms.RandomHorizontalFlip(),
torchvision.transforms.Resize((512, 512)),
torchvision.transforms.RandomCrop(size=patch_size),
torchvision.transforms.ToTensor(),
torchvision.transforms.Normalize(mean=(0.485, 0.456, 0.406),
std=(0.229, 0.224, 0.225))])
else:
transforms = torchvision.transforms.Compose([
torchvision.transforms.Resize((512, 512)),
torchvision.transforms.RandomCrop(size=patch_size),
torchvision.transforms.ToTensor(),
torchvision.transforms.Normalize(mean=(0.485, 0.456, 0.406),
std=(0.229, 0.224, 0.225))])
if dataset == 'live':
self.data = folders.LIVEFolder(
root=path, index=img_indx, transform=transforms, patch_num=patch_num)
elif dataset == 'livec':
self.data = folders.LIVEChallengeFolder(
root=path, index=img_indx, transform=transforms, patch_num=patch_num)
elif dataset == 'csiq':
self.data = folders.CSIQFolder(
root=path, index=img_indx, transform=transforms, patch_num=patch_num)
elif dataset == 'koniq-10k':
self.data = folders.Koniq_10kFolder(
root=path, index=img_indx, transform=transforms, patch_num=patch_num)
elif dataset == 'bid':
self.data = folders.BIDFolder(
root=path, index=img_indx, transform=transforms, patch_num=patch_num)
elif dataset == 'tid2013':
self.data = folders.TID2013Folder(
root=path, index=img_indx, transform=transforms, patch_num=patch_num)
def get_data(self):
if self.istrain:
dataloader = torch.utils.data.DataLoader(
self.data, batch_size=self.batch_size, shuffle=True)
else:
dataloader = torch.utils.data.DataLoader(
self.data, batch_size=1, shuffle=False)
return dataloader