主要是给sca200的板子修改模型用,由于转成onnx后还有一些编译器不认识的层,需要手动改
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
ZhangGe6 02d5b20440 get schema in view.js#activeGraph 4 years ago
docs get schema in view.js#activeGraph 4 years ago
static get schema in view.js#activeGraph 4 years ago
templates change the logo and links in the index page 4 years ago
.gitignore update readme 4 years ago
LICENSE update readme 4 years ago
app.py add sample models in the readme 4 years ago
onnx_modifier.py the dropdown menu of adding new node is basically done 4 years ago
readme.md the dropdown menu of adding new node is basically done 4 years ago
readme_zh-CN.md fix external data loading error for unix platform issue#https://github.com/ZhangGe6/onnx-modifier/issues/1 4 years ago

readme.md

English | 简体中文

Introduction

To edit an ONNX model, One common way is to visualize the model graph, and edit it using ONNX Python API. This works fine. However, we have to code to edit, then visualize to check. The two processes may iterate for many times, which is time-consuming. 👋

What if we have a tool, which allow us to edit and preview the editing effect in a totally visualization fashion?

Then onnx-modifier comes. With it, we can focus on editing the model graph in the visualization pannel. All the editing information will be summarized and processed by Python ONNX API automatically at last. Then our time can be saved! 🚀

onnx-modifier is built based on the popular network viewer Netron and the lightweight web application framework flask.

Currently, the following editing operations are supported:

  • Delete a single node.
  • Delete a node and all the nodes rooted on it.
  • Recover a deleted node.
  • Rename the input/output name of a node.

Hope it helps!

Get started

Clone the repo and install the required Python packages by

git clone git@github.com:ZhangGe6/onnx-modifier.git
cd onnx-modifier

pip install onnx
pip install flask

Then run

python app.py

Click the url in the output info generated by flask (http://127.0.0.1:5000/ for example), then onnx-modifier will be launched in the web browser.

Click Open Model... to upload the ONNX model to edit. The model will be parsed and shown on the page.

Edit

top left buttons (Graph-level-operations) sidebar buttons (Node-level-operations)

Graph-level-operation elements are placed on the left-top of the page. Currently, there are three buttons: PreviewReset and Download. They can do:

  • Preview: Preview the result model graph with all current modifications applied;
  • Reset: Reset the model graph to its initial state;
  • Download: Save the modified model into disk.

Node-level-operation elements are all in the sidebar, which can be invoked by clicking a specific node. Let's take a closer look.

Delete node

There are two modes for deleting node: Delete With Children and Delete Single Node. Delete Single Node only deletes the clicked node, while Delete With Children also deletes all the node rooted on the clicked node, which is convenient and natural if we want to delete a long path of nodes.

The implementation of Delete With Children is based on the backtracking algorithm.

The deleted nodes are in grey mode. The following figure shows a typical deleting process.

Recover node

By Recover Node button, we can recover the node back to graph after deleting it.

Change the input/output name of node

By changing the input/output name of nodes, we can change the model forward routine. It can also be helpful if we want to rename the model output(s).

How can we do this using onnx-modifier? Note that there is a RENAME HELPER section in the node sidebar. All the original input/output names of a node (except weight parameters) are listed here, each following with a input field, where we can input the new name. After clicking the Preview button, the graph will be rendered with the new name.

For example, Now we want remove the preprocess operators (Sub->Mul->Sub->Transpose) shown in the following figure. We can

  1. click on the 1st Conv node, rename its input as serving_default_input:0.
  2. click Preview, we can see that the model input has linked to the 1st Convdirectly. And the preprocess operators have been split from the main routine. Then delete them.
  3. we are done! click Preview to have a check (click Download, then we can get the modified ONNX model).
rename_node_io

Sample models

For quick testing, some typical sample models are provided as following. Most of them are from onnx model zoo

onnx-modifier is under active development 🛠️. Welcome to use, create issues and pull requests! 🥰

Credits and referred materials