How to create a Flux model from parameter vector?

I would first create the model using something like

model = Chain(map(x -> Dense(x[1]...), shape)...)

and then use loadparams!(model, theta),
where I would create theta as

theta = mapreduce(x -> [view(parameter_vector, x[1]...),view(parameter_vector, x[2])], vcat, shape)

Also, there is destructure and restructure commands, converting model to a vector of parameters and back, so I would take a look on those.

2 Likes