sed4onnx


Namesed4onnx JSON
Version 1.0.5 PyPI version JSON
download
home_pagehttps://github.com/PINTO0309/sed4onnx
SummarySimple ONNX constant encoder/decoder.
upload_time2022-12-30 15:59:43
maintainer
docs_urlNone
authorKatsuya Hyodo
requires_python>=3.6
licenseMIT License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sed4onnx
Simple ONNX constant encoder/decoder.

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

[![Downloads](https://static.pepy.tech/personalized-badge/sed4onnx?period=total&units=none&left_color=grey&right_color=brightgreen&left_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)

<p align="center">
  <img src="https://user-images.githubusercontent.com/33194443/170163328-b680be10-7f98-4a61-8d49-e28423046297.png" />
</p>

## Key concept
- Since the constant values in the JSON files generated by **[onnx2json](https://github.com/PINTO0309/onnx2json)** are Base64-encoded values, ASCII <-> Base64 conversion is required when rewriting JSON constant values.
- 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.

## 1. Setup
### 1-1. HostPC
```bash
### option
$ echo export PATH="~/.local/bin:$PATH" >> ~/.bashrc \
&& source ~/.bashrc

### run
$ pip install -U sed4onnx
```
### 1-2. Docker
https://github.com/PINTO0309/simple-onnx-processing-tools#docker


## 2. CLI Usage
```
$ sed4onnx -h

usage:
    sed4onnx [-h]
    -cs CONSTANT_STRING
    [-d {float16,float32,float64,uint8,int8,int16,int32,int64,string}]
    [-m {encode,decode}]

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

  -cs CONSTANT_STRING, --constant_string CONSTANT_STRING
        Strings to be encoded and decoded for ONNX constants.

  -d {float16,float32,float64,uint8,int8,int16,int32,int64,string}, \
    --dtype {float16,float32,float64,uint8,int8,int16,int32,int64,string}
        Data type.

  -m {encode,decode}, --mode {encode,decode}
        encode: Converts the string specified in constant_string to a Base64 format string
                that can be embedded in ONNX constants.
        decode: Converts a Base64 string specified in constant_string to ASCII like
                Numpy string or pure string.
```

## 3. In-script Usage
```python
>>> from sed4onnx import encode
>>> from sed4onnx import decode
>>> help(encode)

Help on function encode in module sed4onnx.onnx_constant_encoder_decoder:

encode(constant_string: str) -> str

    Parameters
    ----------
    constant_string: str
        ASCII string to be encoded.

    dtype: str
        'float16' or 'float32' or 'float64' or 'uint8'
        or 'int8' or 'int16' or 'int32' or 'int64' or 'string'

    Returns
    -------
    encoded_string: str
        Base64-encoded ASCII string.


>>> help(decode)
Help on function decode in module sed4onnx.onnx_constant_encoder_decoder:

decode(constant_string: str, dtype: str) -> numpy.ndarray

    Parameters
    ----------
    constant_string: str
        Base64 string to be decoded.

    dtype: str
        'float16' or 'float32' or 'float64' or 'uint8'
        or 'int8' or 'int16' or 'int32' or 'int64' or 'string'

    Returns
    -------
    decoded_ndarray: np.ndarray
        Base64-decoded numpy.ndarray.
```

## 4. CLI Execution
```bash
$ sed4onnx \
--constant_string [-1,3,224,224] \
--dtype int64 \
--mode encode

$ sed4onnx \
--constant_string '//////////8DAAAAAAAAAOAAAAAAAAAA4AAAAAAAAAA=' \
--dtype int64 \
--mode decode
```

## 5. In-script Execution
```python
from sed4onnx import encode
from sed4onnx import decode

base64_string = encode(
  constant_string='[-1,3,224,224]',
  dtype='int64',
)

numpy_ndarray = decode(
  constant_string='//////////8DAAAAAAAAAOAAAAAAAAAA4AAAAAAAAAA=',
  dtype='int64',
)
```

## 6. Sample
```bash
$ sed4onnx \
--constant_string [-1,3,224,224] \
--dtype int64 \
--mode encode

//////////8DAAAAAAAAAOAAAAAAAAAA4AAAAAAAAAA=


$ sed4onnx \
--constant_string '//////////8DAAAAAAAAAOAAAAAAAAAA4AAAAAAAAAA=' \
--dtype int64 \
--mode decode

[-1,3,224,224]
```

## 7. Reference
1. https://github.com/onnx/onnx/blob/main/docs/Operators.md
2. https://docs.nvidia.com/deeplearning/tensorrt/onnx-graphsurgeon/docs/index.html
3. https://github.com/NVIDIA/TensorRT/tree/main/tools/onnx-graphsurgeon
4. https://github.com/PINTO0309/simple-onnx-processing-tools
5. https://github.com/PINTO0309/PINTO_model_zoo

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/PINTO0309/sed4onnx",
    "name": "sed4onnx",
    "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/6e/c5/2fe3b9c5c966512a75284f90d662af516b2e1d03a33f93c368d8a0bfabae/sed4onnx-1.0.5.tar.gz",
    "platform": "linux",
    "description": "# 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&units=none&left_color=grey&right_color=brightgreen&left_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<p align=\"center\">\n  <img src=\"https://user-images.githubusercontent.com/33194443/170163328-b680be10-7f98-4a61-8d49-e28423046297.png\" />\n</p>\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 <-> 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\" >> ~/.bashrc \\\n&& 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>>> from sed4onnx import encode\n>>> from sed4onnx import decode\n>>> help(encode)\n\nHelp on function encode in module sed4onnx.onnx_constant_encoder_decoder:\n\nencode(constant_string: str) -> 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>>> help(decode)\nHelp on function decode in module sed4onnx.onnx_constant_encoder_decoder:\n\ndecode(constant_string: str, dtype: str) -> 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",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Simple ONNX constant encoder/decoder.",
    "version": "1.0.5",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "38bcb04e3d08c9b03c6799d4b370746f",
                "sha256": "db80a1c229d7783bed1c88efc868867bd0dfe7180605546d0b05f8aa15c2a50e"
            },
            "downloads": -1,
            "filename": "sed4onnx-1.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "38bcb04e3d08c9b03c6799d4b370746f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 5681,
            "upload_time": "2022-12-30T15:59:42",
            "upload_time_iso_8601": "2022-12-30T15:59:42.440545Z",
            "url": "https://files.pythonhosted.org/packages/c2/37/0dd964355edff208522bbe978e82c5eefc1105536afd52a41ce9063b7812/sed4onnx-1.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "00d2f56978d41cc0f0d957b9c87d9d5c",
                "sha256": "14949a1adfc7287ed9857be6a623f73700c26b27cfeb7f76975aac689557f62b"
            },
            "downloads": -1,
            "filename": "sed4onnx-1.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "00d2f56978d41cc0f0d957b9c87d9d5c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 4874,
            "upload_time": "2022-12-30T15:59:43",
            "upload_time_iso_8601": "2022-12-30T15:59:43.788060Z",
            "url": "https://files.pythonhosted.org/packages/6e/c5/2fe3b9c5c966512a75284f90d662af516b2e1d03a33f93c368d8a0bfabae/sed4onnx-1.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-30 15:59:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "PINTO0309",
    "github_project": "sed4onnx",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "sed4onnx"
}
        
Elapsed time: 0.02276s