4242
4343
4444class SeparableConv2d (nn .Module ):
45- def __init__ (self , inplanes , planes , kernel_size = 3 , stride = 1 ,
46- dilation = 1 , bias = False , norm_layer = None , norm_kwargs = None ):
45+ def __init__ (self , inplanes , planes , kernel_size = 3 , stride = 1 , dilation = 1 , bias = False , norm_layer = None ):
4746 super (SeparableConv2d , self ).__init__ ()
48- norm_kwargs = norm_kwargs if norm_kwargs is not None else {}
4947 self .kernel_size = kernel_size
5048 self .dilation = dilation
5149
@@ -54,7 +52,7 @@ def __init__(self, inplanes, planes, kernel_size=3, stride=1,
5452 self .conv_dw = nn .Conv2d (
5553 inplanes , inplanes , kernel_size , stride = stride ,
5654 padding = padding , dilation = dilation , groups = inplanes , bias = bias )
57- self .bn = norm_layer (num_features = inplanes , ** norm_kwargs )
55+ self .bn = norm_layer (num_features = inplanes )
5856 # pointwise convolution
5957 self .conv_pw = nn .Conv2d (inplanes , planes , kernel_size = 1 , bias = bias )
6058
@@ -66,10 +64,8 @@ def forward(self, x):
6664
6765
6866class Block (nn .Module ):
69- def __init__ (self , inplanes , planes , stride = 1 , dilation = 1 , start_with_relu = True ,
70- norm_layer = None , norm_kwargs = None , ):
67+ def __init__ (self , inplanes , planes , stride = 1 , dilation = 1 , start_with_relu = True , norm_layer = None ):
7168 super (Block , self ).__init__ ()
72- norm_kwargs = norm_kwargs if norm_kwargs is not None else {}
7369 if isinstance (planes , (list , tuple )):
7470 assert len (planes ) == 3
7571 else :
@@ -80,17 +76,16 @@ def __init__(self, inplanes, planes, stride=1, dilation=1, start_with_relu=True,
8076 self .skip = nn .Sequential ()
8177 self .skip .add_module ('conv1' , nn .Conv2d (
8278 inplanes , outplanes , 1 , stride = stride , bias = False )),
83- self .skip .add_module ('bn1' , norm_layer (num_features = outplanes , ** norm_kwargs ))
79+ self .skip .add_module ('bn1' , norm_layer (num_features = outplanes ))
8480 else :
8581 self .skip = None
8682
8783 rep = OrderedDict ()
8884 for i in range (3 ):
8985 rep ['act%d' % (i + 1 )] = nn .ReLU (inplace = True )
9086 rep ['conv%d' % (i + 1 )] = SeparableConv2d (
91- inplanes , planes [i ], 3 , stride = stride if i == 2 else 1 , dilation = dilation ,
92- norm_layer = norm_layer , norm_kwargs = norm_kwargs )
93- rep ['bn%d' % (i + 1 )] = norm_layer (planes [i ], ** norm_kwargs )
87+ inplanes , planes [i ], 3 , stride = stride if i == 2 else 1 , dilation = dilation , norm_layer = norm_layer )
88+ rep ['bn%d' % (i + 1 )] = norm_layer (planes [i ])
9489 inplanes = planes [i ]
9590
9691 if not start_with_relu :
@@ -115,74 +110,63 @@ class Xception65(nn.Module):
115110 """
116111
117112 def __init__ (self , num_classes = 1000 , in_chans = 3 , output_stride = 32 , norm_layer = nn .BatchNorm2d ,
118- norm_kwargs = None , drop_rate = 0. , global_pool = 'avg' ):
113+ drop_rate = 0. , global_pool = 'avg' ):
119114 super (Xception65 , self ).__init__ ()
120115 self .num_classes = num_classes
121116 self .drop_rate = drop_rate
122- norm_kwargs = norm_kwargs if norm_kwargs is not None else {}
123117 if output_stride == 32 :
124118 entry_block3_stride = 2
125119 exit_block20_stride = 2
126- middle_block_dilation = 1
127- exit_block_dilations = (1 , 1 )
120+ middle_dilation = 1
121+ exit_dilation = (1 , 1 )
128122 elif output_stride == 16 :
129123 entry_block3_stride = 2
130124 exit_block20_stride = 1
131- middle_block_dilation = 1
132- exit_block_dilations = (1 , 2 )
125+ middle_dilation = 1
126+ exit_dilation = (1 , 2 )
133127 elif output_stride == 8 :
134128 entry_block3_stride = 1
135129 exit_block20_stride = 1
136- middle_block_dilation = 2
137- exit_block_dilations = (2 , 4 )
130+ middle_dilation = 2
131+ exit_dilation = (2 , 4 )
138132 else :
139133 raise NotImplementedError
140134
141135 # Entry flow
142136 self .conv1 = nn .Conv2d (in_chans , 32 , kernel_size = 3 , stride = 2 , padding = 1 , bias = False )
143- self .bn1 = norm_layer (num_features = 32 , ** norm_kwargs )
137+ self .bn1 = norm_layer (num_features = 32 )
144138 self .act1 = nn .ReLU (inplace = True )
145139
146140 self .conv2 = nn .Conv2d (32 , 64 , kernel_size = 3 , stride = 1 , padding = 1 , bias = False )
147141 self .bn2 = norm_layer (num_features = 64 )
148142 self .act2 = nn .ReLU (inplace = True )
149143
150- self .block1 = Block (
151- 64 , 128 , stride = 2 , start_with_relu = False , norm_layer = norm_layer , norm_kwargs = norm_kwargs )
144+ self .block1 = Block (64 , 128 , stride = 2 , start_with_relu = False , norm_layer = norm_layer )
152145 self .block1_act = nn .ReLU (inplace = True )
153- self .block2 = Block (
154- 128 , 256 , stride = 2 , start_with_relu = False , norm_layer = norm_layer , norm_kwargs = norm_kwargs )
155- self .block3 = Block (
156- 256 , 728 , stride = entry_block3_stride , norm_layer = norm_layer , norm_kwargs = norm_kwargs )
146+ self .block2 = Block (128 , 256 , stride = 2 , start_with_relu = False , norm_layer = norm_layer )
147+ self .block3 = Block (256 , 728 , stride = entry_block3_stride , norm_layer = norm_layer )
157148
158149 # Middle flow
159150 self .mid = nn .Sequential (OrderedDict ([('block%d' % i , Block (
160- 728 , 728 , stride = 1 , dilation = middle_block_dilation ,
161- norm_layer = norm_layer , norm_kwargs = norm_kwargs )) for i in range (4 , 20 )]))
151+ 728 , 728 , stride = 1 , dilation = middle_dilation , norm_layer = norm_layer )) for i in range (4 , 20 )]))
162152
163153 # Exit flow
164154 self .block20 = Block (
165- 728 , (728 , 1024 , 1024 ), stride = exit_block20_stride , dilation = exit_block_dilations [0 ],
166- norm_layer = norm_layer , norm_kwargs = norm_kwargs )
155+ 728 , (728 , 1024 , 1024 ), stride = exit_block20_stride , dilation = exit_dilation [0 ], norm_layer = norm_layer )
167156 self .block20_act = nn .ReLU (inplace = True )
168157
169- self .conv3 = SeparableConv2d (
170- 1024 , 1536 , 3 , stride = 1 , dilation = exit_block_dilations [1 ],
171- norm_layer = norm_layer , norm_kwargs = norm_kwargs )
172- self .bn3 = norm_layer (num_features = 1536 , ** norm_kwargs )
158+ self .conv3 = SeparableConv2d (1024 , 1536 , 3 , stride = 1 , dilation = exit_dilation [1 ], norm_layer = norm_layer )
159+ self .bn3 = norm_layer (num_features = 1536 )
173160 self .act3 = nn .ReLU (inplace = True )
174161
175- self .conv4 = SeparableConv2d (
176- 1536 , 1536 , 3 , stride = 1 , dilation = exit_block_dilations [1 ],
177- norm_layer = norm_layer , norm_kwargs = norm_kwargs )
178- self .bn4 = norm_layer (num_features = 1536 , ** norm_kwargs )
162+ self .conv4 = SeparableConv2d (1536 , 1536 , 3 , stride = 1 , dilation = exit_dilation [1 ], norm_layer = norm_layer )
163+ self .bn4 = norm_layer (num_features = 1536 )
179164 self .act4 = nn .ReLU (inplace = True )
180165
181166 self .num_features = 2048
182167 self .conv5 = SeparableConv2d (
183- 1536 , self .num_features , 3 , stride = 1 , dilation = exit_block_dilations [1 ],
184- norm_layer = norm_layer , norm_kwargs = norm_kwargs )
185- self .bn5 = norm_layer (num_features = self .num_features , ** norm_kwargs )
168+ 1536 , self .num_features , 3 , stride = 1 , dilation = exit_dilation [1 ], norm_layer = norm_layer )
169+ self .bn5 = norm_layer (num_features = self .num_features )
186170 self .act5 = nn .ReLU (inplace = True )
187171 self .feature_info = [
188172 dict (num_chs = 64 , reduction = 2 , module = 'act2' ),
0 commit comments