Skip to content
Convert trained PyTorch models to Keras, and the other way around
Python Jupyter Notebook
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
nn_transfer Import keras before pytorch Dec 28, 2017
.gitignore Initial version Sep 13, 2017
.travis.yml No progress bar when installing with conda Dec 6, 2017
LICENSE Initial commit Jul 1, 2017 Add note about brokenness Dec 25, 2018
example.ipynb Add h5py dependency Sep 13, 2017


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 TEST_TRANSFER_DIRECTION environment variable, see .travis.yml.

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 flake8.
  • It works for both Python 2 and 3.
You can’t perform that action at this time.