From f92e5253a44cf1c80dad28589b24e4f0523c45a8 Mon Sep 17 00:00:00 2001 From: Feng Date: Mon, 20 Jun 2022 09:42:00 +0200 Subject: [PATCH 1/3] add docker container --- app.py | 16 ++++++++++------ readme.md | 27 ++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/app.py b/app.py index 04070b7..5155784 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python3.8 + + from flask import Flask, render_template, request from onnx_modifier import onnxModifier app = Flask(__name__) @@ -10,10 +13,10 @@ def index(): def open_model(): # https://blog.miguelgrinberg.com/post/handling-file-uploads-with-flask onnx_file = request.files['file'] - + global onnx_modifier onnx_modifier = onnxModifier.from_name_stream(onnx_file.filename, onnx_file.stream) - + return 'OK', 200 @@ -21,13 +24,14 @@ def open_model(): def modify_and_download_model(): modify_info = request.get_json() # print(modify_info) - + onnx_modifier.reload() # allow downloading for multiple times - + onnx_modifier.modify(modify_info) onnx_modifier.check_and_save_model() - + return 'OK', 200 if __name__ == '__main__': - app.run() \ No newline at end of file + app.debug = True + app.run(host="0.0.0.0") diff --git a/readme.md b/readme.md index 2a1fc3e..118d444 100644 --- a/readme.md +++ b/readme.md @@ -37,8 +37,7 @@ 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 +pip install onnx onnxruntime flask ``` Then run @@ -58,16 +57,34 @@ Click the url in the output info generated by flask (`http://127.0.0.1:5000/` fo Click `Open Model...` to upload the ONNX model to edit. The model will be parsed and shown on the page. +## launch from a docker container + +We create a docker container like this: + +```bash +docker build --file Dockerfile . -t onnx-modifier +``` + +After building the container, we run onnx-modifier from it by mapping docker port 5000 to host port 5000 + +```bash +docker run -d -t --name onnx-modifier -p 5000:5000 onnx-modifier +``` + +Then we have access to onnx-modifer from URL . + + + # Usage Graph-level-operation elements are placed on the left-top of the page. Currently, there are four buttons: `Refresh`, `Reset`, `Download` and `Add node`. They can do: - `Refresh`: Refresh the model graph to preview editing effects. - + > In this version, the model graph is refreshed automatically as soon as an editing operation is invoked. So this button can be used much fewer than earlier versions. - `Reset`: Reset the whole model graph to its initial state; - `Download`: Save the modified model into disk. - `Add node`: Add a new node into the model. -Node-level-operation elements are all in the sidebar, which can be invoked by clicking a specific node. +Node-level-operation elements are all in the sidebar, which can be invoked by clicking a specific node. Let's take a closer look. @@ -109,7 +126,7 @@ Change the original attribute to a new value, then we are done. ## Add new node -Sometimes we want to add new nodes into the existed model. `onnx-modifier` supports this feature experimentally now. +Sometimes we want to add new nodes into the existed model. `onnx-modifier` supports this feature experimentally now. Note there is an `Add node` button, following with a selector elements on the top-left of the index page. To do this, what we need to do is as easy as 3 steps: From c5d4d8f28aac9bd91d4c18ec5a5419e7e9ec3ccb Mon Sep 17 00:00:00 2001 From: Feng Date: Mon, 20 Jun 2022 09:42:06 +0200 Subject: [PATCH 2/3] add docker container --- Dockerfile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5e33bbc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.8 +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get clean && apt-get update -y && apt-get upgrade -y && pip install --upgrade pip + +RUN pip3 install -U onnx flask onnxruntime + +COPY ./static /static +COPY ./templates /templates +COPY ./utils /utils +COPY ./*.py / +RUN chmod +x /app.py + +CMD ["/bin/bash", "-c", "/app.py"] + From dfcfc624ab2620e7214ee0e5ae05cbe3bf07b14b Mon Sep 17 00:00:00 2001 From: Feng Date: Mon, 20 Jun 2022 17:10:09 +0200 Subject: [PATCH 3/3] fetch modified models from mounted folder, as is explained in readme. --- readme.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 118d444..777675f 100644 --- a/readme.md +++ b/readme.md @@ -62,17 +62,24 @@ Click `Open Model...` to upload the ONNX model to edit. The model will be parsed We create a docker container like this: ```bash +git clone git@github.com:ZhangGe6/onnx-modifier.git +cd onnx-modifier docker build --file Dockerfile . -t onnx-modifier ``` -After building the container, we run onnx-modifier from it by mapping docker port 5000 to host port 5000 +After building the container, we run onnx-modifier by mapping docker port and a local folder `modified_onnx` ```bash -docker run -d -t --name onnx-modifier -p 5000:5000 onnx-modifier +mkdir -p modified_onnx +docker run -d -t \ + --name onnx-modifier \ + -u $(id -u ${USER}):$(id -g ${USER}) \ + -v $(pwd)/modified_onnx:/modified_onnx \ + -p 5000:5000 \ + onnx-modifier ``` -Then we have access to onnx-modifer from URL . - +Then we have access to onnx-modifer from URL . The modified ONNX models are expected to be found inside the local folder `modified_onnx`. # Usage