# Importing Pre-Trained Model in Julia

**URL:** https://discourse.julialang.org/t/importing-pre-trained-model-in-julia/33952
**Category:** Machine Learning
**Tags:** question, package
**Created:** [January 29, 2020, 10:36pm UTC](https://discourse.julialang.org/t/importing-pre-trained-model-in-julia/33952 "2020-01-29T22:36:33Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![abianco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abianco/32/12992_2.png) [@abianco](https://discourse.julialang.org/u/abianco)
#### Post date: [January 29, 2020, 10:36pm UTC](https://discourse.julialang.org/t/importing-pre-trained-model-in-julia/33952/1 "2020-01-29T22:36:33Z")

</div>

Is there an effective way to import a pre-trained model (or at least the model specification and weights) in Julia and use it in TensorFlow.jl?  
If not, are there other ways to load in a pre-trained BLSTM and work with it in Julia? I’ve looked into ONNX, but haven’t found yet a working example.

---

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [January 30, 2020, 12:06am UTC](https://discourse.julialang.org/t/importing-pre-trained-model-in-julia/33952/2 "2020-01-30T00:06:25Z")

</div>

You can load model specifications from python tensorflow into TensorFlow.jl using the import metagraph, (in theory).  
[https://malmaud.github.io/TensorFlow.jl/latest/saving.html#Saving-and-restoring-models-1](https://malmaud.github.io/TensorFlow.jl/latest/saving.html#Saving-and-restoring-models-1)

You can’t load weights IIRC as at the time TensorFlow.jl was developed there was no public standard for how python tensorflow stored them.

---

<div class="post-metadata">

### Author: ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)
#### Post date: [January 30, 2020, 12:05pm UTC](https://discourse.julialang.org/t/importing-pre-trained-model-in-julia/33952/3 "2020-01-30T12:05:14Z")

</div>

Hi,

KNET seems to have out of the box support for bidirectional LSTMs:[Reference · Knet.jl](https://denizyuret.github.io/Knet.jl/latest/reference/#Recurrent-neural-networks-1)

With Flux I guess you should be able to craft your own by just using two LSTM layers (and I can’t rule out that there is some other secret way this works in Flux).

As for importing a pre-trained model, [ONNX.jl](https://github.com/FluxML/ONNX.jl) does not seem to handle birectional LSTM and neither does my own [GitHub - DrChainsaw/ONNXNaiveNASflux.jl: Import/export ONNX models](https://github.com/DrChainsaw/ONNXmutable.jl) atm. If you file an issue on the latter (or better, a PR) I can try to add it tonight.

If you just want to do something fast both ONNX.jl and ONNXmutable.jl allow you override the LSTM mapping function with your own function definition by just replacing the :LSTM mapping in a dict.
