IanNathaniel commited on
Commit
7a8305f
1 Parent(s): 4d9f2fc

Upload lowlight_test.py

Browse files
Files changed (1) hide show
  1. lowlight_test.py +62 -0
lowlight_test.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+ import torchvision
4
+ import torch.backends.cudnn as cudnn
5
+ import torch.optim
6
+ import os
7
+ import sys
8
+ import argparse
9
+ import time
10
+ import dataloader
11
+ import model
12
+ import numpy as np
13
+ from torchvision import transforms
14
+ from PIL import Image
15
+ import glob
16
+ import time
17
+
18
+
19
+
20
+ def lowlight(image_path):
21
+ os.environ['CUDA_VISIBLE_DEVICES']='0'
22
+ data_lowlight = Image.open(image_path)
23
+
24
+
25
+
26
+ data_lowlight = (np.asarray(data_lowlight)/255.0)
27
+
28
+
29
+ data_lowlight = torch.from_numpy(data_lowlight).float()
30
+ data_lowlight = data_lowlight.permute(2,0,1)
31
+ data_lowlight = data_lowlight.cuda().unsqueeze(0)
32
+
33
+ DCE_net = model.enhance_net_nopool().cuda()
34
+ DCE_net.load_state_dict(torch.load('snapshots/Epoch99.pth'))
35
+ start = time.time()
36
+ _,enhanced_image,_ = DCE_net(data_lowlight)
37
+
38
+ end_time = (time.time() - start)
39
+ print(end_time)
40
+ image_path = image_path.replace('test_data','result')
41
+ result_path = image_path
42
+ if not os.path.exists(image_path.replace('/'+image_path.split("/")[-1],'')):
43
+ os.makedirs(image_path.replace('/'+image_path.split("/")[-1],''))
44
+
45
+ torchvision.utils.save_image(enhanced_image, result_path)
46
+
47
+ if __name__ == '__main__':
48
+ # test_images
49
+ with torch.no_grad():
50
+ filePath = 'data/test_data/'
51
+
52
+ file_list = os.listdir(filePath)
53
+
54
+ for file_name in file_list:
55
+ test_list = glob.glob(filePath+file_name+"/*")
56
+ for image in test_list:
57
+ # image = image
58
+ print(image)
59
+ lowlight(image)
60
+
61
+
62
+