Convert trained PyTorch models to Keras, and the other way around
Switch branches/tags
Nothing to show
Clone or download
Latest commit 27f3a57 Dec 28, 2017


Build Status

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.