A very simple tool for situations where optimization with onnx-simplifier would exceed the Protocol Buffers upper file size limit of 2GB, or simply to separate onnx files to any size you want.

Overview

sne4onnx

A very simple tool for situations where optimization with onnx-simplifier would exceed the Protocol Buffers upper file size limit of 2GB, or simply to separate onnx files to any size you want. Simple Network Extraction for ONNX.

https://github.com/PINTO0309/simple-onnx-processing-tools

Downloads GitHub PyPI CodeQL

Key concept

  • If INPUT OP name and OUTPUT OP name are specified, the onnx graph within the range of the specified OP name is extracted and .onnx is generated.
  • Change backend to onnx.utils.Extractor.extract_model so that onnx.ModelProto can be specified as input.

1. Setup

1-1. HostPC

### option
$ echo export PATH="~/.local/bin:$PATH" >> ~/.bashrc \
&& source ~/.bashrc

### run
$ pip install -U onnx \
&& pip install -U sne4onnx

1-2. Docker

### docker pull
$ docker pull pinto0309/sne4onnx:latest

### docker build
$ docker build -t pinto0309/sne4onnx:latest .

### docker run
$ docker run --rm -it -v `pwd`:/workdir pinto0309/sne4onnx:latest
$ cd /workdir

2. CLI Usage

$ sne4onnx -h

usage:
    sne4onnx [-h]
    --input_onnx_file_path INPUT_ONNX_FILE_PATH
    --input_op_names INPUT_OP_NAMES
    --output_op_names OUTPUT_OP_NAMES
    [--output_onnx_file_path OUTPUT_ONNX_FILE_PATH]

optional arguments:
  -h, --help
        show this help message and exit

  --input_onnx_file_path INPUT_ONNX_FILE_PATH
        Input onnx file path.

  --input_op_names INPUT_OP_NAMES
        List of OP names to specify for the input layer of the model.
        Specify the name of the OP, separated by commas.
        e.g. --input_op_names aaa,bbb,ccc

  --output_op_names OUTPUT_OP_NAMES
        List of OP names to specify for the output layer of the model.
        Specify the name of the OP, separated by commas.
        e.g. --output_op_names ddd,eee,fff

  --output_onnx_file_path OUTPUT_ONNX_FILE_PATH
        Output onnx file path. If not specified, extracted.onnx is output.

3. In-script Usage

$ python
>>> from sne4onnx import extraction
>>> help(extraction)

Help on function extraction in module sne4onnx.onnx_network_extraction:

extraction(
    input_op_names: List[str],
    output_op_names: List[str],
    input_onnx_file_path: Union[str, NoneType] = '',
    onnx_graph: Union[onnx.onnx_ml_pb2.ModelProto, NoneType] = None,
    output_onnx_file_path: Union[str, NoneType] = ''
) -> onnx.onnx_ml_pb2.ModelProto

    Parameters
    ----------
    input_op_names: List[str]
        List of OP names to specify for the input layer of the model.
        Specify the name of the OP, separated by commas.
        e.g. ['aaa','bbb','ccc']

    output_op_names: List[str]
        List of OP names to specify for the output layer of the model.
        Specify the name of the OP, separated by commas.
        e.g. ['ddd','eee','fff']

    input_onnx_file_path: Optional[str]
        Input onnx file path.
        Either input_onnx_file_path or onnx_graph must be specified.
        onnx_graph If specified, ignore input_onnx_file_path and process onnx_graph.

    onnx_graph: Optional[onnx.ModelProto]
        onnx.ModelProto.
        Either input_onnx_file_path or onnx_graph must be specified.
        onnx_graph If specified, ignore input_onnx_file_path and process onnx_graph.

    output_onnx_file_path: Optional[str]
        Output onnx file path.
        If not specified, .onnx is not output.
        Default: ''

    Returns
    -------
    extracted_graph: onnx.ModelProto
        Extracted onnx ModelProto

4. CLI Execution

$ sne4onnx \
--input_onnx_file_path input.onnx \
--input_op_names aaa,bbb,ccc \
--output_op_names ddd,eee,fff \
--output_onnx_file_path output.onnx

5. In-script Execution

5-1. Use ONNX files

from sne4onnx import extraction

extracted_graph = extraction(
  input_op_names=['aaa', 'bbb', 'ccc'],
  output_op_names=['ddd', 'eee', 'fff'],
  input_onnx_file_path='input.onnx',
  output_onnx_file_path='output.onnx',
)

5-2. Use onnx.ModelProto

from sne4onnx import extraction

extracted_graph = extraction(
  input_op_names=['aaa', 'bbb', 'ccc'],
  output_op_names=['ddd', 'eee', 'fff'],
  onnx_graph=graph,
  output_onnx_file_path='output.onnx',
)

6. Samples

6-1. Pre-extraction

image image image

6-2. Extraction

$ sne4onnx \
--input_onnx_file_path hitnet_sf_finalpass_720x1280.onnx \
--input_op_names 0,1 \
--output_op_names 497,785 \
--output_onnx_file_path hitnet_sf_finalpass_720x960_head.onnx

6-3. Extracted

image image image

7. Reference

  1. https://github.com/onnx/onnx/blob/main/docs/PythonAPIOverview.md
  2. https://docs.nvidia.com/deeplearning/tensorrt/onnx-graphsurgeon/docs/index.html
  3. https://github.com/NVIDIA/TensorRT/tree/main/tools/onnx-graphsurgeon
  4. https://github.com/PINTO0309/snd4onnx
  5. https://github.com/PINTO0309/scs4onnx
  6. https://github.com/PINTO0309/snc4onnx
  7. https://github.com/PINTO0309/sog4onnx
  8. https://github.com/PINTO0309/PINTO_model_zoo

8. Issues

https://github.com/PINTO0309/simple-onnx-processing-tools/issues

You might also like...
Parasite: a tool allowing you to compress and decompress files, to reduce their size
Parasite: a tool allowing you to compress and decompress files, to reduce their size

🦠 Parasite 🦠 Parasite is a tool written in Python3 allowing you to "compress" any file, reducing its size. ⭐ Features ⭐ + Fast + Good optimization,

🍅🍅🍅YOLOv5-Lite: lighter, faster and easier to deploy. Evolved from yolov5 and the size of model is only 1.7M (int8) and 3.3M (fp16). It can reach 10+ FPS on the Raspberry Pi 4B when the input size is 320×320~
🍅🍅🍅YOLOv5-Lite: lighter, faster and easier to deploy. Evolved from yolov5 and the size of model is only 1.7M (int8) and 3.3M (fp16). It can reach 10+ FPS on the Raspberry Pi 4B when the input size is 320×320~

YOLOv5-Lite:lighter, faster and easier to deploy Perform a series of ablation experiments on yolov5 to make it lighter (smaller Flops, lower memory, a

ONNX Runtime Web demo is an interactive demo portal showing real use cases running ONNX Runtime Web in VueJS.

ONNX Runtime Web demo is an interactive demo portal showing real use cases running ONNX Runtime Web in VueJS. It currently supports four examples for you to quickly experience the power of ONNX Runtime Web.

A repository that shares tuning results of trained models generated by TensorFlow / Keras. Post-training quantization (Weight Quantization, Integer Quantization, Full Integer Quantization, Float16 Quantization), Quantization-aware training. TensorFlow Lite. OpenVINO. CoreML. TensorFlow.js. TF-TRT. MediaPipe. ONNX. [.tflite,.h5,.pb,saved_model,tfjs,tftrt,mlmodel,.xml/.bin, .onnx]
An executor that loads ONNX models and embeds documents using the ONNX runtime.

ONNXEncoder An executor that loads ONNX models and embeds documents using the ONNX runtime. Usage via Docker image (recommended) from jina import Flow

ONNX-GLPDepth - Python scripts for performing monocular depth estimation using the GLPDepth model in ONNX
ONNX-GLPDepth - Python scripts for performing monocular depth estimation using the GLPDepth model in ONNX

ONNX-GLPDepth - Python scripts for performing monocular depth estimation using the GLPDepth model in ONNX

ONNX-PackNet-SfM: Python scripts for performing monocular depth estimation using the PackNet-SfM model in ONNX
ONNX-PackNet-SfM: Python scripts for performing monocular depth estimation using the PackNet-SfM model in ONNX

Python scripts for performing monocular depth estimation using the PackNet-SfM model in ONNX

Keras + Hyperopt: A very simple wrapper for convenient hyperparameter optimization

This project is now archived. It's been fun working on it, but it's time for me to move on. Thank you for all the support and feedback over the last c

Music source separation is a task to separate audio recordings into individual sources

Music Source Separation Music source separation is a task to separate audio recordings into individual sources. This repository is an PyTorch implmeme

Comments
  • Significantly faster processing

    Significantly faster processing

    1. https://github.com/PINTO0309/simple-onnx-processing-tools/issues/2
    2. Eliminate comma-separated specifications for input_op_names and output_op_names
    3. Add non_verbose option
    opened by PINTO0309 0
Releases(1.0.10)
  • 1.0.10(Sep 7, 2022)

    • Add short form parameter
    $ sne4onnx -h
    
    usage:
        sne4onnx [-h]
        -if INPUT_ONNX_FILE_PATH
        -ion INPUT_OP_NAMES
        -oon OUTPUT_OP_NAMES
        [-of OUTPUT_ONNX_FILE_PATH]
        [-n]
    
    optional arguments:
      -h, --help
        show this help message and exit
    
      -if INPUT_ONNX_FILE_PATH, --input_onnx_file_path INPUT_ONNX_FILE_PATH
        Input onnx file path.
    
      -ion INPUT_OP_NAMES [INPUT_OP_NAMES ...], --input_op_names INPUT_OP_NAMES [INPUT_OP_NAMES ...]
        List of OP names to specify for the input layer of the model.
        e.g. --input_op_names aaa bbb ccc
    
      -oon OUTPUT_OP_NAMES [OUTPUT_OP_NAMES ...], --output_op_names OUTPUT_OP_NAMES [OUTPUT_OP_NAMES ...]
        List of OP names to specify for the output layer of the model.
        e.g. --output_op_names ddd eee fff
    
      -of OUTPUT_ONNX_FILE_PATH, --output_onnx_file_path OUTPUT_ONNX_FILE_PATH
        Output onnx file path. If not specified, extracted.onnx is output.
    
      -n, --non_verbose
        Do not show all information logs. Only error logs are displayed.
    
    Source code(tar.gz)
    Source code(zip)
  • 1.0.9(Jun 7, 2022)

  • 1.0.8(May 25, 2022)

  • 1.0.7(May 8, 2022)

  • 1.0.6(May 8, 2022)

    1. Fix: https://github.com/PINTO0309/simple-onnx-processing-tools/issues/2
    2. Eliminate comma-separated specifications for input_op_names and output_op_names
    3. Add non_verbose option
    Source code(tar.gz)
    Source code(zip)
  • 1.0.5(Apr 11, 2022)

  • 1.0.4(Apr 11, 2022)

  • 1.0.3(Apr 11, 2022)

  • 1.0.2(Apr 10, 2022)

  • 1.0.1(Apr 7, 2022)

  • 1.0.0(Apr 7, 2022)

Owner
Katsuya Hyodo
Hobby programmer. Intel Software Innovator Program member.
Katsuya Hyodo
A very tiny, very simple, and very secure file encryption tool.

Picocrypt is a very tiny (hence "Pico"), very simple, yet very secure file encryption tool. It uses the modern ChaCha20-Poly1305 cipher suite as well

Evan Su 1k Dec 30, 2022
YOLTv5 rapidly detects objects in arbitrarily large aerial or satellite images that far exceed the ~600×600 pixel size typically ingested by deep learning object detection frameworks

YOLTv5 rapidly detects objects in arbitrarily large aerial or satellite images that far exceed the ~600×600 pixel size typically ingested by deep learning object detection frameworks.

Adam Van Etten 145 Jan 1, 2023
A very simple tool to rewrite parameters such as attributes and constants for OPs in ONNX models. Simple Attribute and Constant Modifier for ONNX.

sam4onnx A very simple tool to rewrite parameters such as attributes and constants for OPs in ONNX models. Simple Attribute and Constant Modifier for

Katsuya Hyodo 6 May 15, 2022
Very simple NCHW and NHWC conversion tool for ONNX. Change to the specified input order for each and every input OP. Also, change the channel order of RGB and BGR. Simple Channel Converter for ONNX.

scc4onnx Very simple NCHW and NHWC conversion tool for ONNX. Change to the specified input order for each and every input OP. Also, change the channel

Katsuya Hyodo 16 Dec 22, 2022
Simple tool to combine(merge) onnx models. Simple Network Combine Tool for ONNX.

snc4onnx Simple tool to combine(merge) onnx models. Simple Network Combine Tool for ONNX. https://github.com/PINTO0309/simple-onnx-processing-tools 1.

Katsuya Hyodo 8 Oct 13, 2022
Technical Indicators implemented in Python only using Numpy-Pandas as Magic - Very Very Fast! Very tiny! Stock Market Financial Technical Analysis Python library . Quant Trading automation or cryptocoin exchange

MyTT Technical Indicators implemented in Python only using Numpy-Pandas as Magic - Very Very Fast! to Stock Market Financial Technical Analysis Python

dev 34 Dec 27, 2022
This program generates a random 12 digit/character password (upper and lowercase) and stores it in a file along with your username and app/website.

PasswordGeneratorAndVault This program generates a random 12 digit/character password (upper and lowercase) and stores it in a file along with your us

Chris 1 Feb 26, 2022
arxiv-sanity, but very lite, simply providing the core value proposition of the ability to tag arxiv papers of interest and have the program recommend similar papers.

arxiv-sanity, but very lite, simply providing the core value proposition of the ability to tag arxiv papers of interest and have the program recommend similar papers.

Andrej 671 Dec 31, 2022
Simple ONNX operation generator. Simple Operation Generator for ONNX.

sog4onnx Simple ONNX operation generator. Simple Operation Generator for ONNX. https://github.com/PINTO0309/simple-onnx-processing-tools Key concept V

Katsuya Hyodo 6 May 15, 2022
Have you ever wondered how cool it would be to have your own A.I

Have you ever wondered how cool it would be to have your own A.I. assistant Imagine how easier it would be to send emails without typing a single word, doing Wikipedia searches without opening web browsers, and performing many other daily tasks like playing music with the help of a single voice command.

Harsh Gupta 1 Nov 9, 2021