{"id":15695845,"url":"https://github.com/pinto0309/sog4onnx","last_synced_at":"2026-02-25T12:03:48.465Z","repository":{"id":42050326,"uuid":"480017899","full_name":"PINTO0309/sog4onnx","owner":"PINTO0309","description":"Simple ONNX operation generator. Simple Operation Generator for ONNX.","archived":false,"fork":false,"pushed_at":"2024-04-30T06:22:31.000Z","size":66,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-14T08:41:41.392Z","etag":null,"topics":["cli","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-10T12:57:06.000Z","updated_at":"2024-04-30T06:21:55.000Z","dependencies_parsed_at":"2024-10-24T02:03:13.250Z","dependency_job_id":"c94e9073-bff6-4eaa-8062-820e23528baa","html_url":"https://github.com/PINTO0309/sog4onnx","commit_stats":{"total_commits":67,"total_committers":2,"mean_commits":33.5,"dds":"0.014925373134328401","last_synced_commit":"cbd28bded471f51621e62be3d73d7861ade55a35"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsog4onnx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsog4onnx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsog4onnx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsog4onnx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PINTO0309","download_url":"https://codeload.github.com/PINTO0309/sog4onnx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246395594,"owners_count":20770242,"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":["cli","model-converter","models","onnx","python"],"created_at":"2024-10-03T19:05:09.431Z","updated_at":"2026-02-25T12:03:48.438Z","avatar_url":"https://github.com/PINTO0309.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sog4onnx\nSimple ONNX operation generator. **S**imple **O**peration **G**enerator for **ONNX**.\n\nhttps://github.com/PINTO0309/simple-onnx-processing-tools\n\n[![Downloads](https://static.pepy.tech/personalized-badge/sog4onnx?period=total\u0026units=none\u0026left_color=grey\u0026right_color=brightgreen\u0026left_text=Downloads)](https://pepy.tech/project/sog4onnx) ![GitHub](https://img.shields.io/github/license/PINTO0309/sog4onnx?color=2BAF2B) [![PyPI](https://img.shields.io/pypi/v/sog4onnx?color=2BAF2B)](https://pypi.org/project/sog4onnx/) [![CodeQL](https://github.com/PINTO0309/sog4onnx/workflows/CodeQL/badge.svg)](https://github.com/PINTO0309/sog4onnx/actions?query=workflow%3ACodeQL)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/33194443/170155206-3e771286-b5c4-4ac0-a5d7-ec9a0196cbbb.png\" /\u003e\n\u003c/p\u003e\n\n# Key concept\n\n- [x] Variable, Constant, Operation and Attribute can be generated externally.\n- [x] Allow Opset to be specified externally.\n- [x] No check for consistency of Operations within the tool, as new OPs are added frequently and the definitions of existing OPs change with each new version of ONNX's Opset.\n- [x] Only one OP can be defined at a time, and the goal is to generate free ONNX graphs using a combination of **[snc4onnx](https://github.com/PINTO0309/snc4onnx)**, **[sne4onnx](https://github.com/PINTO0309/sne4onnx)**, **[snd4onnx](https://github.com/PINTO0309/snd4onnx)** and **[scs4onnx](https://github.com/PINTO0309/scs4onnx)**.\n- [x] List of parameters that can be specified: https://github.com/onnx/onnx/blob/main/docs/Operators.md\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 onnx \\\n\u0026\u0026 python3 -m pip install -U onnx_graphsurgeon --index-url https://pypi.ngc.nvidia.com \\\n\u0026\u0026 pip install -U sog4onnx\n```\n### 1-2. Docker\nhttps://github.com/PINTO0309/simple-onnx-processing-tools#docker\n\n## 2. CLI Usage\n```\n$ sog4onnx -h\n\nusage: sog4onnx [-h]\n  --ot OP_TYPE\n  --os OPSET\n  --ir IR_VERSION\n  --on OP_NAME\n  [-iv NAME TYPE VALUE]\n  [-ov NAME TYPE VALUE]\n  [-a NAME DTYPE VALUE]\n  [-of OUTPUT_ONNX_FILE_PATH]\n  [-n]\n\noptional arguments:\n  -h, --help\n    show this help message and exit\n\n  -ot OP_TYPE, --op_type OP_TYPE\n    ONNX OP type.\n    https://github.com/onnx/onnx/blob/main/docs/Operators.md\n\n  -os OPSET, --opset OPSET\n    ONNX opset number.\n\n  -ir IR_VERSION, --ir_version IR_VERSION\n    ONNX ir_version number.\n\n  -on OP_NAME, --op_name OP_NAME\n    OP name.\n\n  -iv INPUT_VARIABLES INPUT_VARIABLES INPUT_VARIABLES, --input_variables INPUT_VARIABLES INPUT_VARIABLES INPUT_VARIABLES\n    input_variables can be specified multiple times.\n    --input_variables variable_name numpy.dtype shape\n    https://github.com/onnx/onnx/blob/main/docs/Operators.md\n\n    e.g.\n    --input_variables i1 float32 [1,3,5,5] \\\n    --input_variables i2 int32 [1] \\\n    --input_variables i3 float64 [1,3,224,224]\n\n  -ov OUTPUT_VARIABLES OUTPUT_VARIABLES OUTPUT_VARIABLES, --output_variables OUTPUT_VARIABLES OUTPUT_VARIABLES OUTPUT_VARIABLES\n    output_variables can be specified multiple times.\n    --output_variables variable_name numpy.dtype shape\n    https://github.com/onnx/onnx/blob/main/docs/Operators.md\n\n    e.g.\n    --output_variables o1 float32 [1,3,5,5] \\\n    --output_variables o2 int32 [1] \\\n    --output_variables o3 float64 [1,3,224,224]\n\n  -a ATTRIBUTES ATTRIBUTES ATTRIBUTES, --attributes ATTRIBUTES ATTRIBUTES ATTRIBUTES\n    attributes can be specified multiple times.\n    dtype is one of \"float32\" or \"float64\" or \"int32\" or \"int64\" or \"str\".\n    --attributes name dtype value\n    https://github.com/onnx/onnx/blob/main/docs/Operators.md\n\n    e.g.\n    --attributes alpha float32 1.0 \\\n    --attributes beta float32 1.0 \\\n    --attributes transA int32 0 \\\n    --attributes transB int32 0\n\n  -of OUTPUT_ONNX_FILE_PATH, --output_onnx_file_path OUTPUT_ONNX_FILE_PATH\n    Output onnx file path.\n    If not specified, a file with the OP type name is generated.\n\n    e.g. op_type=\"Gemm\" -\u003e Gemm.onnx\n\n  -n, --non_verbose\n    Do not show all information logs. Only error logs are displayed.\n```\n\n## 3. In-script Usage\n```python\n$ python\n\u003e\u003e\u003e from sog4onnx import generate\n\u003e\u003e\u003e help(generate)\nHelp on function generate in module sog4onnx.onnx_operation_generator:\n\ngenerate(\n  op_type: str,\n  opset: int,\n  ir_version: int,\n  op_name: str,\n  input_variables: dict,\n  output_variables: dict,\n  attributes: Union[dict, NoneType] = None,\n  output_onnx_file_path: Union[str, NoneType] = '',\n  non_verbose: Union[bool, NoneType] = False\n) -\u003e onnx.onnx_ml_pb2.ModelProto\n\n    Parameters\n    ----------\n    op_type: str\n        ONNX op type.\n        See below for the types of OPs that can be specified.\n        https://github.com/onnx/onnx/blob/main/docs/Operators.md\n\n        e.g. \"Add\", \"Div\", \"Gemm\", ...\n\n    opset: int\n        ONNX opset number.\n\n        e.g. 11\n\n    ir_version: int\n        ONNX ir_version number.\n\n        e.g. 9\n\n    op_name: str\n        OP name.\n\n    input_variables: Optional[dict]\n        Specify input variables for the OP to be generated.\n        See below for the variables that can be specified.\n        https://github.com/onnx/onnx/blob/main/docs/Operators.md\n        {\"input_var_name1\": [numpy.dtype, shape], \"input_var_name2\": [dtype, shape], ...}\n\n        e.g.\n        input_variables = {\n          \"name1\": [np.float32, [1,224,224,3]],\n          \"name2\": [np.bool_, [0]],\n          ...\n        }\n\n    output_variables: Optional[dict]\n        Specify output variables for the OP to be generated.\n        See below for the variables that can be specified.\n        https://github.com/onnx/onnx/blob/main/docs/Operators.md\n        {\"output_var_name1\": [numpy.dtype, shape], \"output_var_name2\": [dtype, shape], ...}\n\n        e.g.\n        output_variables = {\n          \"name1\": [np.float32, [1,224,224,3]],\n          \"name2\": [np.bool_, [0]],\n          ...\n        }\n\n    attributes: Optional[dict]\n        Specify output attributes for the OP to be generated.\n        See below for the attributes that can be specified.\n        When specifying Tensor format values, specify an array converted to np.ndarray.\n        https://github.com/onnx/onnx/blob/main/docs/Operators.md\n        {\"attr_name1\": value1, \"attr_name2\": value2, \"attr_name3\": value3, ...}\n\n        e.g.\n        attributes = {\n          \"alpha\": 1.0,\n          \"beta\": 1.0,\n          \"transA\": 0,\n          \"transB\": 0\n        }\n        Default: None\n\n    output_onnx_file_path: Optional[str]\n        Output of onnx file path.\n        If not specified, no .onnx file is output.\n        Default: ''\n\n    non_verbose: Optional[bool]\n        Do not show all information logs. Only error logs are displayed.\n        Default: False\n\n    Returns\n    -------\n    single_op_graph: onnx.ModelProto\n        Single op onnx ModelProto\n```\n\n## 4. CLI Execution\n```bash\n$ sog4onnx \\\n--op_type Gemm \\\n--opset 1 \\\n--op_name gemm_custom1 \\\n--input_variables i1 float32 [1,2,3] \\\n--input_variables i2 float32 [1,1] \\\n--input_variables i3 int32 [0] \\\n--output_variables o1 float32 [1,2,3] \\\n--attributes alpha float32 1.0 \\\n--attributes beta float32 1.0 \\\n--attributes transA int32 0 \\\n--attributes transB int32 0\n```\n\n## 5. In-script Execution\n```python\nimport numpy as np\nfrom sog4onnx import generate\n\nsingle_op_graph = generate(\n    op_type = 'Gemm',\n    opset = 1,\n    op_name = \"gemm_custom1\",\n    input_variables = {\n      \"i1\": [np.float32, [1,2,3]],\n      \"i2\": [np.float32, [1,1]],\n      \"i3\": [np.int32, [0]],\n    },\n    output_variables = {\n      \"o1\": [np.float32, [1,2,3]],\n    },\n    attributes = {\n      \"alpha\": 1.0,\n      \"beta\": 1.0,\n      \"broadcast\": 0,\n      \"transA\": 0,\n      \"transB\": 0,\n    },\n    non_verbose = True,\n)\n```\n\n## 6. Sample\n### 6-1. opset=1, Gemm\n```bash\n$ sog4onnx \\\n--op_type Gemm \\\n--opset 1 \\\n--op_name gemm_custom1 \\\n--input_variables i1 float32 [1,2,3] \\\n--input_variables i2 float32 [1,1] \\\n--input_variables i3 int32 [0] \\\n--output_variables o1 float32 [1,2,3] \\\n--attributes alpha float32 1.0 \\\n--attributes beta float32 1.0 \\\n--attributes transA int32 0 \\\n--attributes transB int32 0\n--non_verbose\n```\n![image](https://user-images.githubusercontent.com/33194443/163018526-f2d5c647-c3e9-4e65-9b9a-c1c4fa5da8a5.png)\n![image](https://user-images.githubusercontent.com/33194443/163018647-a6880370-8772-4af1-9ffe-59820a621c30.png)\n\n### 6-2. opset=11, Add\n```bash\n$ sog4onnx \\\n--op_type Add \\\n--opset 11 \\\n--op_name add_custom1 \\\n--input_variables i1 float32 [1,2,3] \\\n--input_variables i2 float32 [1,2,3] \\\n--output_variables o1 float32 [1,2,3] \\\n--non_verbose\n```\n![image](https://user-images.githubusercontent.com/33194443/163042479-9998ba73-ee26-44ea-bd6b-dcd04539190b.png)\n![image](https://user-images.githubusercontent.com/33194443/163042529-5dbd1b5f-e8d1-47d0-8a9e-aacd91539c2b.png)\n\n### 6-3. opset=11, NonMaxSuppression\n```bash\n$ sog4onnx \\\n--op_type NonMaxSuppression \\\n--opset 11 \\\n--op_name nms_custom1 \\\n--input_variables boxes float32 [1,6,4] \\\n--input_variables scores float32 [1,1,6] \\\n--input_variables max_output_boxes_per_class int64 [1] \\\n--input_variables iou_threshold float32 [1] \\\n--input_variables score_threshold float32 [1] \\\n--output_variables selected_indices int64 [3,3] \\\n--attributes center_point_box int64 1\n```\n![image](https://user-images.githubusercontent.com/33194443/163291737-8bd7ad7e-f9e5-4ce9-a8ba-444f1a8e77bb.png)\n![image](https://user-images.githubusercontent.com/33194443/163291789-59e4e5c8-26f4-4971-ab22-1486093f1be0.png)\n\n### 6-4. opset=11, Constant\n```bash\n$ sog4onnx \\\n--op_type Constant \\\n--opset 11 \\\n--op_name const_custom1 \\\n--output_variables boxes float32 [1,6,4] \\\n--attributes value float32 \\\n[[\\\n[0.5,0.5,1.0,1.0],\\\n[0.5,0.6,1.0,1.0],\\\n[0.5,0.4,1.0,1.0],\\\n[0.5,10.5,1.0,1.0],\\\n[0.5,10.6,1.0,1.0],\\\n[0.5,100.5,1.0,1.0]\\\n]]\n```\n![image](https://user-images.githubusercontent.com/33194443/163311192-b559134f-d42d-4119-8990-0f7ac63230e3.png)\n\n### 6-5. opset=11, EfficientNMS_TRT (TensorRT Efficient NMS Plugin)\n```bash\n$ sog4onnx \\\n--op_type EfficientNMS_TRT \\\n--opset 11 \\\n--op_name trt_nms_efficient_std_11 \\\n--input_variables boxes float32 [1,3549,4] \\\n--input_variables scores float32 [1,3549,16] \\\n--attributes plugin_version str 1 \\\n--attributes score_threshold float32 0.25 \\\n--attributes iou_threshold float32 0.45 \\\n--attributes max_output_boxes int64 20 \\\n--attributes background_class int64 -1 \\\n--attributes score_activation bool False \\\n--attributes box_coding int64 0 \\\n--output_variables num_detections int32 [1,1] \\\n--output_variables detection_boxes float32 [1,20,4] \\\n--output_variables detection_scores float32 [1,20] \\\n--output_variables detection_classes int32 [1,20]\n```\n![image](https://github.com/PINTO0309/sog4onnx/assets/33194443/1b3989fd-cd73-4b1e-af59-cda25ea61a97)\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/sne4onnx\n5. https://github.com/PINTO0309/snd4onnx\n6. https://github.com/PINTO0309/snc4onnx\n7. https://github.com/PINTO0309/scs4onnx\n8. 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%2Fsog4onnx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpinto0309%2Fsog4onnx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinto0309%2Fsog4onnx/lists"}