Convert PyTorch models to Keras (TensorFlow backend) for deployment and interoperability.
pytorch2keras is a Python library that converts PyTorch neural network models into Keras models with TensorFlow backend. It solves the problem of framework lock-in by enabling developers to train models in PyTorch and deploy them using Keras/TensorFlow tooling, including export to TensorFlow.js for web applications.
Deep learning engineers and researchers who train models in PyTorch but need to deploy them in TensorFlow-based production environments or convert them to formats like TensorFlow.js for web deployment.
Developers choose pytorch2keras because it provides a simple, code-minimal conversion process with support for many common PyTorch layers and architectures, reducing the need for manual model rewriting and enabling faster experimentation-to-deployment cycles.
PyTorch to Keras model convertor
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Handles common layers like convolutions, activations, and normalizations, enabling conversion of popular architectures such as ResNet and MobileNet v2 as listed in the README.
Supports dynamic input shapes with None dimensions, allowing for fully convolutional networks without fixed size constraints, as shown in the usage examples.
Provides detailed, step-by-step guidance for exporting to TensorFlow.js, including code snippets for freezing the graph and using tensorflowjs_converter.
Offers a straightforward pytorch_to_keras function that requires minimal code changes, demonstrated with a clean conversion workflow in the README.
Requires manual changes to keras.json to set backend to TensorFlow and image_data_format to channels_first, which can disrupt existing projects and add setup complexity.
Only supports a subset of PyTorch layers; advanced operations like recurrent layers are missing, restricting conversion for models with non-standard architectures.
The TensorFlow.js conversion process is multi-step and relies on a custom freeze_session function, increasing the risk of errors and making it less user-friendly.