@@ -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
"""
277
280
@nograd conv_transpose_dims
278
281
279
282
function (c:: ConvTranspose )(x:: AbstractArray )
280
- b = reshape (c. bias, map (_-> 1 , c. stride)... , :, 1 )
281
283
σ = NNlib. fast_act (c. σ, x)
282
284
cdims = conv_transpose_dims (c, x)
283
- σ .(∇conv_data (x, c. weight, cdims) .+ b )
285
+ σ .(∇conv_data (x, c. weight, cdims) .+ conv_reshape_bias (c) )
284
286
end
285
287
286
288
function Base. show (io:: IO , l:: ConvTranspose )
@@ -372,10 +374,9 @@ depthwiseconvfilter(filter::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer};
372
374
init = glorot_uniform) where N = init (filter... , div (ch[2 ], ch[1 ]), ch[1 ])
373
375
374
376
function (c:: DepthwiseConv )(x)
375
- b = reshape (c. bias, map (_-> 1 , c. stride)... , :, 1 )
376
377
σ = NNlib. fast_act (c. σ, x)
377
378
cdims = DepthwiseConvDims (x, c. weight; stride= c. stride, padding= c. pad, dilation= c. dilation)
378
- σ .(depthwiseconv (x, c. weight, cdims) .+ b )
379
+ σ .(depthwiseconv (x, c. weight, cdims) .+ conv_reshape_bias (c) )
379
380
end
380
381
381
382
function Base. show (io:: IO , l:: DepthwiseConv )
@@ -453,10 +454,9 @@ function crosscor(x, w, ddims::DenseConvDims)
453
454
end
454
455
455
456
function (c:: CrossCor )(x:: AbstractArray )
456
- b = reshape (c. bias, map (_-> 1 , c. stride)... , :, 1 )
457
457
σ = NNlib. fast_act (c. σ, x)
458
458
cdims = DenseConvDims (x, c. weight; stride= c. stride, padding= c. pad, dilation= c. dilation)
459
- σ .(crosscor (x, c. weight, cdims) .+ b )
459
+ σ .(crosscor (x, c. weight, cdims) .+ conv_reshape_bias (c) )
460
460
end
461
461
462
462
function Base. show (io:: IO , l:: CrossCor )
0 commit comments