{"id":15700754,"url":"https://github.com/pinto0309/sed4onnx","last_synced_at":"2025-06-12T06:41:30.391Z","repository":{"id":57679622,"uuid":"492417060","full_name":"PINTO0309/sed4onnx","owner":"PINTO0309","description":"Simple ONNX constant encoder/decoder. Since the constant values in the JSON files generated by onnx2json are Base64-encoded values, ASCII \u003c-\u003e Base64 conversion is required when rewriting JSON constant values.","archived":false,"fork":false,"pushed_at":"2022-12-30T15:58:56.000Z","size":28,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-15T11:47:12.189Z","etag":null,"topics":["json","model-converter","models","onnx","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PINTO0309.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-15T07:26:25.000Z","updated_at":"2024-01-04T17:08:34.000Z","dependencies_parsed_at":"2023-01-31T12:00:58.533Z","dependency_job_id":null,"html_url":"https://github.com/PINTO0309/sed4onnx","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsed4onnx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsed4onnx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsed4onnx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsed4onnx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PINTO0309","download_url":"https://codeload.github.com/PINTO0309/sed4onnx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253766904,"owners_count":21961017,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","model-converter","models","onnx","python"],"created_at":"2024-10-03T19:53:29.635Z","updated_at":"2025-05-12T15:39:16.255Z","avatar_url":"https://github.com/PINTO0309.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sed4onnx\nSimple ONNX constant encoder/decoder.\n\nhttps://github.com/PINTO0309/simple-onnx-processing-tools\n\n[![Downloads](https://static.pepy.tech/personalized-badge/sed4onnx?period=total\u0026units=none\u0026left_color=grey\u0026right_color=brightgreen\u0026left_text=Downloads)](https://pepy.tech/project/sed4onnx) ![GitHub](https://img.shields.io/github/license/PINTO0309/sed4onnx?color=2BAF2B) [![PyPI](https://img.shields.io/pypi/v/sed4onnx?color=2BAF2B)](https://pypi.org/project/sed4onnx/) [![CodeQL](https://github.com/PINTO0309/sed4onnx/workflows/CodeQL/badge.svg)](https://github.com/PINTO0309/sed4onnx/actions?query=workflow%3ACodeQL)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/33194443/170163328-b680be10-7f98-4a61-8d49-e28423046297.png\" /\u003e\n\u003c/p\u003e\n\n## Key concept\n- Since the constant values in the JSON files generated by **[onnx2json](https://github.com/PINTO0309/onnx2json)** are Base64-encoded values, ASCII \u003c-\u003e Base64 conversion is required when rewriting JSON constant values.\n- After writing the converted Base64 strings to JSON using this tool, **[json2onnx](https://github.com/PINTO0309/json2onnx)** can be used to regenerate the constant-modified ONNX file.\n\n## 1. Setup\n### 1-1. HostPC\n```bash\n### option\n$ echo export PATH=\"~/.local/bin:$PATH\" \u003e\u003e ~/.bashrc \\\n\u0026\u0026 source ~/.bashrc\n\n### run\n$ pip install -U sed4onnx\n```\n### 1-2. Docker\nhttps://github.com/PINTO0309/simple-onnx-processing-tools#docker\n\n\n## 2. CLI Usage\n```\n$ sed4onnx -h\n\nusage:\n    sed4onnx [-h]\n    -cs CONSTANT_STRING\n    [-d {float16,float32,float64,uint8,int8,int16,int32,int64,string}]\n    [-m {encode,decode}]\n\noptional arguments:\n  -h, --help\n        show this help message and exit.\n\n  -cs CONSTANT_STRING, --constant_string CONSTANT_STRING\n        Strings to be encoded and decoded for ONNX constants.\n\n  -d {float16,float32,float64,uint8,int8,int16,int32,int64,string}, \\\n    --dtype {float16,float32,float64,uint8,int8,int16,int32,int64,string}\n        Data type.\n\n  -m {encode,decode}, --mode {encode,decode}\n        encode: Converts the string specified in constant_string to a Base64 format string\n                that can be embedded in ONNX constants.\n        decode: Converts a Base64 string specified in constant_string to ASCII like\n                Numpy string or pure string.\n```\n\n## 3. In-script Usage\n```python\n\u003e\u003e\u003e from sed4onnx import encode\n\u003e\u003e\u003e from sed4onnx import decode\n\u003e\u003e\u003e help(encode)\n\nHelp on function encode in module sed4onnx.onnx_constant_encoder_decoder:\n\nencode(constant_string: str) -\u003e str\n\n    Parameters\n    ----------\n    constant_string: str\n        ASCII string to be encoded.\n\n    dtype: str\n        'float16' or 'float32' or 'float64' or 'uint8'\n        or 'int8' or 'int16' or 'int32' or 'int64' or 'string'\n\n    Returns\n    -------\n    encoded_string: str\n        Base64-encoded ASCII string.\n\n\n\u003e\u003e\u003e help(decode)\nHelp on function decode in module sed4onnx.onnx_constant_encoder_decoder:\n\ndecode(constant_string: str, dtype: str) -\u003e numpy.ndarray\n\n    Parameters\n    ----------\n    constant_string: str\n        Base64 string to be decoded.\n\n    dtype: str\n        'float16' or 'float32' or 'float64' or 'uint8'\n        or 'int8' or 'int16' or 'int32' or 'int64' or 'string'\n\n    Returns\n    -------\n    decoded_ndarray: np.ndarray\n        Base64-decoded numpy.ndarray.\n```\n\n## 4. CLI Execution\n```bash\n$ sed4onnx \\\n--constant_string [-1,3,224,224] \\\n--dtype int64 \\\n--mode encode\n\n$ sed4onnx \\\n--constant_string '//////////8DAAAAAAAAAOAAAAAAAAAA4AAAAAAAAAA=' \\\n--dtype int64 \\\n--mode decode\n```\n\n## 5. In-script Execution\n```python\nfrom sed4onnx import encode\nfrom sed4onnx import decode\n\nbase64_string = encode(\n  constant_string='[-1,3,224,224]',\n  dtype='int64',\n)\n\nnumpy_ndarray = decode(\n  constant_string='//////////8DAAAAAAAAAOAAAAAAAAAA4AAAAAAAAAA=',\n  dtype='int64',\n)\n```\n\n## 6. Sample\n```bash\n$ sed4onnx \\\n--constant_string [-1,3,224,224] \\\n--dtype int64 \\\n--mode encode\n\n//////////8DAAAAAAAAAOAAAAAAAAAA4AAAAAAAAAA=\n\n\n$ sed4onnx \\\n--constant_string '//////////8DAAAAAAAAAOAAAAAAAAAA4AAAAAAAAAA=' \\\n--dtype int64 \\\n--mode decode\n\n[-1,3,224,224]\n```\n\n## 7. Reference\n1. https://github.com/onnx/onnx/blob/main/docs/Operators.md\n2. https://docs.nvidia.com/deeplearning/tensorrt/onnx-graphsurgeon/docs/index.html\n3. https://github.com/NVIDIA/TensorRT/tree/main/tools/onnx-graphsurgeon\n4. https://github.com/PINTO0309/simple-onnx-processing-tools\n5. https://github.com/PINTO0309/PINTO_model_zoo\n\n## 8. Issues\nhttps://github.com/PINTO0309/simple-onnx-processing-tools/issues\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinto0309%2Fsed4onnx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpinto0309%2Fsed4onnx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinto0309%2Fsed4onnx/lists"}