Hi everyone!I am trying to create a custom layer, and customize the parameter collection to train, the following is my code
using Flux
struct Linear{F,S<:AbstractArray,T<:AbstractArray}
W::S
b::T
σ::F
end
function Linear(in::Integer, out::Integer, σ = identity;
initW = Flux.glorot_uniform, initb = zeros)
return Linear(initW(out, in), initb(out), σ)
end
function (a::Linear)(x::AbstractArray)
W, b, σ = a.W, a.b, a.σ
σ.(W*x .+ b)
end
Flux.@functor Linear (W,)
# Flux.trainable(m::Linear) = (m.W)
m = Linear(2,1)
ps = Flux.params(m) # always get Params([])
But the ps
is always empty, Where is wrong?