-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
161 lines (141 loc) · 4.49 KB
/
test.py
File metadata and controls
161 lines (141 loc) · 4.49 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import os
from torch.utils import data
from loader.image_label_loader import imageLabelLoader
from models.deeplab_g1_g2 import deeplabG1G2
from util.confusion_matrix import ConfusionMatrix
import torch
import numpy as np
import scipy.misc
def color(label):
bg = label == 0
bg = bg.reshape(bg.shape[0], bg.shape[1])
face = label == 1
face = face.reshape(face.shape[0], face.shape[1])
hair = label == 2
hair = hair.reshape(hair.shape[0], hair.shape[1])
Upcloth = label == 3
Upcloth = Upcloth.reshape(Upcloth.shape[0], Upcloth.shape[1])
Larm = label == 4
Larm = Larm.reshape(Larm.shape[0], Larm.shape[1])
Rarm = label == 5
Rarm = Rarm.reshape(Rarm.shape[0], Rarm.shape[1])
pants = label == 6
pants = pants.reshape(pants.shape[0], pants.shape[1])
Lleg = label == 7
Lleg = Lleg.reshape(Lleg.shape[0], Lleg.shape[1])
Rleg = label == 8
Rleg = Rleg.reshape(Rleg.shape[0], Rleg.shape[1])
dress = label == 9
dress = dress.reshape(dress.shape[0], dress.shape[1])
Lshoe = label == 10
Lshoe = Lshoe.reshape(Lshoe.shape[0], Lshoe.shape[1])
Rshoe = label == 11
Rshoe = Rshoe.reshape(Rshoe.shape[0], Rshoe.shape[1])
# bag = label == 12
# bag = bag.reshape(bag.shape[0], bag.shape[1])
# repeat 2nd axis to 3
label = label.reshape(bg.shape[0], bg.shape[1], 1)
label = label.repeat(3, 2)
R = label[:, :, 2]
G = label[:, :, 1]
B = label[:, :, 0]
R[bg] = 230
G[bg] = 230
B[bg] = 230
R[face] = 255
G[face] = 215
B[face] = 0
R[hair] = 80
G[hair] = 49
B[hair] = 49
R[Upcloth] = 51
G[Upcloth] = 0
B[Upcloth] = 255
R[Larm] = 2
G[Larm] = 251
B[Larm] = 49
R[Rarm] = 141
G[Rarm] = 255
B[Rarm] = 212
R[pants] = 160
G[pants] = 0
B[pants] = 255
R[Lleg] = 0
G[Lleg] = 204
B[Lleg] = 255
R[Rleg] = 191
G[Rleg] = 255
B[Rleg] = 248
R[dress] = 255
G[dress] = 182
B[dress] = 185
R[Lshoe] = 180
G[Lshoe] = 122
B[Lshoe] = 121
R[Rshoe] = 202
G[Rshoe] = 160
B[Rshoe] = 57
# R[bag] = 255
# G[bag] = 1
# B[bag] = 1
return label
def update_confusion_matrix(matrix, output, target):
values, indices = output.max(1)
output = indices
target = target.cpu().numpy()
output = output.cpu().numpy()
matrix.update(target, output)
return matrix
def main():
if len(args['device_ids']) > 0:
torch.cuda.set_device(args['device_ids'][0])
test_loader = data.DataLoader(imageLabelLoader(args['data_path'], dataName=args['domainB'], phase='test'),
batch_size=args['batch_size'],
num_workers=args['num_workers'], shuffle=False)
gym = deeplabG1G2()
gym.initialize(args)
gym.load('/home/ben/mathfinder/PROJECT/AAAI2017/our_Method/v3/deeplab_feature_adaptation/checkpoints/lr_g1=0.00001_lr_g2=0.00000001_interval_g1=6_interval_d1=6_net_D=lsganMultOutput_D_if_adaptive=True/best_Ori_on_B_model.pth')
gym.eval()
matrix = ConfusionMatrix(args['label_nums'])
for i, (image, label) in enumerate(test_loader):
label = label.cuda(async=True)
target_var = torch.autograd.Variable(label, volatile=True)
gym.test(image)
output = gym.output
matrix = update_confusion_matrix(matrix, output.data, label)
print(matrix.all_acc())
if __name__ == "__main__":
global args
args = {
'test_init':False,
'test_init':False,
'label_nums':12,
'l_rate':1e-8,
'lr_g1': 0.00001,
'lr_g2': 0.00000002,
'beta1': 0.5,
'interval_g2':5,
'interval_d2':5,
'data_path':'datasets',
'n_epoch':1000,
'batch_size':10,
'num_workers':10,
'print_freq':20,
'device_ids':[0],
'domainA': 'Lip',
'domainB': 'Indoor',
'weigths_pool': 'pretrain_models',
'pretrain_model': 'deeplab.pth',
'fineSizeH':241,
'fineSizeW':121,
'input_nc':3,
'name': 'lr_g1=0.00001_lr_g2=0.00000002_interval_g1=5_interval_d1=5_net_D=lsganMultOutput_D_if_adaptive=False',
'checkpoints_dir': 'checkpoints',
'net_d1': 'NoBNSinglePathdilationMultOutputNet',
'net_d2': 'lsganMultOutput_D',
'use_lsgan': True,
'resume':None,#'checkpoints/g2_lr_gan=0.0000002_interval_G=5_interval_D=10_net_D=lsganMultOutput_D/best_Ori_on_B_model.pth',#'checkpoints/v3_1/',
'if_adv_train':True,
'if_adaptive':False,
}
main()