# Simple Knet.jl Question: save/load model?

**URL:** https://discourse.julialang.org/t/simple-knet-jl-question-save-load-model/8202
**Category:** Machine Learning
**Tags:** knet
**Created:** [January 6, 2018, 5:03pm UTC](https://discourse.julialang.org/t/simple-knet-jl-question-save-load-model/8202 "2018-01-06T17:03:14Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Joshua\_Bowles](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshua_bowles/32/4515_2.png) [@Joshua\_Bowles](https://discourse.julialang.org/u/Joshua_Bowles)
#### Post date: [January 6, 2018, 5:03pm UTC](https://discourse.julialang.org/t/simple-knet-jl-question-save-load-model/8202/1 "2018-01-06T17:03:14Z")

</div>

I’m new to julia (as of last week; toyed a bit long time ago with v0.2). I’ve looked over previous Knet posts, searched docs, and Knet (stable) source but can’t find an example of saving/loading a model.

I see what look like some examples of loading or saving a model, but in the knet source these are in the deprecated directory… for example `model = gpucopy(load(opts["modelfile"],"model"))` in [Knet predict.jl deprecated example](https://github.com/denizyuret/Knet.jl/blob/1ef934cc58f9671f2d85063f88a3d6959a49d088/examples/deprecated/ipa/predict.jl#L14) … or this in the deprecated s2s.jl `# todo: implement load/save: revive cpucopy - done`

Could someone point me to an example or help me with how one saves and loads an pre-trained model?

What I’m trying to do: I’m evaluating julia for use in my company. Ideally I’d like to build ML/DL models and provide a backend “prediction” API… doing all of that in 1 language would be awesome!

One option is to build the graph (and likely train) in python-tensorflow then use go-tensorflow (maybe to train, definitely to serve the model) with go http server.

I’t might also be cool to see if I could build in Knet (or flux) and see if I could somehow serve the model from go (my understanding though is that would not be straightforward).

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [January 6, 2018, 6:36pm UTC](https://discourse.julialang.org/t/simple-knet-jl-question-save-load-model/8202/2 "2018-01-06T18:36:30Z")

</div>

> [@Joshua\_Bowles](#):
>
> I’m new to julia (as of last week; toyed a bit long time ago with v0.2). I’ve looked over previous Knet posts, searched docs, and Knet (stable) source but can’t find an example of saving/loading a model.
> 
> I see what look like some examples of loading or saving a model, but in the knet source these are in the deprecated directory… for example model = gpucopy(load(opts[“modelfile”],“model”)) in Knet predict.jl deprecated example … or this in the deprecated s2s.jl # todo: implement load/save: revive cpucopy - done
> 
> Could someone point me to an example or help me with how one saves and loads an pre-trained model?

They are using the JLD.jl library. I would instead suggest using JLD2.jl

[https://github.com/simonster/JLD2.jl](https://github.com/simonster/JLD2.jl)

It’ll save pretty much anything. But one thing to remember is you have to `using KNet` before loading in order for it to know how to rebuild the types.

---

<div class="post-metadata">

### Author: ![Joshua\_Bowles](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshua_bowles/32/4515_2.png) [@Joshua\_Bowles](https://discourse.julialang.org/u/Joshua_Bowles)
#### Post date: [January 6, 2018, 7:35pm UTC](https://discourse.julialang.org/t/simple-knet-jl-question-save-load-model/8202/3 "2018-01-06T19:35:41Z")

</div>

sweet, thanks. Gonna check it out. I’m thrilled (and a bit overwhelmed) at the number of projects in julia’s ecosystem. Just got done scanning down the list of packages in JuliaML… 😲
