@@ -49,27 +49,22 @@ def validate(args):
49
49
images = Variable (images .cuda (), volatile = True )
50
50
#labels = Variable(labels.cuda(), volatile=True)
51
51
52
- if model_name == 'pspnet' :
53
- outputs = model (images )[- 1 ]
54
- if args .include_flip_mode :
55
- outputs = outputs .data .cpu ().numpy ()
56
- flipped_images = np .copy (images .data .cpu ().numpy ()[:, :, :, ::- 1 ])
57
- flipped_images = Variable (torch .from_numpy ( flipped_images ).float ().cuda (), volatile = True )
58
- outputs_flipped = model ( flipped_images )[- 1 ].data .cpu ().numpy ()
59
- outputs = (outputs + outputs_flipped [:, :, :, ::- 1 ]) / 2.0
60
- else :
52
+ if args .eval_flip :
61
53
outputs = model (images )
62
- if args .include_flip_mode :
63
- outputs = outputs .data .cpu ().numpy ()
64
- flipped_images = np .copy (images .data .cpu ().numpy ()[:, :, :, ::- 1 ])
65
- flipped_images = Variable (torch .from_numpy ( flipped_images ).float ().cuda (), volatile = True )
66
- outputs_flipped = model ( flipped_images ).data .cpu ().numpy ()
67
- outputs = (outputs + outputs_flipped [:, :, :, ::- 1 ]) / 2.0
68
-
69
- if args .include_flip_mode :
70
- pred = np .argmax (outputs , axis = 1 ).astype (np .uint8 )
54
+
55
+ # Flip images in numpy (not support in tensor)
56
+ outputs = outputs .data .cpu ().numpy ()
57
+ flipped_images = np .copy (images .data .cpu ().numpy ()[:, :, :, ::- 1 ])
58
+ flipped_images = Variable (torch .from_numpy ( flipped_images ).float ().cuda (), volatile = True )
59
+ outputs_flipped = model ( flipped_images )
60
+ outputs_flipped = outputs_flipped .data .cpu ().numpy ()
61
+ outputs = (outputs + outputs_flipped [:, :, :, ::- 1 ]) / 2.0
62
+
63
+ pred = np .argmax (outputs , axis = 1 )
71
64
else :
72
- pred = outputs .data .max (1 )[1 ].cpu ().numpy ().astype (np .uint8 )
65
+ outputs = model (images )
66
+ pred = outputs .data .max (1 )[1 ].cpu ().numpy ()
67
+
73
68
#gt = labels.data.cpu().numpy()
74
69
gt = labels .numpy ()
75
70
@@ -103,11 +98,11 @@ def validate(args):
103
98
help = 'Disable input image scales normalization [0, 1] | True by default' )
104
99
parser .set_defaults (img_norm = True )
105
100
106
- parser .add_argument ('--include_flip_mode ' , dest = 'include_flip_mode ' , action = 'store_true' ,
101
+ parser .add_argument ('--eval_flip ' , dest = 'eval_flip ' , action = 'store_true' ,
107
102
help = 'Enable evaluation with flipped image | True by default' )
108
- parser .add_argument ('--no-include_flip_mode ' , dest = 'include_flip_mode ' , action = 'store_false' ,
103
+ parser .add_argument ('--no-eval_flip ' , dest = 'eval_flip ' , action = 'store_false' ,
109
104
help = 'Disable evaluation with flipped image | True by default' )
110
- parser .set_defaults (include_flip_mode = True )
105
+ parser .set_defaults (eval_flip = True )
111
106
112
107
parser .add_argument ('--batch_size' , nargs = '?' , type = int , default = 1 ,
113
108
help = 'Batch Size' )
0 commit comments