Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load a trained model with BSON in Flux.jl

I trained a model earlier in Flux.jl and saved it by doing:

@save "mymodel.bson" model

Now I want to load that model back and use it again. How can I achieve this in Flux?

like image 505
logankilpatrick Avatar asked Sep 20 '25 05:09

logankilpatrick


1 Answers

Similar to the @save macro used above, there is also a built in @load macro which comes from the BSON package. You can access it by doing using BSON: @load and then quite simply do something like:

julia> using Flux

julia> using BSON: @load

julia> @load "mymodel.bson" model

julia> model
Chain(Dense(10, 5, NNlib.relu), Dense(5, 2), NNlib.softmax)

You can find out more about saving and loading models in the Flux.jl docs.

like image 73
logankilpatrick Avatar answered Sep 23 '25 01:09

logankilpatrick