@@ -114,23 +114,28 @@ Create a basic inverted residual block for MobileNet variants
114
114
- `reduction`: The reduction factor for the number of hidden feature maps
115
115
in a squeeze and excite layer (see [`squeeze_excite`](#)).
116
116
"""
117
- function invertedresidual (kernel_size, inplanes, hidden_planes, outplanes,
118
- activation = relu; stride, reduction = nothing )
117
+ function invertedresidual (kernel_size, inplanes:: Integer , hidden_planes:: Integer ,
118
+ outplanes:: Integer , activation = relu; stride:: Integer ,
119
+ reduction:: Union{Nothing, Integer} = nothing )
119
120
@assert stride in [1 , 2 ] " `stride` has to be 1 or 2"
120
121
pad = @. (kernel_size - 1 ) ÷ 2
121
- conv1 = (inplanes == hidden_planes) ? identity :
122
- Chain ( conv_norm ((1 , 1 ), inplanes, hidden_planes, activation; bias = false ) )
122
+ conv1 = (inplanes == hidden_planes) ? ( identity,) :
123
+ conv_norm ((1 , 1 ), inplanes, hidden_planes, activation; bias = false )
123
124
selayer = isnothing (reduction) ? identity :
124
125
squeeze_excite (hidden_planes; reduction, activation, gate_activation = hardσ,
125
126
norm_layer = BatchNorm)
126
- invres = Chain (conv1,
127
+ invres = Chain (conv1... ,
127
128
conv_norm (kernel_size, hidden_planes, hidden_planes, activation;
128
129
bias = false , stride, pad = pad, groups = hidden_planes)... ,
129
130
selayer,
130
131
conv_norm ((1 , 1 ), hidden_planes, outplanes, identity; bias = false )... )
131
132
return (stride == 1 && inplanes == outplanes) ? SkipConnection (invres, + ) : invres
132
133
end
133
134
134
- function invertedresidual (kernel_size:: Integer , args... ; kwargs... )
135
- return invertedresidual ((kernel_size, kernel_size), args... ; kwargs... )
135
+ function invertedresidual (kernel_size, inplanes:: Integer , outplanes:: Integer ,
136
+ activation = relu; stride:: Integer , expansion,
137
+ reduction:: Union{Nothing, Integer} = nothing )
138
+ hidden_planes = Int (inplanes * expansion)
139
+ return invertedresidual (kernel_size, inplanes, hidden_planes, outplanes, activation;
140
+ stride, reduction)
136
141
end
0 commit comments