Giter VIP home page Giter VIP logo

paddle-onnx's Introduction

PaddlePaddle to ONNX model convertor

Converts a PaddlePaddle model (ProgramDesc + parameters) into an ONNX model, with a goal to support inference of PaddlePaddle models across hardware platforms. Uses the ONNX pip helper library and targets models constructed with PaddlePaddle's Fluid API. Written in Python 2.7 (and underneath the hood, ONNX binds its Python helpers to their C++ packages).

Usage

Before running the convertor,

  • Install all the necessary dependencies (see "Installation" section below)
  • Generate/save a PaddlePaddle Fluid model using the generate model directory by running any fluid test / example and write the model using the fluid.io.save_inference_model API (see some of the examples that you can plug this into).
    • A simple model for fit_a_line has been provided within the extras directory of this repo, to help you skip this step if you just wish to test it out.

Then, run the following:

python fluid_to_onnx.py --fluid_model <path_to_paddlepaddle_fluid.model> --onnx_model <path_to_where_you_want_to_output_model.onnx>

This should output an ONNX model (current version of opset: 6) which can be run on an ONNX backend for inference.

Installation

  1. Clone the paddle-onnx repository from GitHub (in future, we plan to integrate it into the core PaddlePaddle pip and Docker distributable packages).

  2. Install the external dependencies.

    1. Create a virtual environment to isolate dependencies (Optional).

      virtualenv venv

    2. If you are running on Ubuntu, run ./setup.sh and move to the next step.

      On other systems, you need to install protobuf manually before installing the Python package dependencies. On Mac, to get the development version, use brew install protobuf.

    3. If you created a virtual environment, activate it using:

      source venv/bin/activate

  3. We now need to make sure that we have a built PaddlePaddle package available for us. If you have this setup during your model building process, and have the PYTHONPATH of PaddlePaddle already set in the environment (this should be setup if you followed the right instructions or used Docker), you are all set and continue to use the converter!

    The way you can test this is by opening up the Python shell by running python on your main shell. And then, if you can import paddle, you are all set.

    If not, build PaddlePaddle's develop branch from source. Make the paddle/python available in the execution environment's PYTHONPATH, or pip install the wheel after building the target paddle_python.

    NOTE: Make sure your virtual environment has the new Protobuf and the correct onnx dependency used by this project (see the version in the requirements.txt file), as the PaddlePaddle installation may try to downgrade it without asking you.

How it works

Status

The current release targets Paddle->ONNX conversion for now (or what's called frontend in the ONNX world), and will consequently support the reverse too.

Currently aimed at a wider coverage of models and operators. There are several PaddlePaddle model features not available in ONNX and some vice-versa, so will also aim to resolve these in near future. See the design document in the How it works section above for more details.

Testing / validation

Install dependencies

You may use either the Caffe2 or the ONNX-TensorRT backend (basically platforms where the ONNX models are executed) to test your models.

Please refer to each library / platforms' installation instructions pages (and make them available in the current Python virtual environment, if you created one):

Validate a model

To validate the similarity of the PaddlePaddle Fluid model and the exported ONNX model, run the following:

python validate.py --fluid_model <path_to_paddlepaddle_fluid.model> --onnx_model <path_to_exported_model.onnx>

This validation aims for an output tensor comparison precision at 5-decimal places. To discover the other arguments to validation, run:

python validate.py --help

Supported models

We aim to at least support all the models from our model bank. During our preliminary stage, we have validated the inference model's conversion on following models:

Got feedback or issues?

If you have suggestions or bugs you run into, we invite you to share them in the Issues section of this repo. The maintainers of this project look at these issues everyday - you know, while squinting their eyes staring at their cell phones in the dark right after waking up.

Contribute

In the highest spirits of open-source, we welcome your contributions! The philosophy around contribution at this stage is to get better model coverage. Some of the code for training popular models is already written for PaddlePaddle Fluid. For code not written for PaddlePaddle Fluid, we invite writing this training code first (and possibly contributing it to the tests inside PaddlePaddle's main repo) and then:

  • Read the documents in the How it works section above.
  • (Optional) Create an issue sharing need for support for a new model. Assign to yourself.
  • Add the necessary operator conversion logic in fluid_onnx/ops.py.
  • Write tests for the newly introduced operator convertor functions.
  • Add the model to the list of supported models in this root README.md file.
  • Open a new PR for the model(s) that resolves your issue. In your tests, post the output of your validation process.

License

Provided under the Apache-2.0 license.

paddle-onnx's People

Contributors

pkuyym avatar sidgoyal78 avatar tsocha avatar mvafin avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.