3232from ..layers import MaxPooling2D
3333from ..layers import GlobalAveragePooling2D
3434from ..layers import GlobalMaxPooling2D
35+ from ..layers import ZeroPadding2D
3536from ..engine .topology import get_source_inputs
3637from ..utils .data_utils import get_file
38+ from ..utils import layer_utils
3739from .. import backend as K
3840from . import imagenet_utils
3941from .imagenet_utils import decode_predictions
@@ -136,7 +138,8 @@ def Xception(include_top=True, weights='imagenet',
136138 else :
137139 img_input = input_tensor
138140
139- x = Conv2D (32 , (3 , 3 ), strides = (2 , 2 ), use_bias = False , name = 'block1_conv1' )(img_input )
141+ x = ZeroPadding2D (padding = (1 , 1 ))(img_input )
142+ x = Conv2D (32 , (3 , 3 ), strides = (2 , 2 ), use_bias = False , name = 'block1_conv1' )(x )
140143 x = BatchNormalization (name = 'block1_conv1_bn' )(x )
141144 x = Activation ('relu' , name = 'block1_conv1_act' )(x )
142145 x = Conv2D (64 , (3 , 3 ), use_bias = False , name = 'block1_conv2' )(x )
@@ -153,7 +156,8 @@ def Xception(include_top=True, weights='imagenet',
153156 x = SeparableConv2D (128 , (3 , 3 ), padding = 'same' , use_bias = False , name = 'block2_sepconv2' )(x )
154157 x = BatchNormalization (name = 'block2_sepconv2_bn' )(x )
155158
156- x = MaxPooling2D ((3 , 3 ), strides = (2 , 2 ), padding = 'same' , name = 'block2_pool' )(x )
159+ x = ZeroPadding2D (padding = (1 , 1 ))(x )
160+ x = MaxPooling2D ((3 , 3 ), strides = (2 , 2 ), padding = 'valid' , name = 'block2_pool' )(x )
157161 x = layers .add ([x , residual ])
158162
159163 residual = Conv2D (256 , (1 , 1 ), strides = (2 , 2 ),
@@ -167,7 +171,8 @@ def Xception(include_top=True, weights='imagenet',
167171 x = SeparableConv2D (256 , (3 , 3 ), padding = 'same' , use_bias = False , name = 'block3_sepconv2' )(x )
168172 x = BatchNormalization (name = 'block3_sepconv2_bn' )(x )
169173
170- x = MaxPooling2D ((3 , 3 ), strides = (2 , 2 ), padding = 'same' , name = 'block3_pool' )(x )
174+ x = ZeroPadding2D (padding = (1 , 1 ))(x )
175+ x = MaxPooling2D ((3 , 3 ), strides = (2 , 2 ), padding = 'valid' , name = 'block3_pool' )(x )
171176 x = layers .add ([x , residual ])
172177
173178 residual = Conv2D (728 , (1 , 1 ), strides = (2 , 2 ),
@@ -181,7 +186,8 @@ def Xception(include_top=True, weights='imagenet',
181186 x = SeparableConv2D (728 , (3 , 3 ), padding = 'same' , use_bias = False , name = 'block4_sepconv2' )(x )
182187 x = BatchNormalization (name = 'block4_sepconv2_bn' )(x )
183188
184- x = MaxPooling2D ((3 , 3 ), strides = (2 , 2 ), padding = 'same' , name = 'block4_pool' )(x )
189+ x = ZeroPadding2D (padding = (1 , 1 ))(x )
190+ x = MaxPooling2D ((3 , 3 ), strides = (2 , 2 ), padding = 'valid' , name = 'block4_pool' )(x )
185191 x = layers .add ([x , residual ])
186192
187193 for i in range (8 ):
@@ -211,7 +217,8 @@ def Xception(include_top=True, weights='imagenet',
211217 x = SeparableConv2D (1024 , (3 , 3 ), padding = 'same' , use_bias = False , name = 'block13_sepconv2' )(x )
212218 x = BatchNormalization (name = 'block13_sepconv2_bn' )(x )
213219
214- x = MaxPooling2D ((3 , 3 ), strides = (2 , 2 ), padding = 'same' , name = 'block13_pool' )(x )
220+ x = ZeroPadding2D (padding = (1 , 1 ))(x )
221+ x = MaxPooling2D ((3 , 3 ), strides = (2 , 2 ), padding = 'valid' , name = 'block13_pool' )(x )
215222 x = layers .add ([x , residual ])
216223
217224 x = SeparableConv2D (1536 , (3 , 3 ), padding = 'same' , use_bias = False , name = 'block14_sepconv1' )(x )
@@ -256,6 +263,9 @@ def Xception(include_top=True, weights='imagenet',
256263 elif weights is not None :
257264 model .load_weights (weights )
258265
266+ if K .backend () == 'theano' :
267+ layer_utils .convert_all_kernels_in_model (model )
268+
259269 if old_data_format :
260270 K .set_image_data_format (old_data_format )
261271 return model
0 commit comments