IanNathaniel commited on
Commit
5f7fa96
1 Parent(s): 7a8305f

Upload dataloader.py

Browse files
Files changed (1) hide show
  1. dataloader.py +59 -0
dataloader.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+
4
+ import torch
5
+ import torch.utils.data as data
6
+
7
+ import numpy as np
8
+ from PIL import Image
9
+ import glob
10
+ import random
11
+ import cv2
12
+
13
+ random.seed(1143)
14
+
15
+
16
+ def populate_train_list(lowlight_images_path):
17
+
18
+
19
+
20
+
21
+ image_list_lowlight = glob.glob(lowlight_images_path + "*.jpg")
22
+
23
+ train_list = image_list_lowlight
24
+
25
+ random.shuffle(train_list)
26
+
27
+ return train_list
28
+
29
+
30
+
31
+ class lowlight_loader(data.Dataset):
32
+
33
+ def __init__(self, lowlight_images_path):
34
+
35
+ self.train_list = populate_train_list(lowlight_images_path)
36
+ self.size = 256
37
+
38
+ self.data_list = self.train_list
39
+ print("Total training examples:", len(self.train_list))
40
+
41
+
42
+
43
+
44
+ def __getitem__(self, index):
45
+
46
+ data_lowlight_path = self.data_list[index]
47
+
48
+ data_lowlight = Image.open(data_lowlight_path)
49
+
50
+ data_lowlight = data_lowlight.resize((self.size,self.size), Image.ANTIALIAS)
51
+
52
+ data_lowlight = (np.asarray(data_lowlight)/255.0)
53
+ data_lowlight = torch.from_numpy(data_lowlight).float()
54
+
55
+ return data_lowlight.permute(2,0,1)
56
+
57
+ def __len__(self):
58
+ return len(self.data_list)
59
+