A tool to modify onnx models in a visualization fashion, based on Netron and flask.

Overview

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 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 require Python packages by

git clone [email protected]: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 nature 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

[https://github.com/onnx/models/blob/main/vision/classification/mobilenet/model/mobilenetv2-7.onnx]:

Comments
  • 无法成功插入slice节点,希望增加修改输入通道数的功能

    无法成功插入slice节点,希望增加修改输入通道数的功能

    作者你好,我的情况是这样的,我的模型是在灰度图上训练的,所以输入的通道数只有1,现在我要把输入的通道数变成3,这样才能享受TNN的加速,但我又不想重新制作数据集和训练,所以我想到的是:第一步,修改输入的通道数从1变成3,即[1,1,192,192]变成[1,3,192,192];第二步,在输入后面插入一个slice算子,只选取三个通道中的第一个通道。这样我就不用重新训练模型了。 现在我跳过第一步,先尝试第二步插入slice 算子,但遇到了以下问题: 我已经修改了slice的输入和输出 image 也修改了第一个卷积的输入 image 可slice算子还是无法成功地与第一个卷积连接。 我使用的onnx模型是:model.zip

    opened by wwdok 7
  • new output after Conv layer

    new output after Conv layer

    Is it possible to add new "out_put layer", for instance, output after a convolution layer. Sometimes, we might want to check feature maps from the convolution layer as for image recognition.

    I'd like to get such output. I found such way for Pytorch and Keras/Tensorflow. I'd like to do the same thing using onnx model in onnxRT by cutting(?) and modifing the onnx model.

    I can not find tutorial of it. If there exists such exsamples, please teach me.

    opened by tomoporo 7
  • 修改batchSize实际上不起作用

    修改batchSize实际上不起作用

    场景描述:将原来onnx模型batch_size改为1(即输入尺寸由[batch_size, 3, 224, 224]改为[1, 3,224,224]),nerton可视化结果符合预期,但在解析modified onnx模型时通过onnx::ValueInfoProto获取输入尺寸,如tensorInfo.shape().dim(i).dim_value(),结果和batch_size相同,均为[0,3,224,224], 模型为开源mobilenet onnx

    可视化 原始模型 image

    修改batch_size=1后模型 image

    opened by XiaotaoChen 5
  • Add a Cast node and modify to attribute but keep roll back to NaN

    Add a Cast node and modify to attribute but keep roll back to NaN

    I create a Cast node. to attribute is undefined initially. I change to float32, float, Float, Float32, FLOAT, ... etc. No matter what I put, it show NaN later

    I change to 1 and it shows float32 later I thought I make it. but when I load new model with netron, it say unknown type "1"

    Really don't know how to add Cast properly

    opened by jjdd88 4
  • onnx flask有版本限制吗?

    onnx flask有版本限制吗?

    执行

    python3.8 app.py
    

    得到输出:

     * Serving Flask app 'app' (lazy loading)
     * Environment: production
       WARNING: This is a development server. Do not use it in a production deployment.
       Use a production WSGI server instead.
     * Debug mode: off
     * Running on http://127.0.0.1:5000 (Press CTRL+C to quit)
    127.0.0.1 - - [09/May/2022 16:22:44] "GET / HTTP/1.1" 200 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/view-grapher.css HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/view-sidebar.css HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/sweetalert.css HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/sweetalert.min.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/dagre.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/base.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/text.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/json.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/xml.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/python.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/protobuf.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/flatbuffers.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/zip.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/gzip.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/tar.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/view-grapher.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/view-sidebar.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/view.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/index.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:44] "GET /static/logo.svg HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:45] "GET /favicon.ico HTTP/1.1" 404 -
    127.0.0.1 - - [09/May/2022 16:22:50] "GET /static/onnx.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:50] "GET /static/onnx-proto.js HTTP/1.1" 304 -
    127.0.0.1 - - [09/May/2022 16:22:51] "GET /static/onnx-metadata.json HTTP/1.1" 304 -
    [2022-05-09 16:22:51,596] ERROR in app: Exception on /open_model [POST]
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2077, in wsgi_app
        response = self.full_dispatch_request()
      File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1525, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1523, in full_dispatch_request
        rv = self.dispatch_request()
      File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1509, in dispatch_request
        return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
      File "app.py", line 15, in open_model
        onnx_modifier = onnxModifier.from_name_stream(onnx_file.filename, onnx_file.stream)
      File "/Users/dengxuezheng/BeKe/tf/onnx/onnx-modifier/onnx_modifier.py", line 26, in from_name_stream
        model_proto = onnx.load_model(stream, onnx.ModelProto)
      File "/Users/dengxuezheng/Library/Python/3.8/lib/python/site-packages/onnx/__init__.py", line 124, in load_model
        model_filepath = _get_file_path(f)
      File "/Users/dengxuezheng/Library/Python/3.8/lib/python/site-packages/onnx/__init__.py", line 54, in _get_file_path
        return os.path.abspath(f.name)
      File "/usr/local/Cellar/[email protected]/3.8.13_1/Frameworks/Python.framework/Versions/3.8/lib/python3.8/posixpath.py", line 374, in abspath
        path = os.fspath(path)
    TypeError: expected str, bytes or os.PathLike object, not int
    127.0.0.1 - - [09/May/2022 16:22:51] "POST /open_model HTTP/1.1" 500 -
    [2022-05-09 16:24:02,033] ERROR in app: Exception on /download [POST]
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2077, in wsgi_app
        response = self.full_dispatch_request()
      File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1525, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1523, in full_dispatch_request
        rv = self.dispatch_request()
      File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1509, in dispatch_request
        return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
      File "app.py", line 26, in modify_and_download_model
        onnx_modifier.reload()   # allow for downloading for multiple times
    NameError: name 'onnx_modifier' is not defined
    127.0.0.1 - - [09/May/2022 16:24:02] "POST /download HTTP/1.1" 500 -
    

    执行python3.8 app.py 出错,大神帮忙看看

    opened by wikipedia2008 4
  • Any other examples to add nodes, like add a multi-dimension constant?

    Any other examples to add nodes, like add a multi-dimension constant?

    Any other examples to add nodes, like add a multi-dimension constant?

    like input is [1,3,480,640] and the constant [1,3,1,1] (100,100,100) and we want to broadcast add them ?

    Thank you!

    opened by ganyz 3
  • how to delete constant nodes in onnx?

    how to delete constant nodes in onnx?

    As shown in pictures below, when open an onnx modified by onnx-modifier with netron, constant nodes are found. How could I delete these constant nodes with onnx-modifier?

    constant_nodes

    Sincerely, wish for reply!!

    opened by SStarver 3
  • How to prohibit auto-translation to chinese!

    How to prohibit auto-translation to chinese!

    Hi,there I've encountered a problem that once I open the app on windows, everything would be ugly translated into chinese. How could I prevent this from happening?

    problem

    Installation by method 2: "launch from executable file"

    Wish for solutions!

    opened by SStarver 2
  • 删除子分支后,分支上的节点变成了inputs。

    删除子分支后,分支上的节点变成了inputs。

    1,原始模型删除子分支,如下图: screenshot_24

    2,保存后打开修剪过的模型,可以看到inputs变多了,如下图: screenshot_25

    3,我是通过如下代码对模型的inputs进行了删除:

    import onnx                         
    
    inputpath = "./descriptor.onnx"
    
    # 1,修改模型
    model = onnx.load(inputpath)
    inputs = model.graph.input
    inputs_num = 1  # 原始网络的输入会排在列表的最前面,所以调用pop函数删除冗余输入
    for i in range(len(inputs)-inputs_num):
        inputs.pop()
    print(inputs)
    
    # 2,检查结构并保存模型(覆盖保存)
    onnx.checker.check_model(model)
    onnx.save(model, inputpath)
    
    opened by ganleiboy 2
  • Unable to download model after changes

    Unable to download model after changes

    @ZhangGe6 This tool is exactly what I was looking for but unfortunately, after I make my changes on the development server I get the error that on line 27 of app.py, that onnx_modifier is not defined.

    Traceback (most recent call last):
      File "/home/travis/p38_venv/lib/python3.8/site-packages/flask/app.py", line 2091, in __call__
        return self.wsgi_app(environ, start_response)
      File "/home/travis/p38_venv/lib/python3.8/site-packages/flask/app.py", line 2076, in wsgi_app
        response = self.handle_exception(e)
      File "/home/travis/p38_venv/lib/python3.8/site-packages/flask/app.py", line 2073, in wsgi_app
        response = self.full_dispatch_request()
      File "/home/travis/p38_venv/lib/python3.8/site-packages/flask/app.py", line 1519, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "/home/travis/p38_venv/lib/python3.8/site-packages/flask/app.py", line 1517, in full_dispatch_request
        rv = self.dispatch_request()
      File "/home/travis/p38_venv/lib/python3.8/site-packages/flask/app.py", line 1503, in dispatch_request
        return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
      File "/home/travis/memryx_dev/onnx-modifier/app.py", line 27, in modify_and_download_model
        onnx_modifier.reload()   # allow downloading for multiple times
    NameError: name 'onnx_modifier' is not defined
    
    opened by TravisHaran 2
  • Graph modified but output is not giving

    Graph modified but output is not giving

    Hi @ZhangGe6 First of all thanks for this wonderful tool. Actually i modified my graph using this tool and when i am viewing in netron it is proper but the node which i added is giving no output means i can't see what shape it output or what type it outputs it just showing the output name as text. can you please help me to fix this?

    Thanks in Advance:)

    opened by rajan780 1
Owner
Zhang Ge
Zhang Ge
Based on the web application system framework developed by flask and layui

Based on the web application system framework developed by flask and layui, the project integrates the workflow engine and has built-in functions such as organization authority management, which can be applied to the development of OA, HR, CRM, PM and other systems.

Qian Chen 43 Nov 25, 2022
Use real-time computing technology and web technology to build a big data Kanban l to solve the problem. Among them, practical technologies include MySQL, Kafka, Flink, Redis, Flask and Echarts

实时计算(English Version) 运用实时计算技术、Web 技术构建一个大数据看板来解决问题。其中实用技术包括Mysql、Kafka、Flink、Redis、Flask和Echarts 目录 1.问题需求 2.方案分析 3.安装环境 4.环境启动命令和运行代码的方法 5.代码目录结构说明

Serendipity 2 Jan 8, 2022
The app's backend is written in Python (Flask) and for search it uses Elasticsearch. I used this app as candidate application for learning out how to build, run and deploy a multi-container environment (docker-compose).

foodtrucks-app-docker-compose The app's backend is written in Python (Flask) and for search it uses Elasticsearch. I used this app as candidate applic

Selçuk Şan 3 Oct 24, 2022
a website to manage queue with FLASK-PYTHON

wc-queue-with-flask Hello I just needed to organize wc-queue when we go to family trips and made a website with Flask library (for making sample websi

Shayan Salehe 3 Jul 10, 2022
Visualize, modify, and build your database with dbSpy! An open-source data modeling tool to facilitate relational database development.

Visualize, modify, and build your database with dbSpy! dbSpy is an open-source data modeling tool to facilitate relational database development. Key F

OSLabs 115 Dec 22, 2022
This project will be a basic website that allows users to add/remove books from a list. The main objective is to understand how to use JavaScript objects and arrays and dynamically modify the DOM and add basic events.

Awesome-books Awesome Books This project will be a basic website that allows users to add/remove books from a list. This project is part of the Microv

Aleksandra Ujvari 10 Oct 3, 2022
A simple to do list webpage where you can log the daily tasks you have to do, mark them as checked, modify them, reorder them and remove them. Made using HTML, CSS and JavaScript.

To-Do-List This Webpage is for an app called To-Do-List which helps you add, remove or check tasks you have to do. It is a simple web page which conta

Zeeshan Haider 9 Mar 12, 2022
Codism is a Codepen inspired coding playgound that lets you add and modify HTML, CSS and JavaScript

Codism Codism is a Codepen inspired coding playgound that lets you add and modify HTML, CSS and JavaScript to create in order to create cool stuff! Yo

Muhammad Hasnain 5 Nov 24, 2022
An event-driven architecture wrapper for Wechaty that applies the CQS principle by using separate Query and Command messages to retrieve and modify the bot state, respectively.

CQRS Wechaty An event-driven architecture wrapper for Wechaty that applies the CQS principle by using separate Query and Command messages to retrieve

Wechaty 3 Mar 23, 2022
A web-based 3D visualization tool for 3D computer vision.

Wis3D: A web-based 3D visualization tool for 3D computer vision Online Demo | Installation | Tutorial | Documentation Wis3D is a web-based 3D visualiz

ZJU3DV 131 Dec 27, 2022
A simple task manager that allows that allows users to add, remove and modify tasks from a list.

TO-DO LIST TO-DO LIST is a basic app that allows users to add/remove task from a to-do list. Built With HTML, CSS, JavaScript, Live Demo Live Demo Lin

Shingirai Bhengesa 3 May 3, 2022
To Do list is a small but useful project to make list app , you can add tasks delete tasks and modify tasks, the project built using HTML, CSS, JavaScript

Project Name The To-Do-List app description this is a project in the second week of the second module in microverse. its a useful to do list that save

Alzubair Alqaraghuli 5 Jul 25, 2022
✏️ A small jQuery extension to turn a static HTML table into an editable one. For quickly populating a small table with JSON data, letting the user modify it with validation, and then getting JSON data back out.

jquery-editable-table A small jQuery extension to turn an HTML table editable for fast data entry and validation Demo ?? https://jsfiddle.net/torrobin

Tor 7 Jul 31, 2022
This is a basic app that allows user add/remove books from a list of books. It was created by using JavaScript arrays and objects to dynamically modify the DOM.

Awesome-Books This application lets you compile a dynamic collection of books using JavaScript. It is a single page app. You enter your book title & a

Jules Edozie 7 Oct 24, 2022
Modify Request & Response Headers Chrome Extension (Manifest V3)

Modify request & response headers (Chrome Extension Manifest V3) This Chrome extension will add request header and response header to few network requ

Requestly 6 Dec 9, 2022
🧙 Mage is an open-source data management platform that helps you clean data and prepare it for training AI/ML models.

Intro Mage is an open-source data management platform that helps you clean data and prepare it for training AI/ML models. What does this do? The curre

Mage 2.5k Jan 4, 2023
A regular table library, for async and virtual data models.

A Javascript library for the browser, regular-table exports a custom element named <regular-table>, which renders a regular HTML <table> to a sticky p

J.P. Morgan Chase & Co. 285 Dec 16, 2022
Fnon is a client-side JavaScript library for models, loading indicators, notifications, and alerts which makes your web projects much better.

???????? Fnon is the name of my late mother, It's an Arabic word which means Art, I created this library in honor of her name. Fnon is a client-side J

Adel N Al-Awdy 5 Sep 11, 2022