Code Monkey home page Code Monkey logo

pytorch_onnx_exporter's Introduction

What is pytorch_onnx_exporter ?


  • This code is to export onnx file from computer vision pytorch model. Input type is related to single color image (Channel=3, Height, Width).

What shoud I change ?


  • ① You should change model = net.Net() in get_model function. Net() means model's representative class name (ex. ResNet(), DenseNet() ...) in your model.py and Net() has necessary parameters you set.
  • ② If you don't use input as single image, please revise dummy_data = torch.empty(1, 3, args.height, args.width) as your model's input type.
  • ③ If your model has multiple outputs, please revise output_names of torch.onnx.export.

What does this code operate ?


  • ① Load the deep learning network you want to use and set it to evaluation mode.
  • ② Create the onnx model using the torch model.
  • ③ Reload the created onnx model and compare the weights of the torch model and onnx model
  • ④ If the onnx model has different weights from the existing torch model, update the whole and save it anew.
  • ⑤ Finally, load the saved onnx model, add shape information, and then save it again.

Dependencies


pip install torch 
pip install onnx
pip install numpy

What arguments do it needs ?


  • Arguments below are required and optional. You can use like below.

- `python pytorch_noonx_exporter \
    --model_path=/path/.../to/.../model.py \
    --onnx_file_path=/path/.../to/.../output.onnx \
    --height=512 \
    --width=1024 \
    --checkpoint_path=/path/.../to/.../checkpoint.pth \
    --opset_version=11

  • Arguments list are below.

parser.add_argument('--model_path', required=True, help="model file path")                        
parser.add_argument('--onnx_file_path', required=True, help='onnx file path to be saved.(ex. path/name.onnx)')
parser.add_argument('--height', type=int, required=True, help='target Height of RGB image')
parser.add_argument('--width', type=int, required=True, help='target Width of RGB image')
parser.add_argument('--checkpoint_path', default="", help='(Optional) checkpoint path to load.')
parser.add_argument('--opset_version', type=int, default=11, help='(Optional) opset_version (default = 11).')

pytorch_onnx_exporter's People

Contributors

gaussian37 avatar

Stargazers

 avatar 서영덕_T5105 avatar Jisu Kim avatar  avatar

Watchers

James Cloos avatar  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.