-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_loader.py
58 lines (52 loc) · 2.52 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
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 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))
])
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))
])
if dataset == 'kadis-700k':
self.data = folders.KADIS_700kFolder(
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 == '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 == 'pipal':
self.data = folders.PIPALFolder(
root=path, index=img_indx, transform=transforms, patch_num=patch_num)
elif dataset == 'spaq':
self.data = folders.SPAQFolder(
root=path, index=img_indx, transform=transforms, patch_num=patch_num)
elif dataset == 'kadid-10k':
self.data = folders.KADID_10kFolder(
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