@@ -68,7 +68,7 @@ See also [`ConvTranspose`](@ref), [`DepthwiseConv`](@ref), [`CrossCor`](@ref).
6868julia> xs = rand(Float32, 100, 100, 3, 50); # a batch of images
6969
7070julia> 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
7272
7373julia> lay(xs) |> size
7474(96, 96, 7, 50)
9999 Conv(weight::AbstractArray, [bias, activation; stride, pad, dilation])
100100
101101Constructs 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)`
103103method.
104104
105105# Examples
@@ -109,7 +109,7 @@ julia> weight = rand(3, 4, 5);
109109julia> bias = zeros(5);
110110
111111julia> c1 = Conv(weight, bias, sigmoid) # expects 1 spatial dimension
112- Conv((3,), 4=> 5, σ)
112+ Conv((3,), 4 => 5, σ) # 65 parameters
113113
114114julia> c1(randn(100, 4, 64)) |> size
115115(98, 5, 64)
@@ -135,7 +135,7 @@ function Conv(k::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer}, σ = identity
135135end
136136
137137"""
138- convfilter(filter::Tuple, in=> out)
138+ convfilter(filter::Tuple, in => out)
139139
140140Constructs a standard convolutional weight matrix with given `filter` and
141141channels from `in` to `out`.
@@ -160,11 +160,18 @@ end
160160
161161function Base. show (io:: IO , l:: Conv )
162162 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 )
165165 print (io, " )" )
166166end
167167
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
168175
169176"""
170177 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.
185192julia> xs = rand(Float32, 100, 100, 3, 50); # a batch of 50 RGB images
186193
187194julia> lay = ConvTranspose((5,5), 3 => 7, relu)
188- ConvTranspose((5, 5), 3=> 7, relu)
195+ ConvTranspose((5, 5), 3 => 7, relu) # 532 parameters
189196
190197julia> lay(xs) |> size
191198(104, 104, 7, 50)
192199
193- julia> ConvTranspose((5,5), 3=> 7, stride=2)(xs) |> size
200+ julia> ConvTranspose((5,5), 3 => 7, stride=2)(xs) |> size
194201(203, 203, 7, 50)
195202
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
197204(300, 300, 7, 50)
198205```
199206"""
210217 ConvTranspose(weight::AbstractArray, [bias, activation; stride, pad, dilation])
211218
212219Constructs 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.
214221"""
215222function ConvTranspose (w:: AbstractArray{T,N} , bias = true , σ = identity;
216223 stride = 1 , pad = 0 , dilation = 1 ) where {T,N}
256263
257264function Base. show (io:: IO , l:: ConvTranspose )
258265 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 )
261268 print (io, " )" )
262269end
263270
@@ -267,7 +274,7 @@ function calc_padding(::Type{ConvTranspose}, pad::SamePad, k::NTuple{N,T}, dilat
267274end
268275
269276"""
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])
271278
272279Depthwise convolutional layer. `filter` is a tuple of integers
273280specifying the size of the convolutional kernel, while
@@ -285,7 +292,7 @@ See also [`Conv`](@ref) for more detailed description of keywords.
285292julia> xs = rand(Float32, 100, 100, 3, 50); # a batch of 50 RGB images
286293
287294julia> 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
289296
290297julia> lay(xs) |> size
291298(96, 96, 6, 50)
307314 DepthwiseConv(weight::AbstractArray, bias, [activation; stride, pad, dilation])
308315
309316Constructs 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.
311318"""
312319function DepthwiseConv (w:: AbstractArray{T,N} , bias = true , σ = identity;
313320 stride = 1 , pad = 0 , dilation = 1 ) where {T,N}
328335@functor DepthwiseConv
329336
330337"""
331- depthwiseconvfilter(filter::Tuple, in=> out)
338+ depthwiseconvfilter(filter::Tuple, in => out)
332339
333340Constructs a depthwise convolutional weight array defined by `filter` and channels
334341from `in` to `out`.
349356
350357function Base. show (io:: IO , l:: DepthwiseConv )
351358 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 )
354361 print (io, " )" )
355362end
356363
@@ -373,12 +380,12 @@ See also [`Conv`](@ref) for more detailed description of keywords.
373380julia> xs = rand(Float32, 100, 100, 3, 50); # a batch of 50 RGB images
374381
375382julia> 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
377384
378385julia> lay(xs) |> size
379386(96, 96, 6, 50)
380387
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
382389(34, 32, 7, 50)
383390```
384391"""
395402 CrossCor(weight::AbstractArray, [bias, activation; stride, pad, dilation])
396403
397404Constructs 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.
399406"""
400407function CrossCor (w:: AbstractArray{T,N} , bias = true , σ = identity;
401408 stride = 1 , pad = 0 , dilation = 1 ) where {T,N}
430437
431438function Base. show (io:: IO , l:: CrossCor )
432439 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 )
435442 print (io, " )" )
436443end
437444
@@ -530,8 +537,7 @@ See also [`MaxPool`](@ref), [`GlobalMeanPool`](@ref).
530537```jldoctest
531538julia> xs = rand(Float32, 100, 100, 3, 50);
532539
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());
535541
536542julia> m(xs) |> size
537543(1, 1, 7, 50)
@@ -568,8 +574,7 @@ by performing mean pooling on the complete (w,h)-shaped feature maps.
568574```jldoctest
569575julia> xs = rand(Float32, 100, 100, 3, 50);
570576
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());
573578
574579julia> m(xs) |> size
575580(1, 1, 7, 50)
@@ -612,8 +617,11 @@ See also [`Conv`](@ref), [`MeanPool`](@ref), [`AdaptiveMaxPool`](@ref), [`Global
612617```jldoctest
613618julia> xs = rand(Float32, 100, 100, 3, 50); # batch of 50 RGB images
614619
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+ )
617625
618626julia> m[1](xs) |> size
619627(100, 100, 7, 50)
@@ -675,7 +683,10 @@ See also [`Conv`](@ref), [`MaxPool`](@ref), [`AdaptiveMeanPool`](@ref).
675683julia> xs = rand(Float32, 100, 100, 3, 50);
676684
677685julia> 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+ )
679690
680691julia> m[1](xs) |> size
681692(96, 96, 7, 50)
0 commit comments