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.

Overview

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 order of RGB and BGR. Simple Channel Converter for ONNX.

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

Downloads GitHub PyPI CodeQL

Key concept

  • Allow the user to specify the name of the input OP to change the input order.
  • All number of dimensions can be freely changed, not only 4 dimensions such as NCHW and NHWC.
  • Simply rewrite the input order of the input OP to the specified order and extrapolate Transpose after the input OP so that it does not affect the processing of subsequent OPs.
  • Allows the user to change the channel order of RGB and BGR by specifying options.

1. Setup

1-1. HostPC

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

### run
$ pip install -U onnx \
&& python3 -m pip install -U onnx_graphsurgeon --index-url https://pypi.ngc.nvidia.com \
&& pip install -U scc4onnx

1-2. Docker

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

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

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

2. CLI Usage

$ scc4onnx -h

usage:
  scc4onnx [-h]
  --input_onnx_file_path INPUT_ONNX_FILE_PATH
  --output_onnx_file_path OUTPUT_ONNX_FILE_PATH
  [--input_op_names_and_order_dims INPUT_OP_NAME ORDER_DIM]
  [--channel_change_inputs INPUT_OP_NAME DIM]
  [--non_verbose]

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

  --input_onnx_file_path INPUT_ONNX_FILE_PATH
      Input onnx file path.

  --output_onnx_file_path OUTPUT_ONNX_FILE_PATH
      Output onnx file path.

  --input_op_names_and_order_dims INPUT_OP_NAME ORDER_DIM
      Specify the name of the input_op to be dimensionally changed and the order of the
      dimensions after the change.
      The name of the input_op to be dimensionally changed can be specified multiple times.

      e.g.
      --input_op_names_and_order_dims aaa [0,3,1,2] \
      --input_op_names_and_order_dims bbb [0,2,3,1] \
      --input_op_names_and_order_dims ccc [0,3,1,2,4,5]

  --channel_change_inputs INPUT_OP_NAME DIM
      Change the channel order of RGB and BGR.
      If the original model is RGB, it is transposed to BGR.
      If the original model is BGR, it is transposed to RGB.
      It can be selectively specified from among the OP names specified
      in --input_op_names_and_order_dims.
      OP names not specified in --input_op_names_and_order_dims are ignored.
      Multiple times can be specified as many times as the number of OP names specified
      in --input_op_names_and_order_dims.
      --channel_change_inputs op_name dimension_number_representing_the_channel
      dimension_number_representing_the_channel must specify the dimension position before
      the change in input_op_names_and_order_dims.
      For example, dimension_number_representing_the_channel is 1 for NCHW and 3 for NHWC.

      e.g.
      --channel_change_inputs aaa 3 \
      --channel_change_inputs bbb 1 \
      --channel_change_inputs ccc 5

  --non_verbose
      Do not show all information logs. Only error logs are displayed.

3. In-script Usage

$ python
>>> from scc4onnx import order_conversion
>>> help(order_conversion)
Help on function order_conversion in module scc4onnx.onnx_input_order_converter:

order_conversion(
  input_op_names_and_order_dims: Union[dict, NoneType] = None,
  channel_change_inputs: Union[dict, NoneType] = None,
  input_onnx_file_path: Union[str, NoneType] = '',
  output_onnx_file_path: Union[str, NoneType] = '',
  onnx_graph: Union[onnx.onnx_ml_pb2.ModelProto, NoneType] = None,
  non_verbose: Union[bool, NoneType] = False
) -> onnx.onnx_ml_pb2.ModelProto

    Parameters
    ----------
    input_onnx_file_path: Optional[str]
        Input onnx file path.
        Either input_onnx_file_path or onnx_graph must be specified.
    
    output_onnx_file_path: Optional[str]
        Output onnx file path.
        If output_onnx_file_path is not specified, no .onnx file is output.
    
    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.
    
    input_op_names_and_order_dims: Optional[dict]
        Specify the name of the input_op to be dimensionally changed and
        the order of the dimensions after the change.
        The name of the input_op to be dimensionally changed
        can be specified multiple times.
    
        e.g.
        input_op_names_and_order_dims = {
            "input_op_name1": [0,3,1,2],
            "input_op_name2": [0,2,3,1],
            "input_op_name3": [0,3,1,2,4,5],
        }
    
    channel_change_inputs: Optional[dict]
        Change the channel order of RGB and BGR.
        If the original model is RGB, it is transposed to BGR.
        If the original model is BGR, it is transposed to RGB.
        It can be selectively specified from among the OP names
        specified in input_op_names_and_order_dims.
        OP names not specified in input_op_names_and_order_dims are ignored.
        Multiple times can be specified as many times as the number
        of OP names specified in input_op_names_and_order_dims.
        channel_change_inputs = {"op_name": dimension_number_representing_the_channel}
        dimension_number_representing_the_channel must specify
        the dimension position after the change in input_op_names_and_order_dims.
        For example, dimension_number_representing_the_channel is 1 for NCHW and 3 for NHWC.
    
        e.g.
        channel_change_inputs = {
            "aaa": 1,
            "bbb": 3,
            "ccc": 2,
        }
    
    non_verbose: Optional[bool]
        Do not show all information logs. Only error logs are displayed.
        Default: False
    
    Returns
    -------
    order_converted_graph: onnx.ModelProto
        Order converted onnx ModelProto

4. CLI Execution

$ scc4onnx \
--input_onnx_file_path crestereo_next_iter2_240x320.onnx \
--output_onnx_file_path crestereo_next_iter2_240x320_ord.onnx \
--input_op_names_and_order_dims left [0,2,3,1] \
--input_op_names_and_order_dims right [0,2,3,1] \
--channel_change_inputs left 1 \
--channel_change_inputs right 1

5. In-script Execution

from scc4onnx import order_conversion

order_converted_graph = order_conversion(
    onnx_graph=graph,
    input_op_names_and_order_dims={"left": [0,2,3,1], "right": [0,2,3,1]},
    channel_change_inputs={"left": 1, "right": 1},
    non_verbose=True,
)

6. Sample

6-1. Transpose only

image

$ scc4onnx \
--input_onnx_file_path crestereo_next_iter2_240x320.onnx \
--output_onnx_file_path crestereo_next_iter2_240x320_ord.onnx \
--input_op_names_and_order_dims left [0,2,3,1] \
--input_op_names_and_order_dims right [0,2,3,1]

image image

6-2. Transpose + RGB<->BGR

image

$ scc4onnx \
--input_onnx_file_path crestereo_next_iter2_240x320.onnx \
--output_onnx_file_path crestereo_next_iter2_240x320_ord.onnx \
--input_op_names_and_order_dims left [0,2,3,1] \
--input_op_names_and_order_dims right [0,2,3,1] \
--channel_change_inputs left 1 \
--channel_change_inputs right 1

image

6-3. RGB<->BGR only

image

$ scc4onnx \
--input_onnx_file_path crestereo_next_iter2_240x320.onnx \
--output_onnx_file_path crestereo_next_iter2_240x320_ord.onnx \
--channel_change_inputs left 1 \
--channel_change_inputs right 1

image

7. Issues

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

You might also like...
Python script for performing depth completion from sparse depth and rgb images using the msg_chn_wacv20. model in ONNX
Python script for performing depth completion from sparse depth and rgb images using the msg_chn_wacv20. model in ONNX

ONNX msg_chn_wacv20 depth completion Python script for performing depth completion from sparse depth and rgb images using the msg_chn_wacv20 model in

A Planar RGB-D SLAM which utilizes Manhattan World structure to provide optimal camera pose trajectory while also providing a sparse reconstruction containing points, lines and planes, and a dense surfel-based reconstruction.
A Planar RGB-D SLAM which utilizes Manhattan World structure to provide optimal camera pose trajectory while also providing a sparse reconstruction containing points, lines and planes, and a dense surfel-based reconstruction.

ManhattanSLAM Authors: Raza Yunus, Yanyan Li and Federico Tombari ManhattanSLAM is a real-time SLAM library for RGB-D cameras that computes the camera

Using Streamlit to host a multi-page tool with model specs and classification metrics, while also accepting user input values for prediction.

Predicitng_viability Using Streamlit to host a multi-page tool with model specs and classification metrics, while also accepting user input values for

Python project to take sound as input and output as RGB + Brightness values suitable for DMX

sound-to-light Python project to take sound as input and output as RGB + Brightness values suitable for DMX Current goals: Get one pixel working: Vary

Feed forward VQGAN-CLIP model, where the goal is to eliminate the need for optimizing the latent space of VQGAN for each input prompt
Feed forward VQGAN-CLIP model, where the goal is to eliminate the need for optimizing the latent space of VQGAN for each input prompt

Feed forward VQGAN-CLIP model, where the goal is to eliminate the need for optimizing the latent space of VQGAN for each input prompt. This is done by

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 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] 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

Releases(1.0.5)
  • 1.0.5(Sep 9, 2022)

    • Add short form parameter
      $ scc4onnx -h
      
      usage:
        scc4onnx [-h]
        -if INPUT_ONNX_FILE_PATH
        -of OUTPUT_ONNX_FILE_PATH
        [-ioo INPUT_OP_NAME ORDER_DIM]
        [-cci INPUT_OP_NAME DIM]
        [-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.
      
        -of OUTPUT_ONNX_FILE_PATH, --output_onnx_file_path OUTPUT_ONNX_FILE_PATH
            Output onnx file path.
      
        -ioo INPUT_OP_NAMES_AND_ORDER_DIMS INPUT_OP_NAMES_AND_ORDER_DIMS, --input_op_names_and_order_dims INPUT_OP_NAMES_AND_ORDER_DIMS INPUT_OP_NAMES_AND_ORDER_DIMS
            Specify the name of the input_op to be dimensionally changed and the order of the
            dimensions after the change.
            The name of the input_op to be dimensionally changed can be specified multiple times.
      
            e.g.
            --input_op_names_and_order_dims aaa [0,3,1,2] \
            --input_op_names_and_order_dims bbb [0,2,3,1] \
            --input_op_names_and_order_dims ccc [0,3,1,2,4,5]
      
        -cci CHANNEL_CHANGE_INPUTS CHANNEL_CHANGE_INPUTS, --channel_change_inputs CHANNEL_CHANGE_INPUTS CHANNEL_CHANGE_INPUTS
            Change the channel order of RGB and BGR.
            If the original model is RGB, it is transposed to BGR.
            If the original model is BGR, it is transposed to RGB.
            It can be selectively specified from among the OP names specified
            in --input_op_names_and_order_dims.
            OP names not specified in --input_op_names_and_order_dims are ignored.
            Multiple times can be specified as many times as the number of OP names specified
            in --input_op_names_and_order_dims.
            --channel_change_inputs op_name dimension_number_representing_the_channel
            dimension_number_representing_the_channel must specify the dimension position before
            the change in input_op_names_and_order_dims.
            For example, dimension_number_representing_the_channel is 1 for NCHW and 3 for NHWC.
      
            e.g.
            --channel_change_inputs aaa 3 \
            --channel_change_inputs bbb 1 \
            --channel_change_inputs ccc 5
      
        -n, --non_verbose
            Do not show all information logs. Only error logs are displayed.
      

    Full Changelog: https://github.com/PINTO0309/scc4onnx/compare/1.0.4...1.0.5

    Source code(tar.gz)
    Source code(zip)
  • 1.0.4(May 25, 2022)

  • 1.0.3(May 15, 2022)

  • 1.0.2(May 10, 2022)

  • 1.0.1(Apr 19, 2022)

  • 1.0.0(Apr 18, 2022)

Owner
Katsuya Hyodo
Hobby programmer. Intel Software Innovator Program member.
Katsuya Hyodo
ML models implementation practice

Let's implement various ML algorithms with numpy/tf Vanilla Neural Network https://towardsdatascience.com/lets-code-a-neural-network-in-plain-numpy-ae

Jinsoo Heo 4 Jul 04, 2021
This is the codebase for the ICLR 2021 paper Trajectory Prediction using Equivariant Continuous Convolution

Trajectory Prediction using Equivariant Continuous Convolution (ECCO) This is the codebase for the ICLR 2021 paper Trajectory Prediction using Equivar

Spatiotemporal Machine Learning 45 Jul 22, 2022
Galileo library for large scale graph training by JD

近年来,图计算在搜索、推荐和风控等场景中获得显著的效果,但也面临超大规模异构图训练,与现有的深度学习框架Tensorflow和PyTorch结合等难题。 Galileo(伽利略)是一个图深度学习框架,具备超大规模、易使用、易扩展、高性能、双后端等优点,旨在解决超大规模图算法在工业级场景的落地难题,提

JD Galileo Team 128 Nov 29, 2022
PyTorch implementation of Grokking: Generalization Beyond Overfitting on Small Algorithmic Datasets

Simple PyTorch Implementation of "Grokking" Implementation of Grokking: Generalization Beyond Overfitting on Small Algorithmic Datasets Usage Running

Teddy Koker 15 Sep 29, 2022
Simple tools for logging and visualizing, loading and training

TNT TNT is a library providing powerful dataloading, logging and visualization utilities for Python. It is closely integrated with PyTorch and is desi

1.5k Jan 02, 2023
HMLLDB is a collection of LLDB commands to assist in the debugging of iOS apps.

HMLLDB is a collection of LLDB commands to assist in the debugging of iOS apps. 中文介绍 Features Non-intrusive. Your iOS project does not need to be modi

mao2020 47 Oct 22, 2022
Signals-backend - A suite of card games written in Python

Card game A suite of card games written in the Python language. Features coming

1 Feb 15, 2022
Source Code for our paper: Understand me, if you refer to Aspect Knowledge: Knowledge-aware Gated Recurrent Memory Network

KaGRMN-DSG_ABSA This repository contains the PyTorch source Code for our paper: Understand me, if you refer to Aspect Knowledge: Knowledge-aware Gated

XingBowen 4 May 20, 2022
Examples of using f2py to get high-speed Fortran integrated with Python easily

f2py Examples Simple examples of using f2py to get high-speed Fortran integrated with Python easily. These examples are also useful to troubleshoot pr

Michael 35 Aug 21, 2022
THIS IS THE **OLD** PYMC PROJECT. PLEASE USE PYMC3 INSTEAD:

Introduction Version: 2.3.8 Authors: Chris Fonnesbeck Anand Patil David Huard John Salvatier Web site: https://github.com/pymc-devs/pymc Documentation

PyMC 7.2k Jan 07, 2023
This repository contains an implementation of the Permutohedral Attention Module in Pytorch

Permutohedral_attention_module This repository contains an implementation of the Permutohedral Attention Module

Samuel JOUTARD 26 Nov 27, 2022
Streamlit app demonstrating an image browser for the Udacity self-driving-car dataset with realtime object detection using YOLO.

Streamlit Demo: The Udacity Self-driving Car Image Browser This project demonstrates the Udacity self-driving-car dataset and YOLO object detection in

Streamlit 992 Jan 04, 2023
Hyperbolic Hierarchical Clustering.

Hyperbolic Hierarchical Clustering (HypHC) This code is the official PyTorch implementation of the NeurIPS 2020 paper: From Trees to Continuous Embedd

HazyResearch 154 Dec 15, 2022
Brain Tumor Detection with Tensorflow Neural Networks.

Brain-Tumor-Detection A convolutional neural network model built with Tensorflow & Keras to detect brain tumor and its different variants. Data of the

404ErrorNotFound 5 Aug 23, 2022
UMPNet: Universal Manipulation Policy Network for Articulated Objects

UMPNet: Universal Manipulation Policy Network for Articulated Objects Zhenjia Xu, Zhanpeng He, Shuran Song Columbia University Robotics and Automation

Columbia Artificial Intelligence and Robotics Lab 33 Dec 03, 2022
DC3: A Learning Method for Optimization with Hard Constraints

DC3: A learning method for optimization with hard constraints This repository is by Priya L. Donti, David Rolnick, and J. Zico Kolter and contains the

CMU Locus Lab 57 Dec 26, 2022
NHL 94 AI contests

nhl94-ai The end goals of this project is to: Train Models that play NHL 94 Support AI vs AI contests in NHL 94 Provide an improved AI opponent for NH

Mathieu Poliquin 2 Dec 06, 2021
CIFAR-10_train-test - training and testing codes for dataset CIFAR-10

CIFAR-10_train-test - training and testing codes for dataset CIFAR-10

Frederick Wang 3 Apr 26, 2022
Official repository for GCR rerank, a GCN-based reranking method for both image and video re-ID

Official repository for GCR rerank, a GCN-based reranking method for both image and video re-ID

53 Nov 22, 2022
Official implementation of Neural Bellman-Ford Networks (NeurIPS 2021)

NBFNet: Neural Bellman-Ford Networks This is the official codebase of the paper Neural Bellman-Ford Networks: A General Graph Neural Network Framework

MilaGraph 136 Dec 21, 2022