Skip to main content

Exports the ONNX file to a JSON file or JSON dict.

Project description

onnx2json

Exports the ONNX file to a JSON file and JSON dict. Click here for json2onnx.

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

PyPI - Downloads GitHub PyPI

1. Setup

1-1. HostPC

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

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

1-2. Docker

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

2. CLI Usage

usage:
  onnx2json [-h]
  -if INPUT_ONNX_FILE_PATH
  -oj OUTPUT_JSON_PATH
  [-i JSON_INDENT]

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 model path. (*.onnx)

  -oj OUTPUT_JSON_PATH, --output_json_path OUTPUT_JSON_PATH
      Output JSON file path (*.json) If not specified, no JSON file is output.

  -i JSON_INDENT, --json_indent JSON_INDENT
      Number of indentations in JSON. (default=2)

3. In-script Usage

>>> from onnx2json import convert
>>> help(convert)

Help on function convert in module onnx2json.onnx2json:

convert(
  input_onnx_file_path: Union[str, NoneType] = '',
  onnx_graph: Union[onnx.onnx_ml_pb2.ModelProto, NoneType] = None,
  output_json_path: Union[str, NoneType] = '',
  json_indent: Union[int, NoneType] = 2
)

    Parameters
    ----------
    input_onnx_file_path: Optional[str]
        Input onnx file path.
        Either input_onnx_file_path or onnx_graph must be specified.
        Default: ''

    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, no ONNX file is output.
        Default: ''

    json_indent: Optional[int]
        Number of indentations in JSON.
        Default: 2

    Returns
    -------
    onnx_json: dict
        Converted JSON dict.

4. CLI Execution

$ onnx2json \
--input_onnx_file_path NonMaxSuppression.onnx \
--output_json_path NonMaxSuppression.json \
--json_indent 2

5. In-script Execution

from onnx2json import convert

onnx_json = convert(
  input_onnx_file_path="NonMaxSuppression.onnx",
  output_json_path="NonMaxSuppression.json",
  json_indent=2,
)

# or

onnx_json = convert(
  onnx_graph=graph,
)

6. Issues

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

onnx2json-2.0.3.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

onnx2json-2.0.3-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file onnx2json-2.0.3.tar.gz.

File metadata

  • Download URL: onnx2json-2.0.3.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for onnx2json-2.0.3.tar.gz
Algorithm Hash digest
SHA256 4d15f2982826cc0c88bc6542407aac409653d7390a2aeb84015842e1922a2719
MD5 ccbe75b09450b3c096aba4e7fa3e0b3f
BLAKE2b-256 0fec547dcb7f9ef3c8c8264e5216b8a7658ef8c20c916d62aac6efbd5de36bc3

See more details on using hashes here.

File details

Details for the file onnx2json-2.0.3-py3-none-any.whl.

File metadata

  • Download URL: onnx2json-2.0.3-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for onnx2json-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bedc75e0b7126e39c1dc6a5fcf4a38454026d58ad8c0a117cb9cee32a72d23e9
MD5 f34ac984fa70301890d2a99f6f3a1b45
BLAKE2b-256 c3a0996bdc829bcfeba67033fc917c45146e5249024607cca6c20ff6334a425c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page