Creating Ensemble Model(s) with Flux

I think you want something like this:

makeloss(m) = (x, y) -> mse(m(x), y)
Flux.train!(makeloss(model), params(model), [(x, y)], Flux.Adam())

Or you can just make the anonymous function directly, perhaps with a do block. Something like:

models = [Chain(Dense(300, 300)) for _ in 1:10]
opt = Flux.Adam()  # should be ok to share this

for m in models
  Flux.train!(params(m), [(x, y)], opt) do x1, y1
    mse(m(x1), y1)
  end
end
1 Like