X2Paddle: A Bridge Between AI Frameworks
X2Paddle is a model conversion tool within the PaddlePaddle ecosystem. It is designed to help users of other deep learning frameworks quickly migrate models to the PaddlePaddle framework. Presently, it supports the conversion of inference models as well as the migration of PyTorch training code. Additionally, X2Paddle provides comprehensive API comparison documents between different frameworks, significantly reducing the time developers spend on migration.
Features
-
Support for Major Deep Learning Frameworks: X2Paddle currently supports the conversion of predictive models from four prominent frameworks: Caffe, TensorFlow, ONNX, and PyTorch. It also facilitates the conversion of PyTorch training projects, covering most of the mainstream deep learning frameworks available in the market.
-
Rich Model Support: It supports a wide range of models, especially in the fields of computer vision (CV) and natural language processing (NLP). Currently, X2Paddle supports over 130 PyTorch operations, 90 ONNX operations, 90 TensorFlow operations, and 30 Caffe operations.
-
Simplicity and Ease of Use: Users can complete model conversions with a single command line entry or through an API, making it highly accessible and user-friendly.
Capabilities
-
Inference Model Conversion: X2Paddle can convert models from Caffe, TensorFlow, ONNX, and PyTorch to PaddlePaddle's format with just one click. These converted models can then be deployed across different devices using PaddleInference and PaddleLite.
-
PyTorch Training Project Conversion: It supports the direct conversion of PyTorch project Python code, including training and inference code, into PaddlePaddle-based project code. This feature enables developers to quickly migrate their projects and benefit from the extensive free computational resources provided by the AIStudio platform.
-
Comprehensive API Documentation: Detailed API comparison and analysis documentation is available to assist developers in transitioning smoothly from using the PyTorch framework to leveraging the PaddlePaddle framework.
Installation
To get started with X2Paddle, the following dependencies are required:
- Python version 3.5 or higher
- PaddlePaddle version 2.2.2 or higher
- TensorFlow version 1.14 (for TensorFlow model conversion)
- ONNX version 1.6.0 or higher (for ONNX model conversion)
- Torch version 1.5.0 or higher (for PyTorch model conversion)
- PaddleLite version 2.9.0 or higher (for conversion to Paddle-Lite format)
Recommended Installation via pip
For a stable release, X2Paddle can be installed using pip:
pip install x2paddle
Latest Features via Source Installation
To experience the latest features, the source installation method is available:
git clone https://github.com/PaddlePaddle/X2Paddle.git
cd X2Paddle
git checkout develop
python setup.py install
Quick Start
Feature 1: Inference Model Conversion
For converting PyTorch models:
from x2paddle.convert import pytorch2paddle
pytorch2paddle(module=torch_module, save_dir="./pd_model", jit_type="trace", input_examples=[torch_input])
For TensorFlow model conversion:
x2paddle --framework=tensorflow --model=tf_model.pb --save_dir=pd_model
For ONNX model conversion:
x2paddle --framework=onnx --model=onnx_model.onnx --save_dir=pd_model
For Caffe model conversion:
x2paddle --framework=caffe --prototxt=deploy.prototxt --weight=deploy.caffemodel --save_dir=pd_model
For a detailed explanation of the parameters used in model conversion, as well as API options, consult the X2Paddle documentation.
Feature 2: PyTorch Model Training Migration
Project conversion involves three steps:
- Project code preprocessing
- One-click code/pre-trained model conversion
- Post-processing of converted code
For more detailed guidance, refer to the PyTorch training project conversion documentation.
Model Converter Using VisualDL
VisualDL, the PaddlePaddle visualization tool, offers an online service for converting ONNX models to the PaddlePaddle format, which can be accessed on their website.
Tutorials and Examples
Here are some tutorials to help you get started:
- TensorFlow Inference Model Conversion Tutorial
- MMDetection Model Conversion Guide
- PyTorch Inference Model Conversion Tutorial
- PyTorch Training Project Conversion Tutorial
Contributions and Community
X2Paddle welcomes code contributions and suggestions from the community. Developers can submit pull requests to fix issues or add new features. For those with PyTorch training project conversion needs or suggestions, feel free to raise an issue in the project's repository.