# onnx2json
Exports the ONNX file to a JSON file and JSON dict. Click here for **[json2onnx](https://github.com/PINTO0309/json2onnx)**.
https://github.com/PINTO0309/simple-onnx-processing-tools
[![PyPI - Downloads](https://img.shields.io/pypi/dm/onnx2json?color=2BAF2B&label=Downloads%EF%BC%8FInstalled)](https://pypistats.org/packages/onnx2json) ![GitHub](https://img.shields.io/github/license/PINTO0309/onnx2json?color=2BAF2B) [![PyPI](https://img.shields.io/pypi/v/onnx2json?color=2BAF2B)](https://pypi.org/project/onnx2json/)
<p align="center">
<img src="https://user-images.githubusercontent.com/33194443/170162575-4c3b9b62-a8f4-44a3-9240-856f9abdf460.png" />
</p>
## 1. Setup
### 1-1. HostPC
```bash
### 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
```python
>>> 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_json_path: Optional[str]
Output JSON file path (*.json) If not specified, no JSON 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
```bash
$ onnx2json \
--input_onnx_file_path NonMaxSuppression.onnx \
--output_json_path NonMaxSuppression.json \
--json_indent 2
```
## 5. In-script Execution
```python
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
Raw data
{
"_id": null,
"home_page": "https://github.com/PINTO0309/onnx2json",
"name": "onnx2json",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "Katsuya Hyodo",
"author_email": "rmsdh122@yahoo.co.jp",
"download_url": "https://files.pythonhosted.org/packages/29/99/4d8237cf994c1db087ad71819dc6acd421bb91a6b61e65c0fde20f0664aa/onnx2json-2.0.4.tar.gz",
"platform": "linux",
"description": "# onnx2json\nExports the ONNX file to a JSON file and JSON dict. Click here for **[json2onnx](https://github.com/PINTO0309/json2onnx)**.\n\nhttps://github.com/PINTO0309/simple-onnx-processing-tools\n\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/onnx2json?color=2BAF2B&label=Downloads%EF%BC%8FInstalled)](https://pypistats.org/packages/onnx2json) ![GitHub](https://img.shields.io/github/license/PINTO0309/onnx2json?color=2BAF2B) [![PyPI](https://img.shields.io/pypi/v/onnx2json?color=2BAF2B)](https://pypi.org/project/onnx2json/)\n\n<p align=\"center\">\n <img src=\"https://user-images.githubusercontent.com/33194443/170162575-4c3b9b62-a8f4-44a3-9240-856f9abdf460.png\" />\n</p>\n\n## 1. Setup\n\n### 1-1. HostPC\n```bash\n### option\n$ echo export PATH=\"~/.local/bin:$PATH\" >> ~/.bashrc \\\n&& source ~/.bashrc\n\n### run\n$ pip install -U onnx protobuf \\\n&& python3 -m pip install -U onnx_graphsurgeon --index-url https://pypi.ngc.nvidia.com \\\n&& pip install -U onnx2json\n```\n### 1-2. Docker\nhttps://github.com/PINTO0309/simple-onnx-processing-tools#docker\n\n## 2. CLI Usage\n```\nusage:\n onnx2json [-h]\n -if INPUT_ONNX_FILE_PATH\n -oj OUTPUT_JSON_PATH\n [-i JSON_INDENT]\n\noptional arguments:\n -h, --help\n show this help message and exit\n\n -if INPUT_ONNX_FILE_PATH, --input_onnx_file_path INPUT_ONNX_FILE_PATH\n Input ONNX model path. (*.onnx)\n\n -oj OUTPUT_JSON_PATH, --output_json_path OUTPUT_JSON_PATH\n Output JSON file path (*.json) If not specified, no JSON file is output.\n\n -i JSON_INDENT, --json_indent JSON_INDENT\n Number of indentations in JSON. (default=2)\n```\n\n## 3. In-script Usage\n```python\n>>> from onnx2json import convert\n>>> help(convert)\n\nHelp on function convert in module onnx2json.onnx2json:\n\nconvert(\n input_onnx_file_path: Union[str, NoneType] = '',\n onnx_graph: Union[onnx.onnx_ml_pb2.ModelProto, NoneType] = None,\n output_json_path: Union[str, NoneType] = '',\n json_indent: Union[int, NoneType] = 2\n)\n\n Parameters\n ----------\n input_onnx_file_path: Optional[str]\n Input onnx file path.\n Either input_onnx_file_path or onnx_graph must be specified.\n Default: ''\n\n onnx_graph: Optional[onnx.ModelProto]\n onnx.ModelProto.\n Either input_onnx_file_path or onnx_graph must be specified.\n onnx_graph If specified, ignore input_onnx_file_path and process onnx_graph.\n\n output_json_path: Optional[str]\n Output JSON file path (*.json) If not specified, no JSON file is output.\n Default: ''\n\n json_indent: Optional[int]\n Number of indentations in JSON.\n Default: 2\n\n Returns\n -------\n onnx_json: dict\n Converted JSON dict.\n```\n\n## 4. CLI Execution\n```bash\n$ onnx2json \\\n--input_onnx_file_path NonMaxSuppression.onnx \\\n--output_json_path NonMaxSuppression.json \\\n--json_indent 2\n```\n\n## 5. In-script Execution\n```python\nfrom onnx2json import convert\n\nonnx_json = convert(\n input_onnx_file_path=\"NonMaxSuppression.onnx\",\n output_json_path=\"NonMaxSuppression.json\",\n json_indent=2,\n)\n\n# or\n\nonnx_json = convert(\n onnx_graph=graph,\n)\n```\n\n## 6. Issues\nhttps://github.com/PINTO0309/simple-onnx-processing-tools/issues\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Exports the ONNX file to a JSON file or JSON dict.",
"version": "2.0.4",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4d1e01d79c5317a48a1819ed7d9f4ff5d6fa1e23b97be464ff6862213671a71c",
"md5": "f7a76ca878fd726bd11f8eda67774dd6",
"sha256": "281d86a7b4e4b8e33c1972cfbde3a3d77ef7848074907ae5a8c8b901d0b50e82"
},
"downloads": -1,
"filename": "onnx2json-2.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f7a76ca878fd726bd11f8eda67774dd6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 5011,
"upload_time": "2023-01-25T22:54:12",
"upload_time_iso_8601": "2023-01-25T22:54:12.596749Z",
"url": "https://files.pythonhosted.org/packages/4d/1e/01d79c5317a48a1819ed7d9f4ff5d6fa1e23b97be464ff6862213671a71c/onnx2json-2.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "29994d8237cf994c1db087ad71819dc6acd421bb91a6b61e65c0fde20f0664aa",
"md5": "d77a2b8ab5709fe0b244c91e67e7b9c2",
"sha256": "840d07b81bbe026644e76fb41edc4e280f5cdf8e24966342705eff479a19f2bd"
},
"downloads": -1,
"filename": "onnx2json-2.0.4.tar.gz",
"has_sig": false,
"md5_digest": "d77a2b8ab5709fe0b244c91e67e7b9c2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 4163,
"upload_time": "2023-01-25T22:54:13",
"upload_time_iso_8601": "2023-01-25T22:54:13.597412Z",
"url": "https://files.pythonhosted.org/packages/29/99/4d8237cf994c1db087ad71819dc6acd421bb91a6b61e65c0fde20f0664aa/onnx2json-2.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-25 22:54:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "PINTO0309",
"github_project": "onnx2json",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "onnx2json"
}