Skip to main content

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

Project description


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

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 \
&& pip install -U onnx2json

1-2. Docker

2. CLI Usage

  onnx2json [-h]
  --input_onnx_file_path INPUT_ONNX_FILE_PATH
  --output_json_path OUTPUT_JSON_PATH
  [--json_indent JSON_INDENT]

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

  --input_onnx_file_path INPUT_ONNX_FILE_PATH
      Input ONNX model path. (*.onnx)

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

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

  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

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

    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(

# or

onnx_json = convert(

6. 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.2.tar.gz (4.1 kB view hashes)

Uploaded source

Built Distribution

onnx2json-2.0.2-py3-none-any.whl (5.0 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page