-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatasets_LOL.py
81 lines (64 loc) · 3.23 KB
/
datasets_LOL.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
import glob
import random
import os
import numpy as np
import torch
import time
import cv2
from torch.utils.data import Dataset
from PIL import Image
import torchvision.transforms as transforms
import torchvision.transforms.functional as TF
import torchvision_x_functional as TF_x
class ImageDataset_sRGB(Dataset):
def __init__(self, root, mode="train"):
self.mode = mode
file = open(os.path.join(root,'LOL_train_input.txt'),'r')
set1_input_files = sorted(file.readlines())
self.set1_input_files = list()
self.set1_expert_files = list()
for i in range(len(set1_input_files)):
self.set1_input_files.append(os.path.join(root,"our485","low",set1_input_files[i][:-1] + ".png"))
self.set1_expert_files.append(os.path.join(root,"our485","high",set1_input_files[i][:-1] + ".png"))
file = open(os.path.join(root,'LOL_test_input.txt'),'r')
test_input_files = sorted(file.readlines())
self.test_input_files = list()
self.test_expert_files = list()
for i in range(len(test_input_files)):
self.test_input_files.append(os.path.join(root,"eval15","low",test_input_files[i][:-1] + ".png"))
self.test_expert_files.append(os.path.join(root,"eval15","high",test_input_files[i][:-1] + ".png"))
def __getitem__(self, index):
if self.mode == "train":
img_name = os.path.split(self.set1_input_files[index % len(self.set1_input_files)])[-1]
img_input = Image.open(self.set1_input_files[index % len(self.set1_input_files)])
img_exptC = Image.open(self.set1_expert_files[index % len(self.set1_expert_files)])
elif self.mode == "test":
img_name = os.path.split(self.test_input_files[index % len(self.test_input_files)])[-1]
img_input = Image.open(self.test_input_files[index % len(self.test_input_files)])
img_exptC = Image.open(self.test_expert_files[index % len(self.test_expert_files)])
if self.mode == "train":
ratio_H = np.random.uniform(0.6,1.0)
ratio_W = np.random.uniform(0.6,1.0)
W,H = img_input._size
crop_h = round(H*ratio_H)
crop_w = round(W*ratio_W)
i, j, h, w = transforms.RandomCrop.get_params(img_input, output_size=(crop_h, crop_w))
img_input = TF.crop(img_input, i, j, h, w)
img_exptC = TF.crop(img_exptC, i, j, h, w)
#img_input = TF.resized_crop(img_input, i, j, h, w, (320,320))
#img_exptC = TF.resized_crop(img_exptC, i, j, h, w, (320,320))
if np.random.random() > 0.5:
img_input = TF.hflip(img_input)
img_exptC = TF.hflip(img_exptC)
a = np.random.uniform(0.8,1.2)
img_input = TF.adjust_brightness(img_input,a)
a = np.random.uniform(0.8,1.2)
img_input = TF.adjust_saturation(img_input,a)
img_input = TF.to_tensor(img_input)
img_exptC = TF.to_tensor(img_exptC)
return {"A_input": img_input, "A_exptC": img_exptC, "input_name": img_name}
def __len__(self):
if self.mode == "train":
return len(self.set1_input_files)
elif self.mode == "test":
return len(self.test_input_files)