cleaner API
This commit is contained in:
parent
eb41715d26
commit
245563077b
@ -22,8 +22,7 @@ In other words, a 100×100 RGB image would be a `100×100×3×1` array,
|
|||||||
and a batch of 50 would be a `100×100×3×50` array.
|
and a batch of 50 would be a `100×100×3×50` array.
|
||||||
|
|
||||||
Accepts keyword arguments `weight` and `bias` to set the corresponding fields.
|
Accepts keyword arguments `weight` and `bias` to set the corresponding fields.
|
||||||
Setting `bias` to `Flux.Zeros()` will switch bias off for the
|
Setting `bias` to `Flux.Zeros()` will switch bias off for the layer.
|
||||||
layer.
|
|
||||||
|
|
||||||
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
||||||
"""
|
"""
|
||||||
@ -44,17 +43,15 @@ Constructs the convolutional layer with user defined weight and bias arrays.
|
|||||||
All other behaviours of the Conv layer apply with regard to data order and
|
All other behaviours of the Conv layer apply with regard to data order and
|
||||||
forward pass.
|
forward pass.
|
||||||
|
|
||||||
Setting `bias` to `nothing` or `Flux.Zeros()` would switch `bias` off for the
|
Setting `bias` to `Flux.Zeros()` would switch `bias` off for the layer.
|
||||||
layer.
|
|
||||||
|
|
||||||
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
||||||
"""
|
"""
|
||||||
function Conv(w::AbstractArray{T,N}, b::Union{Nothing, Zeros, AbstractVector{T}}, σ = identity;
|
function Conv(w::AbstractArray{T,N}, b::Union{Zeros, AbstractVector{T}}, σ = identity;
|
||||||
stride = 1, pad = 0, dilation = 1) where {T,N}
|
stride = 1, pad = 0, dilation = 1) where {T,N}
|
||||||
stride = expand(Val(N-2), stride)
|
stride = expand(Val(N-2), stride)
|
||||||
pad = expand(Val(2*(N-2)), pad)
|
pad = expand(Val(2*(N-2)), pad)
|
||||||
dilation = expand(Val(N-2), dilation)
|
dilation = expand(Val(N-2), dilation)
|
||||||
b = b isa Nothing ? Zeros((size(w, ndims(w)), )) : b
|
|
||||||
return Conv(σ, w, b, stride, pad, dilation)
|
return Conv(σ, w, b, stride, pad, dilation)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -70,14 +67,14 @@ distribution.
|
|||||||
See also: [`depthwiseconvfilter`](@ref)
|
See also: [`depthwiseconvfilter`](@ref)
|
||||||
"""
|
"""
|
||||||
convfilter(filter::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer};
|
convfilter(filter::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer};
|
||||||
init = glorot_uniform) where N = init(filter..., ch...)
|
init = glorot_uniform) where N = init(filter..., ch...)
|
||||||
|
|
||||||
function Conv(k::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer}, σ = identity;
|
function Conv(k::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer}, σ = identity;
|
||||||
init = glorot_uniform, stride = 1, pad = 0, dilation = 1,
|
init = glorot_uniform, stride = 1, pad = 0, dilation = 1,
|
||||||
weight = convfilter(k, ch, init = init), bias = zeros(ch[2])) where N
|
weight = convfilter(k, ch, init = init), bias = zeros(ch[2])) where N
|
||||||
|
|
||||||
Conv(weight, bias, σ,
|
Conv(weight, bias, σ,
|
||||||
stride = stride, pad = pad, dilation = dilation)
|
stride = stride, pad = pad, dilation = dilation)
|
||||||
end
|
end
|
||||||
|
|
||||||
@functor Conv
|
@functor Conv
|
||||||
@ -114,8 +111,7 @@ 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.
|
be a `100×100×3` array, and a batch of 50 would be a `100×100×3×50` array.
|
||||||
|
|
||||||
Accepts keyword arguments `weight` and `bias` to set the corresponding fields.
|
Accepts keyword arguments `weight` and `bias` to set the corresponding fields.
|
||||||
Setting `bias` to `Flux.Zeros()` will switch bias off for the
|
Setting `bias` to `Flux.Zeros()` will switch bias off for the layer.
|
||||||
layer.
|
|
||||||
|
|
||||||
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
||||||
"""
|
"""
|
||||||
@ -136,23 +132,21 @@ Constructs the convolutional transpose layer with user defined weight and bias a
|
|||||||
All other behaviours of the ConvTranspose layer apply with regard to data order and
|
All other behaviours of the ConvTranspose layer apply with regard to data order and
|
||||||
forward pass.
|
forward pass.
|
||||||
|
|
||||||
Setting `bias` to `nothing` or `Flux.Zeros()` would switch `bias` off for the
|
Setting `bias` to `Flux.Zeros()` would switch `bias` off for the layer.
|
||||||
layer.
|
|
||||||
|
|
||||||
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
||||||
"""
|
"""
|
||||||
function ConvTranspose(w::AbstractArray{T,N}, b::Union{Nothing, Zeros, AbstractVector{T}}, σ = identity;
|
function ConvTranspose(w::AbstractArray{T,N}, b::Union{Zeros, AbstractVector{T}}, σ = identity;
|
||||||
stride = 1, pad = 0, dilation = 1) where {T,N}
|
stride = 1, pad = 0, dilation = 1) where {T,N}
|
||||||
stride = expand(Val(N-2), stride)
|
stride = expand(Val(N-2), stride)
|
||||||
pad = expand(Val(2*(N-2)), pad)
|
pad = expand(Val(2*(N-2)), pad)
|
||||||
dilation = expand(Val(N-2), dilation)
|
dilation = expand(Val(N-2), dilation)
|
||||||
b = b isa Nothing ? Zeros((size(w, ndims(w)), )) : b
|
|
||||||
return ConvTranspose(σ, w, b, stride, pad, dilation)
|
return ConvTranspose(σ, w, b, stride, pad, dilation)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ConvTranspose(k::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer}, σ = identity;
|
function ConvTranspose(k::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer}, σ = identity;
|
||||||
init = glorot_uniform, stride = 1, pad = 0, dilation = 1,
|
init = glorot_uniform, stride = 1, pad = 0, dilation = 1,
|
||||||
weight = convfilter(k, reverse(ch), init = init), bias = zeros(ch[2])) where N
|
weight = convfilter(k, reverse(ch), init = init), bias = zeros(ch[2])) where N
|
||||||
|
|
||||||
ConvTranspose(weight, bias, σ,
|
ConvTranspose(weight, bias, σ,
|
||||||
stride = stride, pad = pad, dilation = dilation)
|
stride = stride, pad = pad, dilation = dilation)
|
||||||
@ -168,9 +162,9 @@ function conv_transpose_dims(c::ConvTranspose, x::AbstractArray)
|
|||||||
batch_size = size(x)[end]
|
batch_size = size(x)[end]
|
||||||
# Create DenseConvDims() that looks like the corresponding conv()
|
# Create DenseConvDims() that looks like the corresponding conv()
|
||||||
return DenseConvDims((I..., C_in, batch_size), size(c.weight);
|
return DenseConvDims((I..., C_in, batch_size), size(c.weight);
|
||||||
stride=c.stride,
|
stride=c.stride,
|
||||||
padding=c.pad,
|
padding=c.pad,
|
||||||
dilation=c.dilation,
|
dilation=c.dilation,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -206,8 +200,7 @@ 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.
|
be a `100×100×3` array, and a batch of 50 would be a `100×100×3×50` array.
|
||||||
|
|
||||||
Accepts keyword arguments `weight` and `bias` to set the corresponding fields.
|
Accepts keyword arguments `weight` and `bias` to set the corresponding fields.
|
||||||
Setting `bias` to `Flux.Zeros()` will switch bias off for the
|
Setting `bias` to `Flux.Zeros()` will switch bias off for the layer.
|
||||||
layer.
|
|
||||||
|
|
||||||
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
||||||
"""
|
"""
|
||||||
@ -228,17 +221,15 @@ Constructs the `DepthwiseConv` layer with user defined weight and bias arrays.
|
|||||||
All other behaviours of the `DepthwiseConv` layer apply with regard to data order and
|
All other behaviours of the `DepthwiseConv` layer apply with regard to data order and
|
||||||
forward pass.
|
forward pass.
|
||||||
|
|
||||||
Setting `bias` to `nothing` or `Flux.Zeros()` would switch `bias` off for the
|
Setting `bias` to `Flux.Zeros()` would switch `bias` off for the layer.
|
||||||
layer.
|
|
||||||
|
|
||||||
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
||||||
"""
|
"""
|
||||||
function DepthwiseConv(w::AbstractArray{T,N}, b::Union{Nothing, Zeros, AbstractVector{T}}, σ = identity;
|
function DepthwiseConv(w::AbstractArray{T,N}, b::Union{Zeros, AbstractVector{T}}, σ = identity;
|
||||||
stride = 1, pad = 0, dilation = 1) where {T,N}
|
stride = 1, pad = 0, dilation = 1) where {T,N}
|
||||||
stride = expand(Val(N-2), stride)
|
stride = expand(Val(N-2), stride)
|
||||||
pad = expand(Val(2*(N-2)), pad)
|
pad = expand(Val(2*(N-2)), pad)
|
||||||
dilation = expand(Val(N-2), dilation)
|
dilation = expand(Val(N-2), dilation)
|
||||||
b = b isa Nothing ? Zeros((size(w, ndims(w)), )) : b
|
|
||||||
return DepthwiseConv(σ, w, b, stride, pad, dilation)
|
return DepthwiseConv(σ, w, b, stride, pad, dilation)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -254,11 +245,11 @@ distribution.
|
|||||||
See also: [`convfilter`](@ref)
|
See also: [`convfilter`](@ref)
|
||||||
"""
|
"""
|
||||||
depthwiseconvfilter(filter::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer};
|
depthwiseconvfilter(filter::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer};
|
||||||
init = glorot_uniform) where N = init(filter..., div(ch[2], ch[1]), ch[1])
|
init = glorot_uniform) where N = init(filter..., div(ch[2], ch[1]), ch[1])
|
||||||
|
|
||||||
function DepthwiseConv(k::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer}, σ = identity;
|
function DepthwiseConv(k::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer}, σ = identity;
|
||||||
init = glorot_uniform, stride = 1, pad = 0, dilation = 1,
|
init = glorot_uniform, stride = 1, pad = 0, dilation = 1,
|
||||||
weight = depthwiseconvfilter(k, ch, init = init), bias = zeros(ch[2])) where N
|
weight = depthwiseconvfilter(k, ch, init = init), bias = zeros(ch[2])) where N
|
||||||
@assert ch[2] % ch[1] == 0 "Output channels must be integer multiple of input channels"
|
@assert ch[2] % ch[1] == 0 "Output channels must be integer multiple of input channels"
|
||||||
|
|
||||||
return DepthwiseConv(
|
return DepthwiseConv(
|
||||||
@ -312,8 +303,7 @@ In other words, a 100×100 RGB image would be a `100×100×3×1` array,
|
|||||||
and a batch of 50 would be a `100×100×3×50` array.
|
and a batch of 50 would be a `100×100×3×50` array.
|
||||||
|
|
||||||
Accepts keyword arguments `weight` and `bias` to set the corresponding fields.
|
Accepts keyword arguments `weight` and `bias` to set the corresponding fields.
|
||||||
Setting `bias` to `Flux.Zeros()` will switch bias off for the
|
Setting `bias` to `Flux.Zeros()` will switch bias off for the layer.
|
||||||
layer.
|
|
||||||
|
|
||||||
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
||||||
"""
|
"""
|
||||||
@ -334,23 +324,21 @@ Constructs the standard cross convolutional layer with user defined weight and b
|
|||||||
arrays. All other behaviours of the CrossCor layer apply with regard to data order and
|
arrays. All other behaviours of the CrossCor layer apply with regard to data order and
|
||||||
forward pass.
|
forward pass.
|
||||||
|
|
||||||
Setting `bias` to `nothing` or `Flux.Zeros()` would switch `bias` off for the
|
Setting `bias` to `Flux.Zeros()` would switch `bias` off for the layer.
|
||||||
layer.
|
|
||||||
|
|
||||||
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
Takes the keyword arguments `pad`, `stride` and `dilation`.
|
||||||
"""
|
"""
|
||||||
function CrossCor(w::AbstractArray{T,N}, b::Union{Nothing, Zeros, AbstractVector{T}}, σ = identity;
|
function CrossCor(w::AbstractArray{T,N}, b::Union{Zeros, AbstractVector{T}}, σ = identity;
|
||||||
stride = 1, pad = 0, dilation = 1) where {T,N}
|
stride = 1, pad = 0, dilation = 1) where {T,N}
|
||||||
stride = expand(Val(N-2), stride)
|
stride = expand(Val(N-2), stride)
|
||||||
pad = expand(Val(2*(N-2)), pad)
|
pad = expand(Val(2*(N-2)), pad)
|
||||||
dilation = expand(Val(N-2), dilation)
|
dilation = expand(Val(N-2), dilation)
|
||||||
b = b isa Nothing ? Zeros((size(w, ndims(w)), )) : b
|
|
||||||
return CrossCor(σ, w, b, stride, pad, dilation)
|
return CrossCor(σ, w, b, stride, pad, dilation)
|
||||||
end
|
end
|
||||||
|
|
||||||
function CrossCor(k::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer}, σ = identity;
|
function CrossCor(k::NTuple{N,Integer}, ch::Pair{<:Integer,<:Integer}, σ = identity;
|
||||||
init = glorot_uniform, stride = 1, pad = 0, dilation = 1,
|
init = glorot_uniform, stride = 1, pad = 0, dilation = 1,
|
||||||
weight = convfilter(k, ch, init = init), bias = zeros(ch[2])) where N
|
weight = convfilter(k, ch, init = init), bias = zeros(ch[2])) where N
|
||||||
|
|
||||||
CrossCor(weight, bias, σ,
|
CrossCor(weight, bias, σ,
|
||||||
stride = stride, pad = pad, dilation = dilation)
|
stride = stride, pad = pad, dilation = dilation)
|
||||||
|
Loading…
Reference in New Issue
Block a user