-
Notifications
You must be signed in to change notification settings - Fork 0
/
visuModels.py
168 lines (158 loc) · 5.49 KB
/
visuModels.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
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
162
163
164
165
166
167
168
# --------------------------------------------------------
# floor_recog
# Written by Sai Prabhakar
# CMU-RI Masters
# --------------------------------------------------------
from modifiedSiamese.SiameseTrainer import *
from modifiedSiamese.analyse_vis import *
#to visualize toggle train and visu
#to test toggle only train
#to save all the possible masks of visualization use visu_all_pos and visu
v = 1
#net = "floor"
net = "places"
tech = 'both'
save_data = 1
save_img = 0
if v == 1:
visu = 1
visu_all_pos = True #False
analyse_all_visualizations = 0
else:
visu = 0
visu_all_pos = False
analyse_all_visualizations = 1
heat_mask_ratio = 0.05
test_prototxt0 = None
test_prototxt1 = None
viz_tech = ['occ', 'grad', 'exci']
if net == "floor":
netSize = 1000
if 'occ' in viz_tech or 'exci' in viz_tech:
test_prototxt0 = 'modifiedSiameseModels/extracted_siamesePlaces_' + str(
netSize) + '_test.prototxt'
if 'grad' in viz_tech:
test_prototxt1 = 'modifiedSiameseModels/grad_visu_extracted_siamesePlaces_' + str(
netSize) + '_test.prototxt'
meanfile = 'placesOriginalModel/places205CNN_mean.binaryproto'
trainedModel = 'modifiedNetResults/Modified-netsize-1000-epoch-18-tstamp--Timestamp-2017-01-22-20:02:03-net.caffemodel'
fileName_test_visu = 'data/data_floor/imagelist_all.txt'
class_size = 6
class_adju = 2
data_folder = 'data/data_floor/'
im_target_size = 227
final_layer = 'fc9_f' #final_layer
data_index = ''
outputLayerName = 'pool2'
outputBlobName = 'pool2'
#outputLayerName = 'conv2'
#outputBlobName = 'conv2'
topBlobName = 'fc9_f'
topLayerName = 'fc9_f'
secondTopLayerName = 'fc8_s'
secondTopBlobName = 'fc8_s_r'
elif net == "places":
netSize = 1000
if 'occ' in viz_tech or 'exci' in viz_tech:
test_prototxt0 = 'placesOriginalModel/deploy_alexnet_places365.prototxt'
if 'grad' in viz_tech:
test_prototxt1 = 'placesOriginalModel/grad_visu_deploy_alexnet_places365.prototxt'
meanfile = 'placesOriginalModel/places365CNN_mean.binaryproto'
trainedModel = 'placesOriginalModel/alexnet_places365.caffemodel' #None
data_index = ''
fileName_test_visu = 'data/data_places/images_all' + data_index + '.txt'
class_size = 365
class_adju = 0
data_folder = 'data/data_places/val_256/'
im_target_size = 227
final_layer = 'fc8' #final_layer
outputLayerName = 'pool2'
outputBlobName = 'pool2'
topBlobName = 'fc8'
topLayerName = 'fc8'
secondTopLayerName = 'fc7'
secondTopBlobName = 'fc7'
print heat_mask_ratio
print fileName_test_visu
#####################################################
pretrained_model_proto = None #'placesOriginalModel/places_processed.prototxt'
pretrained_model = None #'placesOriginalModel/places205CNN_iter_300000_upgraded.caffemodel'
siameseSolver = None #'modifiedSiameseModels/siamesePlaces_' + str(netSize) + '_solver.prototxt'
train = 0
# mkdir <net>_NetResults_visu_grad/occ
#save dir is used by cam too
visu_all_save_dir = "visu/" + net + '_NetResults_visu' + data_index
visu_all_analyse_dir = 'visu/' + net + '_NetResults_visu' + data_index + '/'
#visu_all_analyse_dir = 'visu/' + net + '_NetResults_visu_back/'
testProto1 = None
compare = 1
size_patch_s = []
dilate_iteration_s = []
if visu == 1:
#load appropriate model while testing
pretrainedSiameseModel = trainedModel
if tech == 'both':
testProto = test_prototxt0
testProto1 = test_prototxt1
compare = 1
size_patch_s = [10, 50, 100]
dilate_iteration_s = [0, 2, 5]
tech = viz_tech
elif analyse_all_visualizations == 1:
# loading test prototype for analysis
pretrainedSiameseModel = trainedModel
testProto = test_prototxt0
_run = []
if analyse_all_visualizations == 1:
analyseNet(
pretrainedSiameseModel=pretrainedSiameseModel,
testProto=testProto,
analyse_all_visualizations=analyse_all_visualizations,
visu_all_analyse_dir=visu_all_analyse_dir,
fileName_test_visu=fileName_test_visu,
viz_tech=tech,
meanfile=meanfile,
netSize=netSize,
class_size=class_size,
class_adju=class_adju,
heat_mask_ratio=heat_mask_ratio,
im_target_size=im_target_size,
final_layer=final_layer,
net=net,
save_img=save_img,
save_data=save_data,
data_folder=data_folder)
elif visu == 1:
siameseTrainer(
siameseSolver=siameseSolver,
pretrainedSiameseModel=pretrainedSiameseModel,
fileName_test_visu=fileName_test_visu,
pretrained_model=pretrained_model,
pretrained_model_proto=pretrained_model_proto,
testProto=testProto,
testProto1=testProto1,
compare=compare,
im_target_size=im_target_size,
train=train,
visu=visu,
visu_all=visu_all_pos,
heat_mask_ratio=heat_mask_ratio,
visu_all_save_dir=visu_all_save_dir,
viz_tech=tech,
meanfile=meanfile,
net=net,
final_layer=final_layer,
data_folder=data_folder,
class_size=class_size,
class_adju=class_adju,
save=save_data,
save_img=save_img,
netSize=netSize,
outputLayerName=outputLayerName,
outputBlobName=outputBlobName,
topLayerName=topLayerName,
topBlobName=topBlobName,
secondTopLayerName=secondTopLayerName,
secondTopBlobName=secondTopBlobName,
dilate_iteration_s=dilate_iteration_s,
size_patch_s=size_patch_s)