-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
41 lines (30 loc) · 919 Bytes
/
main.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
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 net
import numpy as np
from torchvision import transforms
from PIL import Image
import glob
def unfog_image(image_path):
data_foggy = Image.open(image_path)
data_foggy = (np.asarray(data_foggy) / 255.0)
data_foggy = torch.from_numpy(data_foggy).float()
data_foggy = data_foggy.permute(2, 0, 1)
data_foggy = data_foggy.cuda().unsqueeze(0)
unfog_net = net.unfog_net().cuda()
unfog_net.load_state_dict(torch.load('snapshots/net.pth'))
clean_image = unfog_net(data_foggy)
torchvision.utils.save_image(torch.cat((data_foggy, clean_image),0), "results/" + image_path.split("/")[-1])
if __name__ == '__main__':
test_list = glob.glob("test_images/*")
for image in test_list:
unfog_image(image)
print(image, "done!")