@@ -68,7 +68,7 @@ See also [`ConvTranspose`](@ref), [`DepthwiseConv`](@ref), [`CrossCor`](@ref).
68
68
julia> xs = rand(Float32, 100, 100, 3, 50); # a batch of images
69
69
70
70
julia> lay = Conv((5,5), 3 => 7, relu; bias=false)
71
- Conv((5, 5), 3=> 7, relu)
71
+ Conv((5, 5), 3 => 7, relu, bias=false) # 525 parameters
72
72
73
73
julia> lay(xs) |> size
74
74
(96, 96, 7, 50)
99
99
Conv(weight::AbstractArray, [bias, activation; stride, pad, dilation])
100
100
101
101
Constructs a convolutional layer with the given weight and bias.
102
- Accepts the same keywords (and has the same defaults) as the `Conv((4,4), 3=> 7, relu)`
102
+ Accepts the same keywords (and has the same defaults) as the `Conv((4,4), 3 => 7, relu)`
103
103
method.
104
104
105
105
# Examples
@@ -109,7 +109,7 @@ julia> weight = rand(3, 4, 5);
109
109
julia> bias = zeros(5);
110
110
111
111
julia> c1 = Conv(weight, bias, sigmoid) # expects 1 spatial dimension
112
- Conv((3,), 4=> 5, σ)
112
+ Conv((3,), 4 => 5, σ) # 65 parameters
113
113
114
114
julia> c1(randn(100, 4, 64)) |> size
115
115
(98, 5, 64)
@@ -135,7 +135,7 @@ function Conv(k::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer}, σ = identity
135
135
end
136
136
137
137
"""
138
- convfilter(filter::Tuple, in=> out)
138
+ convfilter(filter::Tuple, in => out)
139
139
140
140
Constructs a standard convolutional weight matrix with given `filter` and
141
141
channels from `in` to `out`.
@@ -160,11 +160,18 @@ end
160
160
161
161
function Base. show (io:: IO , l:: Conv )
162
162
print (io, " Conv(" , size (l. weight)[1 : ndims (l. weight)- 2 ])
163
- print (io, " , " , size (l. weight, ndims (l. weight)- 1 ), " => " , size (l. weight, ndims (l. weight)))
164
- l . σ == identity || print (io, " , " , l . σ )
163
+ print (io, " , " , size (l. weight, ndims (l. weight)- 1 ), " => " , size (l. weight, ndims (l. weight)))
164
+ _print_conv_opt (io, l )
165
165
print (io, " )" )
166
166
end
167
167
168
+ function _print_conv_opt (io:: IO , l)
169
+ l. σ == identity || print (io, " , " , l. σ)
170
+ all (== (0 ), l. pad) || print (io, " , pad=" , _maybetuple_string (l. pad))
171
+ all (== (1 ), l. stride) || print (io, " , stride=" , _maybetuple_string (l. stride))
172
+ all (== (1 ), l. dilation) || print (io, " , dilation=" , _maybetuple_string (l. dilation))
173
+ l. bias == Zeros () && print (io, " , bias=false" )
174
+ end
168
175
169
176
"""
170
177
ConvTranspose(filter, in => out, σ=identity; stride=1, pad=0, dilation=1, [bias, init])
@@ -185,15 +192,15 @@ See also [`Conv`](@ref) for more detailed description of keywords.
185
192
julia> xs = rand(Float32, 100, 100, 3, 50); # a batch of 50 RGB images
186
193
187
194
julia> lay = ConvTranspose((5,5), 3 => 7, relu)
188
- ConvTranspose((5, 5), 3=> 7, relu)
195
+ ConvTranspose((5, 5), 3 => 7, relu) # 532 parameters
189
196
190
197
julia> lay(xs) |> size
191
198
(104, 104, 7, 50)
192
199
193
- julia> ConvTranspose((5,5), 3=> 7, stride=2)(xs) |> size
200
+ julia> ConvTranspose((5,5), 3 => 7, stride=2)(xs) |> size
194
201
(203, 203, 7, 50)
195
202
196
- julia> ConvTranspose((5,5), 3=> 7, stride=3, pad=SamePad())(xs) |> size
203
+ julia> ConvTranspose((5,5), 3 => 7, stride=3, pad=SamePad())(xs) |> size
197
204
(300, 300, 7, 50)
198
205
```
199
206
"""
210
217
ConvTranspose(weight::AbstractArray, [bias, activation; stride, pad, dilation])
211
218
212
219
Constructs a layer with the given weight and bias arrays.
213
- Accepts the same keywords as the `ConvTranspose((4,4), 3=> 7, relu)` method.
220
+ Accepts the same keywords as the `ConvTranspose((4,4), 3 => 7, relu)` method.
214
221
"""
215
222
function ConvTranspose (w:: AbstractArray{T,N} , bias = true , σ = identity;
216
223
stride = 1 , pad = 0 , dilation = 1 ) where {T,N}
256
263
257
264
function Base. show (io:: IO , l:: ConvTranspose )
258
265
print (io, " ConvTranspose(" , size (l. weight)[1 : ndims (l. weight)- 2 ])
259
- print (io, " , " , size (l. weight, ndims (l. weight)), " => " , size (l. weight, ndims (l. weight)- 1 ))
260
- l . σ == identity || print (io, " , " , l . σ )
266
+ print (io, " , " , size (l. weight, ndims (l. weight)), " => " , size (l. weight, ndims (l. weight)- 1 ))
267
+ _print_conv_opt (io, l )
261
268
print (io, " )" )
262
269
end
263
270
@@ -267,7 +274,7 @@ function calc_padding(::Type{ConvTranspose}, pad::SamePad, k::NTuple{N,T}, dilat
267
274
end
268
275
269
276
"""
270
- DepthwiseConv(filter, in=> out, σ=identity; stride=1, pad=0, dilation=1, [bias, init])
277
+ DepthwiseConv(filter, in => out, σ=identity; stride=1, pad=0, dilation=1, [bias, init])
271
278
272
279
Depthwise convolutional layer. `filter` is a tuple of integers
273
280
specifying the size of the convolutional kernel, while
@@ -285,7 +292,7 @@ See also [`Conv`](@ref) for more detailed description of keywords.
285
292
julia> xs = rand(Float32, 100, 100, 3, 50); # a batch of 50 RGB images
286
293
287
294
julia> lay = DepthwiseConv((5,5), 3 => 6, relu; bias=false)
288
- DepthwiseConv((5, 5), 3=> 6, relu)
295
+ DepthwiseConv((5, 5), 3 => 6, relu, bias=false) # 150 parameters
289
296
290
297
julia> lay(xs) |> size
291
298
(96, 96, 6, 50)
307
314
DepthwiseConv(weight::AbstractArray, bias, [activation; stride, pad, dilation])
308
315
309
316
Constructs a layer with the given weight and bias arrays.
310
- Accepts the same keywords as the `DepthwiseConv((4,4), 3=> 6, relu)` method.
317
+ Accepts the same keywords as the `DepthwiseConv((4,4), 3 => 6, relu)` method.
311
318
"""
312
319
function DepthwiseConv (w:: AbstractArray{T,N} , bias = true , σ = identity;
313
320
stride = 1 , pad = 0 , dilation = 1 ) where {T,N}
328
335
@functor DepthwiseConv
329
336
330
337
"""
331
- depthwiseconvfilter(filter::Tuple, in=> out)
338
+ depthwiseconvfilter(filter::Tuple, in => out)
332
339
333
340
Constructs a depthwise convolutional weight array defined by `filter` and channels
334
341
from `in` to `out`.
349
356
350
357
function Base. show (io:: IO , l:: DepthwiseConv )
351
358
print (io, " DepthwiseConv(" , size (l. weight)[1 : end - 2 ])
352
- print (io, " , " , size (l. weight)[end ], " => " , prod (size (l. weight)[end - 1 : end ]))
353
- l . σ == identity || print (io, " , " , l . σ )
359
+ print (io, " , " , size (l. weight)[end ], " => " , prod (size (l. weight)[end - 1 : end ]))
360
+ _print_conv_opt (io, l )
354
361
print (io, " )" )
355
362
end
356
363
@@ -373,12 +380,12 @@ See also [`Conv`](@ref) for more detailed description of keywords.
373
380
julia> xs = rand(Float32, 100, 100, 3, 50); # a batch of 50 RGB images
374
381
375
382
julia> lay = CrossCor((5,5), 3 => 6, relu; bias=false)
376
- CrossCor((5, 5), 3=> 6, relu)
383
+ CrossCor((5, 5), 3 => 6, relu, bias=false) # 450 parameters
377
384
378
385
julia> lay(xs) |> size
379
386
(96, 96, 6, 50)
380
387
381
- julia> CrossCor((5,5), 3=> 7, stride=3, pad=(2,0))(xs) |> size
388
+ julia> CrossCor((5,5), 3 => 7, stride=3, pad=(2,0))(xs) |> size
382
389
(34, 32, 7, 50)
383
390
```
384
391
"""
395
402
CrossCor(weight::AbstractArray, [bias, activation; stride, pad, dilation])
396
403
397
404
Constructs a layer with the given weight and bias arrays.
398
- Accepts the same keywords as the `CrossCor((4,4), 3=> 7, relu)` method.
405
+ Accepts the same keywords as the `CrossCor((4,4), 3 => 7, relu)` method.
399
406
"""
400
407
function CrossCor (w:: AbstractArray{T,N} , bias = true , σ = identity;
401
408
stride = 1 , pad = 0 , dilation = 1 ) where {T,N}
430
437
431
438
function Base. show (io:: IO , l:: CrossCor )
432
439
print (io, " CrossCor(" , size (l. weight)[1 : ndims (l. weight)- 2 ])
433
- print (io, " , " , size (l. weight, ndims (l. weight)- 1 ), " => " , size (l. weight, ndims (l. weight)))
434
- l . σ == identity || print (io, " , " , l . σ )
440
+ print (io, " , " , size (l. weight, ndims (l. weight)- 1 ), " => " , size (l. weight, ndims (l. weight)))
441
+ _print_conv_opt (io, l )
435
442
print (io, " )" )
436
443
end
437
444
@@ -530,8 +537,7 @@ See also [`MaxPool`](@ref), [`GlobalMeanPool`](@ref).
530
537
```jldoctest
531
538
julia> xs = rand(Float32, 100, 100, 3, 50);
532
539
533
- julia> m = Chain(Conv((3,3), 3=>7), GlobalMaxPool())
534
- Chain(Conv((3, 3), 3=>7), GlobalMaxPool())
540
+ julia> m = Chain(Conv((3,3), 3 => 7), GlobalMaxPool());
535
541
536
542
julia> m(xs) |> size
537
543
(1, 1, 7, 50)
@@ -568,8 +574,7 @@ by performing mean pooling on the complete (w,h)-shaped feature maps.
568
574
```jldoctest
569
575
julia> xs = rand(Float32, 100, 100, 3, 50);
570
576
571
- julia> m = Chain(Conv((3,3), 3=>7), GlobalMeanPool())
572
- Chain(Conv((3, 3), 3=>7), GlobalMeanPool())
577
+ julia> m = Chain(Conv((3,3), 3 => 7), GlobalMeanPool());
573
578
574
579
julia> m(xs) |> size
575
580
(1, 1, 7, 50)
@@ -612,8 +617,11 @@ See also [`Conv`](@ref), [`MeanPool`](@ref), [`AdaptiveMaxPool`](@ref), [`Global
612
617
```jldoctest
613
618
julia> xs = rand(Float32, 100, 100, 3, 50); # batch of 50 RGB images
614
619
615
- julia> m = Chain(Conv((5, 5), 3=>7, pad=SamePad()), MaxPool((5, 5), pad=SamePad()))
616
- Chain(Conv((5, 5), 3=>7), MaxPool((5, 5), pad=2))
620
+ julia> m = Chain(Conv((5, 5), 3 => 7, pad=SamePad()), MaxPool((5, 5), pad=SamePad()))
621
+ Chain(
622
+ Conv((5, 5), 3 => 7, pad=2), # 532 parameters
623
+ MaxPool((5, 5), pad=2),
624
+ )
617
625
618
626
julia> m[1](xs) |> size
619
627
(100, 100, 7, 50)
@@ -675,7 +683,10 @@ See also [`Conv`](@ref), [`MaxPool`](@ref), [`AdaptiveMeanPool`](@ref).
675
683
julia> xs = rand(Float32, 100, 100, 3, 50);
676
684
677
685
julia> m = Chain(Conv((5,5), 3 => 7), MeanPool((5,5), pad=SamePad()))
678
- Chain(Conv((5, 5), 3=>7), MeanPool((5, 5), pad=2))
686
+ Chain(
687
+ Conv((5, 5), 3 => 7), # 532 parameters
688
+ MeanPool((5, 5), pad=2),
689
+ )
679
690
680
691
julia> m[1](xs) |> size
681
692
(96, 96, 7, 50)
0 commit comments