For my personal uses, I build a network like the example provided by Flux.
However, the resulting function (model) m
is not compatible with Flux.params
.
Here’s reproducible easy example corresponding to my case:
julia> using Flux
julia> layers = [Dense(5, 2), Dense(2, 1)]
2-element Array{Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},1}:
Dense(5, 2)
Dense(2, 1)
julia> m(x) = foldl((x, m) -> m(x), layers, init=x)
m (generic function with 1 method)
julia> params(m)
Params([])
Is there any way to use params
with the networks constructed by this way of using foldl
?
Note:
Here’s my raw code (illustrative; would not be executable for others due to dependencies).
function ICNN(n_x, n_y, n_V, n_h, act, num_layers)
layers = []
for i in 1:num_layers
n_u, n_out = n_h, n_h
if i == 1
n_u = n_x
elseif i == num_layers
n_out = n_V
end
layer = ICNN_Layer(n_u, n_h, n_h, n_out, n_y, act)
push!(layers, layer)
end
push!(layers, selector)
m(x, y) = foldl((input, m) -> m(input, layers, init=(x, zeros(n_h), y)))
return m
end