-
Notifications
You must be signed in to change notification settings - Fork 0
/
3-Test.py
executable file
·178 lines (153 loc) · 9.56 KB
/
3-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
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
169
170
171
172
173
174
175
176
177
178
import json
import argparse
import torch
from dataset.dataset import RADIal
import cv2
from utils.util import SegmentationHMI
#### Importing all the architectures ####
from model.only_camera import SegmentationHead_onlycam
from model.early_fusion import SegmentationHead_earlyfusion
from model.x0_featureblock_fusion import SegmentationHead_x0
from model.x1_featureblock_fusion import SegmentationHead_x1
from model.x2_featureblock_fusion import SegmentationHead_x2
from model.x3_featureblock_fusion import SegmentationHead_x3
from model.x4_featureblock_fusion import SegmentationHead_x4
from model.after_decoder_fusion import SegmentationHead_afterdec
gpu_id = 0
def main(config, checkpoint_filename,difficult):
# set device
device = torch.device('cuda:' + str(gpu_id) if torch.cuda.is_available() else 'cpu')
print("Device used:", device)
# Load the dataset
dataset = RADIal(root_dir = config['dataset']['root_dir'],
statistics=config['dataset']['statistics'],
difficult=difficult)
# Create the model
if (config['architecture']['only_camera'] == 'True'):
net = SegmentationHead_onlycam(channels_bev=config['model']['channels_bev'],
blocks=config['model']['backbone_block'],
segmentation_head=config['model']['SegmentationHead'],
camera_input=config['model']['camera_input'],
)
print("*********************************************")
print("Qualitative results: Only camera architecture")
print("*********************************************")
if (config['architecture']['early_fusion'] == 'True'):
net = SegmentationHead_earlyfusion(mimo_layer=config['model']['MIMO_output'],
channels=config['model']['channels'],
blocks=config['model']['backbone_block'],
segmentation_head=config['model']['SegmentationHead'],
radar_input=config['model']['radar_input'],
camera_input=config['model']['camera_input'],
fusion=config['model']['fusion']
)
print("**********************************************")
print("Qualitative results: Early fusion architecture")
print("**********************************************")
if (config['architecture']['x0_fusion'] == 'True'):
net = SegmentationHead_x0(mimo_layer=config['model']['MIMO_output'],
channels=config['model']['channels'],
channels_bev=config['model']['channels_bev'],
blocks=config['model']['backbone_block'],
segmentation_head=config['model']['SegmentationHead'],
radar_input=config['model']['radar_input'],
camera_input=config['model']['camera_input'],
fusion=config['model']['fusion']
)
print("*******************************************")
print("Qualitative results: x0 fusion architecture")
print("*******************************************")
if (config['architecture']['x1_fusion'] == 'True'):
net = SegmentationHead_x1(mimo_layer=config['model']['MIMO_output'],
channels=config['model']['channels'],
channels_bev=config['model']['channels_bev'],
blocks=config['model']['backbone_block'],
segmentation_head=config['model']['SegmentationHead'],
radar_input=config['model']['radar_input'],
camera_input=config['model']['camera_input'],
fusion=config['model']['fusion']
)
print("*******************************************")
print("Qualitative results: x1 fusion architecture")
print("*******************************************")
if (config['architecture']['x2_fusion'] == 'True'):
net = SegmentationHead_x2(mimo_layer=config['model']['MIMO_output'],
channels=config['model']['channels'],
channels_bev=config['model']['channels_bev'],
blocks=config['model']['backbone_block'],
segmentation_head=config['model']['SegmentationHead'],
radar_input=config['model']['radar_input'],
camera_input=config['model']['camera_input'],
fusion=config['model']['fusion']
)
print("*******************************************")
print("Qualitative results: x2 fusion architecture")
print("*******************************************")
if (config['architecture']['x3_fusion'] == 'True'):
net = SegmentationHead_x3(mimo_layer=config['model']['MIMO_output'],
channels=config['model']['channels'],
channels_bev=config['model']['channels_bev'],
blocks=config['model']['backbone_block'],
segmentation_head=config['model']['SegmentationHead'],
radar_input=config['model']['radar_input'],
camera_input=config['model']['camera_input'],
fusion=config['model']['fusion']
)
print("*******************************************")
print("Qualitative results: x3 fusion architecture")
print("*******************************************")
if (config['architecture']['x4_fusion'] == 'True'):
net = SegmentationHead_x4(mimo_layer=config['model']['MIMO_output'],
channels=config['model']['channels'],
channels_bev=config['model']['channels_bev'],
blocks=config['model']['backbone_block'],
segmentation_head=config['model']['SegmentationHead'],
radar_input=config['model']['radar_input'],
camera_input=config['model']['camera_input'],
fusion=config['model']['fusion']
)
print("*******************************************")
print("Qualitative results: x4 fusion architecture")
print("*******************************************")
if (config['architecture']['after_decoder_fusion'] == 'True'):
net = SegmentationHead_afterdec(mimo_layer=config['model']['MIMO_output'],
channels=config['model']['channels'],
channels_bev=config['model']['channels_bev'],
blocks=config['model']['backbone_block'],
segmentation_head=config['model']['SegmentationHead'],
radar_input=config['model']['radar_input'],
camera_input=config['model']['camera_input'],
fusion=config['model']['fusion']
)
print("******************************************************")
print("Qualitative results: After decoder fusion architecture")
print("******************************************************")
net.to(device)
# Load the model
dict = torch.load(checkpoint_filename, map_location=torch.device(device))
net.load_state_dict(dict['net_state_dict'])
net.eval()
for data in dataset:
ra_inputs = torch.tensor(data[0]).permute(2,0,1).to(device).float().unsqueeze(0)
bev_inputs = torch.tensor(data[2]).permute(2, 0, 1).to(device).float().unsqueeze(0)
with torch.set_grad_enabled(False):
if (config['model']['fusion'] == 'True'):
outputs = net(ra_inputs, bev_inputs)
else:
outputs = net(bev_inputs)
hmi = SegmentationHMI(data[3], data[2], data[0], outputs)
cv2.imshow(' (a)Camera Image (b)RD Spectrum (c)Camera Image in BEV (d)Free Space Segmentation', hmi)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
if __name__=='__main__':
# PARSE THE ARGS
parser = argparse.ArgumentParser(description='PolarSegFusionNet test')
parser.add_argument('-c', '--config', default="config.json",type=str,
help='Path to the config file (default: config.json)')
parser.add_argument('-r', '--checkpoint', default=".pth", type=str,
help='Path to the .pth model checkpoint to resume training')
parser.add_argument('--difficult', action='store_true')
args = parser.parse_args()
config = json.load(open(args.config))
main(config, args.checkpoint,args.difficult)