@@ -46,7 +46,7 @@ In other words, a 100×100 RGB image would be a `100×100×3×1` array,
46
46
and a batch of 50 would be a `100×100×3×50` array.
47
47
48
48
Accepts keyword arguments `weight` and `bias` to set the corresponding fields.
49
- Setting `bias` to `Flux.Zeros() ` will switch bias off for the layer.
49
+ Setting `bias` to `false ` will switch bias off for the layer.
50
50
51
51
Takes the keyword arguments `pad`, `stride` and `dilation`.
52
52
For input dimension N,
82
82
83
83
Constructs the convolutional layer with user defined weight and bias arrays.
84
84
85
- Setting `bias` to `Flux.Zeros() ` would switch `bias` off for the layer.
85
+ Setting `bias` to `false ` would switch `bias` off for the layer.
86
86
87
87
Takes the keyword arguments `pad`, `stride` and `dilation`.
88
88
For input dimension N,
@@ -102,15 +102,16 @@ Conv(weight = weight,
102
102
σ = sigmoid)
103
103
```
104
104
"""
105
- function Conv (w:: AbstractArray{T,N} , b:: Union{Zeros, AbstractVector{T}} , σ = identity;
105
+ function Conv (w:: AbstractArray{T,N} , b:: Union{Bool, Zeros, AbstractVector{T}} , σ = identity;
106
106
stride = 1 , pad = 0 , dilation = 1 ) where {T,N}
107
107
stride = expand (Val (N- 2 ), stride)
108
108
dilation = expand (Val (N- 2 ), dilation)
109
109
pad = calc_padding (Conv, pad, size (w)[1 : N- 2 ], dilation, stride)
110
- return Conv (σ, w, b, stride, pad, dilation)
110
+ bias = create_bias (b, zeros, size (w, N))
111
+ return Conv (σ, w, bias, stride, pad, dilation)
111
112
end
112
113
113
- function Conv (;weight:: AbstractArray{T,N} , bias:: Union{Zeros, AbstractVector{T}} ,
114
+ function Conv (;weight:: AbstractArray{T,N} , bias:: Union{Bool, Zeros, AbstractVector{T}} ,
114
115
activation = identity, stride = 1 , pad = 0 , dilation = 1 ) where {T,N}
115
116
Conv (weight, bias, activation, stride = stride, pad = pad, dilation = dilation)
116
117
end
@@ -131,7 +132,7 @@ convfilter(filter::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer};
131
132
132
133
function Conv (k:: NTuple{N,Integer} , ch:: Pair{<:Integer,<:Integer} , σ = identity;
133
134
init = glorot_uniform, stride = 1 , pad = 0 , dilation = 1 ,
134
- weight = convfilter (k, ch, init = init), bias = zeros (ch[ 2 ]) ) where N
135
+ weight = convfilter (k, ch, init = init), bias = true ) where N
135
136
136
137
Conv (weight, bias, σ,
137
138
stride = stride, pad = pad, dilation = dilation)
@@ -189,7 +190,7 @@ In other words, a 100×100 RGB image would be a `100×100×3×1` array,
189
190
and a batch of 50 would be a `100×100×3×50` array.
190
191
191
192
Accepts keyword arguments `weight` and `bias` to set the corresponding fields.
192
- Setting `bias` to `Flux.Zeros() ` will switch bias off for the layer.
193
+ Setting `bias` to `false ` will switch bias off for the layer.
193
194
194
195
Takes the keyword arguments `pad`, `stride` and `dilation`.
195
196
For input dimension N,
215
216
Constructs the convolutional transpose layer with user defined weight and bias arrays.
216
217
forward pass.
217
218
218
- Setting `bias` to `Flux.Zeros()` would switch ` bias` off for the layer.
219
+ Setting `bias` to `false` will switch bias off for the layer.
219
220
220
221
Takes the keyword arguments `pad`, `stride` and `dilation`.
221
222
For input dimension N,
@@ -226,22 +227,23 @@ indicating padding values for each spatial dimension at both the ends.
226
227
227
228
For keyword-only constuctor, see also [`Conv`](@ref)
228
229
"""
229
- function ConvTranspose (w:: AbstractArray{T,N} , b:: Union{Zeros, AbstractVector{T}} , σ = identity;
230
+ function ConvTranspose (w:: AbstractArray{T,N} , b:: Union{Bool, Zeros, AbstractVector{T}} , σ = identity;
230
231
stride = 1 , pad = 0 , dilation = 1 ) where {T,N}
231
232
stride = expand (Val (N- 2 ), stride)
232
233
dilation = expand (Val (N- 2 ), dilation)
233
234
pad = calc_padding (ConvTranspose, pad, size (w)[1 : N- 2 ], dilation, stride)
234
- return ConvTranspose (σ, w, b, stride, pad, dilation)
235
+ bias = create_bias (b, zeros, size (w, N))
236
+ return ConvTranspose (σ, w, bias, stride, pad, dilation)
235
237
end
236
238
237
- function ConvTranspose (;weight:: AbstractArray{T,N} , bias:: Union{Zeros, AbstractVector{T}} ,
239
+ function ConvTranspose (;weight:: AbstractArray{T,N} , bias:: Union{Bool, Zeros, AbstractVector{T}} ,
238
240
activation = identity, stride = 1 , pad = 0 , dilation = 1 ) where {T,N}
239
241
ConvTranspose (weight, bias, activation, stride = stride, pad = pad, dilation = dilation)
240
242
end
241
243
242
244
function ConvTranspose (k:: NTuple{N,Integer} , ch:: Pair{<:Integer,<:Integer} , σ = identity;
243
245
init = glorot_uniform, stride = 1 , pad = 0 , dilation = 1 ,
244
- weight = convfilter (k, reverse (ch), init = init), bias = zeros (ch[ 2 ]) ) where N
246
+ weight = convfilter (k, reverse (ch), init = init), bias = true ) where N
245
247
246
248
ConvTranspose (weight, bias, σ,
247
249
stride = stride, pad = pad, dilation = dilation)
@@ -307,7 +309,7 @@ In other words, a 100×100 RGB image would be a `100×100×3×1` array,
307
309
and a batch of 50 would be a `100×100×3×50` array.
308
310
309
311
Accepts keyword arguments `weight` and `bias` to set the corresponding fields.
310
- Setting `bias` to `Flux.Zeros() ` will switch bias off for the layer.
312
+ Setting `bias` to `false ` will switch bias off for the layer.
311
313
312
314
Takes the keyword arguments `pad`, `stride` and `dilation`.
313
315
For input dimension N,
333
335
Constructs the `DepthwiseConv` layer with user defined weight and bias arrays.
334
336
forward pass.
335
337
336
- Setting `bias` to `Flux.Zeros() ` would switch `bias` off for the layer.
338
+ Setting `bias` to `false ` would switch `bias` off for the layer.
337
339
338
340
Takes the keyword arguments `pad`, `stride` and `dilation`.
339
341
For input dimension N,
@@ -344,15 +346,16 @@ indicating padding values for each spatial dimension at both the ends.
344
346
345
347
For keyword-only constuctor, see also [`Conv`](@ref)
346
348
"""
347
- function DepthwiseConv (w:: AbstractArray{T,N} , b:: Union{Zeros, AbstractVector{T}} , σ = identity;
349
+ function DepthwiseConv (w:: AbstractArray{T,N} , b:: Union{Bool, Zeros, AbstractVector{T}} , σ = identity;
348
350
stride = 1 , pad = 0 , dilation = 1 ) where {T,N}
349
351
stride = expand (Val (N- 2 ), stride)
350
352
dilation = expand (Val (N- 2 ), dilation)
351
353
pad = calc_padding (DepthwiseConv, pad, size (w)[1 : N- 2 ], dilation, stride)
352
- return DepthwiseConv (σ, w, b, stride, pad, dilation)
354
+ bias = create_bias (b, zeros, prod (size (w)[N- 1 : end ]))
355
+ return DepthwiseConv (σ, w, bias, stride, pad, dilation)
353
356
end
354
357
355
- function DepthwiseConv (;weight:: AbstractArray{T,N} , bias:: Union{Zeros, AbstractVector{T}} ,
358
+ function DepthwiseConv (;weight:: AbstractArray{T,N} , bias:: Union{Bool, Zeros, AbstractVector{T}} ,
356
359
activation = identity, stride = 1 , pad = 0 , dilation = 1 ) where {T,N}
357
360
DepthwiseConv (weight, bias, activation, stride = stride, pad = pad, dilation = dilation)
358
361
end
@@ -373,7 +376,7 @@ depthwiseconvfilter(filter::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer};
373
376
374
377
function DepthwiseConv (k:: NTuple{N,Integer} , ch:: Pair{<:Integer,<:Integer} , σ = identity;
375
378
init = glorot_uniform, stride = 1 , pad = 0 , dilation = 1 ,
376
- weight = depthwiseconvfilter (k, ch, init = init), bias = zeros (ch[ 2 ]) ) where N
379
+ weight = depthwiseconvfilter (k, ch, init = init), bias = true ) where N
377
380
@assert ch[2 ] % ch[1 ] == 0 " Output channels must be integer multiple of input channels"
378
381
379
382
return DepthwiseConv (
@@ -424,7 +427,7 @@ In other words, a 100×100 RGB image would be a `100×100×3×1` array,
424
427
and a batch of 50 would be a `100×100×3×50` array.
425
428
426
429
Accepts keyword arguments `weight` and `bias` to set the corresponding fields.
427
- Setting `bias` to `Flux.Zeros() ` will switch bias off for the layer.
430
+ Setting `bias` to `false ` will switch bias off for the layer.
428
431
429
432
Takes the keyword arguments `pad`, `stride` and `dilation`.
430
433
For input dimension N,
461
464
Constructs the standard cross convolutional layer with user defined weight and bias
462
465
arrays.
463
466
464
- Setting `bias` to `Flux.Zeros() ` would switch `bias` off for the layer.
467
+ Setting `bias` to `false ` would switch `bias` off for the layer.
465
468
466
469
Takes the keyword arguments `pad`, `stride` and `dilation`.
467
470
For input dimension N,
@@ -472,22 +475,23 @@ indicating padding values for each spatial dimension at both the ends.
472
475
473
476
For keyword-only constuctor, see also [`Conv`](@ref)
474
477
"""
475
- function CrossCor (w:: AbstractArray{T,N} , b:: Union{Zeros, AbstractVector{T}} , σ = identity;
478
+ function CrossCor (w:: AbstractArray{T,N} , b:: Union{Bool, Zeros, AbstractVector{T}} , σ = identity;
476
479
stride = 1 , pad = 0 , dilation = 1 ) where {T,N}
477
480
stride = expand (Val (N- 2 ), stride)
478
481
dilation = expand (Val (N- 2 ), dilation)
479
482
pad = calc_padding (CrossCor, pad, size (w)[1 : N- 2 ], dilation, stride)
480
- return CrossCor (σ, w, b, stride, pad, dilation)
483
+ bias = create_bias (b, zeros, size (w, N))
484
+ return CrossCor (σ, w, bias, stride, pad, dilation)
481
485
end
482
486
483
- function CrossCor (;weight:: AbstractArray{T,N} , bias:: Union{Zeros, AbstractVector{T}} ,
487
+ function CrossCor (;weight:: AbstractArray{T,N} , bias:: Union{Bool, Zeros, AbstractVector{T}} ,
484
488
activation = identity, stride = 1 , pad = 0 , dilation = 1 ) where {T,N}
485
489
CrossCor (weight, bias, activation, stride = stride, pad = pad, dilation = dilation)
486
490
end
487
491
488
492
function CrossCor (k:: NTuple{N,Integer} , ch:: Pair{<:Integer,<:Integer} , σ = identity;
489
493
init = glorot_uniform, stride = 1 , pad = 0 , dilation = 1 ,
490
- weight = convfilter (k, ch, init = init), bias = zeros (ch[ 2 ]) ) where N
494
+ weight = convfilter (k, ch, init = init), bias = true ) where N
491
495
492
496
CrossCor (weight, bias, σ,
493
497
stride = stride, pad = pad, dilation = dilation)
0 commit comments