-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
50 lines (39 loc) · 1.1 KB
/
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
import torch
import numpy as np
import matplotlib.pyplot as plt
import torchvision
from torchvision import datasets, transforms
import torch.optim as optim
import torch.nn as nn
from dataset_test import GetLoader
import os
import models
batch_size=1
model_path =os.path.join('.','checkpoint','10.pth')
val_list = os.path.join('.','data','cityscapes','val.txt')
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))
])
valset = GetLoader(
data_root=os.path.join('.','data','cityscapes','val'),
data_list= val_list,
transform1=transforms.ToTensor(),
transform2=transforms.ToTensor()
)
valloader = torch.utils.data.DataLoader(
dataset=valset,
batch_size=batch_size,
shuffle=False,
num_workers=4)
model = models.Generator(d=64)
checkpoint = torch.load(model_path)
model.load_state_dict(checkpoint['G_state_dict'])
model.train()
img_paths = valset.img_paths
i=0
for img1,img2 in valloader:
fake_img1 = model(img2)
torchvision.utils.save_image(fake_img1,os.path.join('.','results','10',str(img_paths[i])))
i+=1
print(i)