conv bias

This commit is contained in:
Mike J Innes 2018-02-15 20:15:41 +00:00
parent bdd07a8bc6
commit 01c31e7fcc

View File

@ -10,20 +10,24 @@ be a `100×100×3` array, and a batch of 50 would be a `100×100×3×50` array.
Takes the keyword arguments `pad` and `stride`. Takes the keyword arguments `pad` and `stride`.
""" """
struct Conv2D{F,A} struct Conv2D{F,A,V}
σ::F σ::F
weight::A weight::A
bias::V
stride::Int stride::Int
pad::Int pad::Int
end end
Conv2D(k::NTuple{2,Integer}, ch::Pair{<:Integer,<:Integer}, σ = identity; Conv2D(k::NTuple{2,Integer}, ch::Pair{<:Integer,<:Integer}, σ = identity;
init = initn, stride = 1, pad = 0) = init = initn, stride = 1, pad = 0) =
Conv2D(σ, param(init(k..., ch...)), stride, pad) Conv2D(σ, param(init(k..., ch...)), param(zeros(ch[2])), stride, pad)
Flux.treelike(Conv2D) Flux.treelike(Conv2D)
(c::Conv2D)(x) = c.σ.(conv2d(x, c.weight, stride = c.stride, padding = c.pad)) function (c::Conv2D)(x)
σ, b = c.σ, reshape(c.bias, 1, 1, :)
σ.(conv2d(x, c.weight, stride = c.stride, padding = c.pad) .+ b)
end
function Base.show(io::IO, l::Conv2D) function Base.show(io::IO, l::Conv2D)
print(io, "Conv2D((", size(l.weight, 1), ", ", size(l.weight, 2), ")") print(io, "Conv2D((", size(l.weight, 1), ", ", size(l.weight, 2), ")")