@@ -6,6 +6,10 @@ _paddims(x::Tuple, y::Tuple) = (x..., y[(end - (length(y) - length(x) - 1)):end]
6
6
expand (N, i:: Tuple ) = i
7
7
expand (N, i:: Integer ) = ntuple (_ -> i, N)
8
8
9
+ conv_reshape_bias (c) = c. bias isa AbstractVector ?
10
+ reshape (c. bias, map (_-> 1 , c. stride)... , :, 1 ) :
11
+ c. bias
12
+
9
13
"""
10
14
SamePad()
11
15
61
65
62
66
Keywords to control initialization of the layer:
63
67
* `init` - Function used to generate initial weights. Defaults to `glorot_uniform`.
64
- * `bias` - Initial bias is zero by default, this can be disabled entirely by setting it to
65
- `false`, or another vector explicitly as `bias = randn(Float32, out)`.
68
+ * `bias` - The initial bias vector is all zero by default. Trainable bias can be disabled entirely
69
+ by setting this to `false`, or another vector can be provided such as `bias = randn(Float32, out)`.
66
70
67
71
See also [`ConvTranspose`](@ref), [`DepthwiseConv`](@ref), [`CrossCor`](@ref).
68
72
159
163
@functor Conv
160
164
161
165
function (c:: Conv )(x:: AbstractArray )
162
- b = reshape (c. bias, map (_-> 1 , c. stride)... , :, 1 )
163
166
σ = NNlib. fast_act (c. σ, x)
164
167
cdims = DenseConvDims (x, c. weight; stride = c. stride, padding = c. pad, dilation = c. dilation, groups = c. groups)
165
- σ .(conv (x, c. weight, cdims) .+ b )
168
+ σ .(conv (x, c. weight, cdims) .+ conv_reshape_bias (c) )
166
169
end
167
170
168
171
_channels_in (l :: Conv ) = size (l. weight, ndims (l. weight)- 1 ) * l. groups
@@ -183,7 +186,7 @@ function _print_conv_opt(io::IO, l)
183
186
if hasproperty (l, :groups )
184
187
(l. groups == 1 ) || print (io, " , groups=" , l. groups)
185
188
end
186
- (l. bias isa Zeros ) && print (io, " , bias=false" )
189
+ (l. bias === false ) && print (io, " , bias=false" )
187
190
end
188
191
189
192
"""
276
279
ChainRulesCore. @non_differentiable conv_transpose_dims (:: Any , :: Any )
277
280
278
281
function (c:: ConvTranspose )(x:: AbstractArray )
279
- b = reshape (c. bias, map (_-> 1 , c. stride)... , :, 1 )
280
282
σ = NNlib. fast_act (c. σ, x)
281
283
cdims = conv_transpose_dims (c, x)
282
- σ .(∇conv_data (x, c. weight, cdims) .+ b )
284
+ σ .(∇conv_data (x, c. weight, cdims) .+ conv_reshape_bias (c) )
283
285
end
284
286
285
287
function Base. show (io:: IO , l:: ConvTranspose )
@@ -371,10 +373,9 @@ depthwiseconvfilter(filter::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer};
371
373
init = glorot_uniform) where N = init (filter... , div (ch[2 ], ch[1 ]), ch[1 ])
372
374
373
375
function (c:: DepthwiseConv )(x)
374
- b = reshape (c. bias, map (_-> 1 , c. stride)... , :, 1 )
375
376
σ = NNlib. fast_act (c. σ, x)
376
377
cdims = DepthwiseConvDims (x, c. weight; stride= c. stride, padding= c. pad, dilation= c. dilation)
377
- σ .(depthwiseconv (x, c. weight, cdims) .+ b )
378
+ σ .(depthwiseconv (x, c. weight, cdims) .+ conv_reshape_bias (c) )
378
379
end
379
380
380
381
function Base. show (io:: IO , l:: DepthwiseConv )
@@ -452,10 +453,9 @@ function crosscor(x, w, ddims::DenseConvDims)
452
453
end
453
454
454
455
function (c:: CrossCor )(x:: AbstractArray )
455
- b = reshape (c. bias, map (_-> 1 , c. stride)... , :, 1 )
456
456
σ = NNlib. fast_act (c. σ, x)
457
457
cdims = DenseConvDims (x, c. weight; stride= c. stride, padding= c. pad, dilation= c. dilation)
458
- σ .(crosscor (x, c. weight, cdims) .+ b )
458
+ σ .(crosscor (x, c. weight, cdims) .+ conv_reshape_bias (c) )
459
459
end
460
460
461
461
function Base. show (io:: IO , l:: CrossCor )
0 commit comments