From 1d93fb8e5992a4e9e433f95f8c8caef31eaee93c Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Sat, 9 Jun 2018 11:02:15 +0530 Subject: [PATCH] Add new constructor and fix a typo in display --- src/layers/conv.jl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/layers/conv.jl b/src/layers/conv.jl index 237b5b7c..6889716b 100644 --- a/src/layers/conv.jl +++ b/src/layers/conv.jl @@ -47,11 +47,13 @@ function Base.show(io::IO, l::Conv) end """ + DepthwiseConv(size, in) DepthwiseConv(size, in=>mul) DepthwiseConv(size, in=>mul, relu) Depthwise convolutional layer. `size` should be a tuple like `(2, 2)`. `in` and `mul` specify the number of input channels and channel multiplier respectively. +In case the `mul` is not specified it is taken as 1. Data should be stored in WHCN order. In other words, a 100×100 RGB image would be a `100×100×3` array, and a batch of 50 would be a `100×100×3×50` array. @@ -70,6 +72,12 @@ DepthwiseConv(w::AbstractArray{T}, b::AbstractVector{T}, σ = identity; stride = 1, pad = 0) where T = DepthwiseConv(σ, w, b, stride, pad) +DepthwiseConv(k::NTuple{N,Integer}, ch::Integer, σ = identity; init = initn, + stride::NTuple{N,Integer} = map(_->1,k), + pad::NTuple{N,Integer} = map(_->0,k)) where N = + DepthwiseConv(param(init(k..., 1, ch)), param(zeros(ch)), σ, + stride = stride, pad = pad) + DepthwiseConv(k::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer}, σ = identity; init = initn, stride::NTuple{N,Integer} = map(_->1,k), pad::NTuple{N,Integer} = map(_->0,k)) where N = @@ -83,7 +91,7 @@ function (c::DepthwiseConv)(x) σ.(depthwiseconv(x, c.weight, stride = c.stride, pad = c.pad) .+ b) end -function Base.show(io::IO, l::Conv) +function Base.show(io::IO, l::DepthwiseConv) print(io, "DepthwiseConv(", size(l.weight)[1:ndims(l.weight)-2]) print(io, ", ", size(l.weight, ndims(l.weight)), "=>", size(l.weight, ndims(l.weight)-1)) l.σ == identity || print(io, ", ", l.σ)