Is it possible to use PyTorch as backend for Keras?

Is it possible to use PyTorch as backend for Keras?


No, currently only Tensorflow, Theano and CNTK are supported (source). Mxnet seems to be in a beta version.
I doubt that Pytorch will be supported in the near future. :wink:
If you are looking for a high-level API, you could try Ignite or Skorch.


what are the advantages and disadvantages of Ignite and Skorch? Which one would you recommend?

Skorch is a scikit-learn compatible wrapper. So if you will feel comfortable using it, if you’re using scikit-learn a lot or like it’s API.
On the other hand, Ignite let’s you define your model and training procedure and just provides some callbacks etc. for convenience. It sounds interesting.

I cannot recommend any wrapper so far, since I’m using plain Pytorch.
For me it’s the right abstraction, so that I can easily define my nets and try some crazy idea.
Using learning rate schedulers etc. I have everything I need so far.
The only point I would like to have is a smoother Visdom integration. At the moment I feel like creating a lot of boilerplate code to visualize the loss etc., but that’s a Visdom issue. :wink:

Give both wrappers a shot and post your experience.


I agree. Both, PyTorch and Keras are high-level API’s.
Accessing PyTorch through Keras would be meaningless.

1 Like

I do agree that the high-level abstractions of Keras would be meaningless, especially when the high-level API of PyTorch is soo convenient. However, I have experienced a few cases were it would’ve been convenient when dealing with legacy code.

Example. I needed to use open-source code from a few years back which was written in Keras. I needed to extend the code with some linear algebra functionality I’ve written in PyTorch. The backend of the Keras code was TensorFlow. This forced me to rewrite the PyTorch linear algebra code to TensorFlow. If I could’ve changed the backend I would’ve circumvented having to rewrite from PyTorch to TensorFlow.