forked from YangZhang4065/AdaptationSeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_FCN_DA.py
44 lines (35 loc) · 1.56 KB
/
test_FCN_DA.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
# -*- coding: utf-8 -*-
import numpy as np
from warp_data import test_cityscape_generator
import sys
sys.path.insert(0,'./cityscapesScripts/cityscapesscripts/evaluation')
from city_meanIU import city_meanIU
image_size=[320,640]
batch_size=5
image_mean = np.zeros((1,3,1,1), dtype=np.float32)
image_mean[:,0,:,:] = 103.939
image_mean[:,1,:,:] = 116.779
image_mean[:,2,:,:] = 123.68
class_number=22
print('Start loading image')
loaded_test_im,loaded_test_label=test_cityscape_generator[range(len(test_cityscape_generator))]
loaded_test_im=loaded_test_im.astype('float32')-image_mean
#create network
from FCN_da import create_vgg16_FCN
seg_model=create_vgg16_FCN(image_size[0],image_size[1],class_number)
#test pretrained baseline model mean IoU
seg_model.load_weights('SYNTHIA_FCN.h5')
current_predicted_test=seg_model.predict(loaded_test_im,batch_size=batch_size)
current_predicted_test=current_predicted_test[0]
predicted_test_class=np.argmax(current_predicted_test,axis=1)
results_dict=city_meanIU(loaded_test_label,predicted_test_class)
test_mean_IU=results_dict['averageScoreClasses']
print('Baseline test mean IoU is '+str(test_mean_IU))
#test trained AdaptationSeg mean IoU
seg_model.load_weights('SYNTHIA_FCN_DA.h5')
current_predicted_test=seg_model.predict(loaded_test_im,batch_size=batch_size)
current_predicted_test=current_predicted_test[0]
predicted_test_class=np.argmax(current_predicted_test,axis=1)
results_dict=city_meanIU(loaded_test_label,predicted_test_class)
test_mean_IU=results_dict['averageScoreClasses']
print('AdaptationSeg test mean IoU is '+str(test_mean_IU))