forked from vision4robotics/DarkLighter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lowlight_test.py
58 lines (47 loc) · 1.45 KB
/
lowlight_test.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
import torch
import torch.nn as nn
import torchvision
import torch.backends.cudnn as cudnn
import torch.optim
import os
import sys
import argparse
import time
import dataloader
import DarkLighter_model as model
import numpy as np
from torchvision import transforms
from PIL import Image
import glob
import time
import pdb
import cv2
def lowlight(image_path, DarkLighter):
os.environ['CUDA_VISIBLE_DEVICES']='1'
data_lowlight = Image.open(image_path)
data_lowlight = (np.asarray(data_lowlight)/255.0)
data_lowlight = torch.from_numpy(data_lowlight).float()
data_lowlight = data_lowlight.permute(2,0,1)
data_lowlight = data_lowlight.cuda().unsqueeze(0)
start = time.time()
enhanced_image,_,_ = DarkLighter(data_lowlight)
end_time = (time.time() - start)
print(end_time)
image_path = image_path.replace('test','result')
result_path = image_path
if not os.path.exists(image_path.replace('/'+image_path.split("/")[-1],'')):
os.makedirs(image_path.replace('/'+image_path.split("/")[-1],''))
torchvision.utils.save_image(enhanced_image, result_path)
if __name__ == '__main__':
# test_images
with torch.no_grad():
filePath = './data/test/'
file_list = os.listdir(filePath)
DarkLighter = model.enhancer().cuda()
DarkLighter.load_state_dict(torch.load('snapshots/Epoch193.pth'))
for file_name in file_list:
test_list = glob.glob(filePath+file_name+"/*")
for image in test_list:
# image = image
print(image)
lowlight(image, DarkLighter)