Giter Site home page Giter Site logo

onnx-typecast's Introduction

A fork of this: https://github.com/aadhithya/onnx-typecast I've added a script to convert ONNX float16 models to float32, since ONNX Runtime Web doesn't currently support float16. It's very haphazard and I've only tested it with one model. If it misses some nodes, the ONNX runtime should tell you their names (in the error message), and then you can open your model file in netron.app to investigate. You'll then need to add another if statement somewhere around here to handle the currently-unhandled node.


onnx-typecast

A simple python script to typecast ONNX model parameters from INT64 to INT32, and FLOAT16 to FLOAT(32).

Why?

I wanted to play around with ONNX.js and soon figured out that it doesn't support onnx models with INT64 parameters. Also, OpenCV doesn't seem to support INT64 parameters.

What does this script do?

  • The script goes through the parameters of each node of the onnx model and blindly converts INT64 parameters to INT32.
  • It also converts the constant parameters from INT64 to INT32.
  • Finally, creates a new model and saves it.

What's the catch?

  • The script does not handle overflows and blindly converts all INT64 parameters to INT32.
  • So ops that require >INT32.max or <INT32.min values may not perform as expected.
  • Please feel free to modify the script to account for this.

Alright. How do I use it?

  • simple.
  • Install requirements: pip install -r requirements.txt
  • run: python convert-int64-to-int32.py path/to/int64_model.onnx path/to/converted_int32_model.onnx
  • or: python convert-float16-to-float32.py path/to/float16_model.onnx path/to/converted_float32_model.onnx

Also Checkout

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.