Giter VIP home page Giter VIP logo

paddle2onnx's Introduction

Paddle2ONNX

简体中文 | English

Introduction

Paddle2ONNX enables users to convert models from PaddlePaddle to ONNX.

  • Supported model format. Paddle2ONNX supports both dynamic and static computational graph of PaddlePaddle. For static computational graph, Paddle2ONNX converts PaddlePaddle models saved by API save_inference_model, for example IPthon example.For dynamic computational graph, it is now under experiment and more details will be released after the release of PaddlePaddle 2.0.
  • Supported operators. Paddle2ONNX can stably export models to ONNX Opset 9~11, and partialy support lower version Opset. More details please refer to Operator list.
  • Supported models. You can find officially verified models by Paddle2ONNX in model zoo.

Environment dependencies

Configuration

 python >= 2.7  
 static computational graph: paddlepaddle >= 1.8.0
 dynamic computational graph: paddlepaddle >= 2.0.0
 onnx == 1.7.0 | Optional

Installation

Pip

pip install paddle2onnx

From source

 git clone https://github.com/PaddlePaddle/paddle2onnx.git
 python setup.py install

Usage

Static computational graph

Using with command line

Uncombined PaddlePaddle model(parameters saved in different files)

paddle2onnx --model_dir paddle_model  --save_file onnx_file --opset_version 10 --enable_onnx_checker True

Combined PaddlePaddle model(parameters saved in one binary file)

paddle2onnx --model_dir paddle_model  --model_filename model_filename --params_filename params_filename --save_file onnx_file --opset_version 10 --enable_onnx_checker True

Parameters

parameters Description
--model_dir the directory path of the paddlepaddle model saved by paddle.fluid.io.save_inference_model
--model_filename [Optional] the model file name under the directory designated by--model_dir. Only needed when all the model parameters saved in one binary file. Default value None
--params_filename [Optonal] the parameter file name under the directory designated by--model_dir. Only needed when all the model parameters saved in one binary file. Default value None
--save_file the directory path for the exported ONNX model
--opset_version [Optional] To configure the ONNX Opset version. Opset 9-11 are stably supported. Default value is 9.
--enable_onnx_checker [Optional] To check the validity of the exported ONNX model. It is suggested to turn on the switch. If set to True, onnx>=1.7.0 is required. Default value is False
--version [Optional] check the version of paddle2onnx
  • Two types of PaddlePaddle models
    • Combined model, parameters saved in one binary file. --model_filename and --params_filename represents the file name and parameter name under the directory designated by --model_dir. --model_filename and --params_filename are valid only with parameter --model_dir.
    • Uncombined model, parameters saved in different files. Only --model_dir is needed,which contains '__model__' file and the seperated parameter files.

IPython tutorials

Dynamic computational graph

import paddle
from paddle import nn
from paddle.static import InputSpec
import paddle2onnx as p2o

class LinearNet(nn.Layer):
    def __init__(self):
        super(LinearNet, self).__init__()
        self._linear = nn.Linear(784, 10)

    def forward(self, x):
        return self._linear(x)

layer = LinearNet()

# configure model inputs
x_spec = InputSpec([None, 784], 'float32', 'x')

# convert model to inference mode
layer.eval()

save_path = 'onnx.save/linear_net'
p2o.dygraph2onnx(layer, save_path + '.onnx', input_spec=[x_spec])

# when paddlepaddle>2.0.0, you can try:
# paddle.onnx.export(layer, save_path, input_spec=[x_spec])

IPython tutorials

Relative documents

License

Apache-2.0 license.

paddle2onnx's People

Contributors

aipioneer avatar channingss avatar cjt222 avatar jiangjiajun avatar mvafin avatar pkuyym avatar rollroll90 avatar sidgoyal78 avatar sunahong1993 avatar tsocha avatar wangwin avatar wawltor avatar xsrobin avatar zeyuchen 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.