# Struggling to load a pre-trained PyTorch model into Julia

**URL:** <https://discourse.julialang.org/t/struggling-to-load-a-pre-trained-pytorch-model-into-julia/104068>\
**Category:** Machine Learning\
**Tags:** flux\
**Created:** [September 20, 2023, 3:39pm UTC](https://discourse.julialang.org/t/struggling-to-load-a-pre-trained-pytorch-model-into-julia/104068 "2023-09-20T15:39:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jian\_ZUO](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jian_zuo/32/33738_2.png) [@Jian\_ZUO](https://discourse.julialang.org/u/Jian_ZUO)\
**Post date:** [September 20, 2023, 3:39pm UTC](https://discourse.julialang.org/t/struggling-to-load-a-pre-trained-pytorch-model-into-julia/104068/1 "2023-09-20T15:39:07Z")

</div>

Hi all,  
I am coming back to this unsolved problem.  
The background is that I have trained a reinforcement learning agent and I want to load the pre-trained model (pytorch) into Julia for inference (it is much faster to evaluate the performance which costs lots of time in python).

Can anyone have a similar experience please share a small demo of how to achieve this?  
Thank you in advance!

---

<div class="post-metadata">

**Author:** ![CarloLucibello](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carlolucibello/32/3278_2.png) [@CarloLucibello](https://discourse.julialang.org/u/CarloLucibello)\
**Post date:** [September 20, 2023, 5:31pm UTC](https://discourse.julialang.org/t/struggling-to-load-a-pre-trained-pytorch-model-into-julia/104068/2 "2023-09-20T17:31:44Z")

</div>

Metalhead.jl has some scripts to load weights from torchision models, you can try adapting one of those

[https://github.com/FluxML/Metalhead.jl/tree/master/scripts](https://github.com/FluxML/Metalhead.jl/tree/master/scripts)

---

<div class="post-metadata">

**Author:** ![Jian\_ZUO](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jian_zuo/32/33738_2.png) [@Jian\_ZUO](https://discourse.julialang.org/u/Jian_ZUO)\
**Post date:** [September 20, 2023, 7:34pm UTC](https://discourse.julialang.org/t/struggling-to-load-a-pre-trained-pytorch-model-into-julia/104068/3 "2023-09-20T19:34:24Z")

</div>

Thanks for pointing out this. I will try to see if it works.
