Need help with nn-transfer?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

220 Stars 39 Forks MIT License 39 Commits 11 Opened issues


Convert trained PyTorch models to Keras, and the other way around

Services available


Need anything else?

Contributors list

# 44,922
32 commits
# 134,772
6 commits


Build Status

NOTE: This repository does not seem to yield the correct output anymore with the latest versions of Keras and PyTorch. Take care to verify the results or use an alternative method for conversion.

This repository contains utilities for converting PyTorch models to Keras and the other way around. More specifically, it allows you to copy the weights from a PyTorch model to an identical model in Keras and vice-versa.

From Keras you can then run it on the TensorFlow, Theano and CNTK backend. You can also convert it to a pure TensorFlow model (see [1] and [2]), which allows you to choose more robust deployment options in the cloud, or even mobile devices. From Keras you can also do inference in browsers with keras-js.


Clone this repository, and simply run

pip install .

You need to have PyTorch and torchvision installed beforehand, see the PyTorch website for how to easily install that.


To run the unit and integration tests:

python test
# OR, if you have nose2 installed,

There is also Travis CI which will automatically build every commit, see the button at the top of the readme. You can test the direction of weight transfer individually using the

environment variable, see

How to use

See example.ipynb for a small tutorial on how to use this library.

Code guidelines

  • This repository is fully PEP8 compliant, I recommend
  • It works for both Python 2 and 3.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.