@@ -5,7 +5,7 @@ A very simple tool for situations where optimization with onnx-simplifier would
5
5
6
6
# Key concept
7
7
- [x] If INPUT OP name and OUTPUT OP name are specified, the onnx graph within the range of the specified OP name is extracted and .onnx is generated.
8
- - [ ] Change backend to onnx-graphsurgeon so that onnx.ModelProto can be specified as input.
8
+ - [x ] Change backend to ` onnx.utils.Extractor.extract_model ` so that onnx.ModelProto can be specified as input.
9
9
10
10
## 1. Setup
11
11
### 1-1. HostPC
@@ -75,7 +75,8 @@ extraction(
75
75
input_onnx_file_path: str,
76
76
input_op_names: List[str],
77
77
output_op_names: List[str],
78
- output_onnx_file_path: Union[str, NoneType] = ' '
78
+ output_onnx_file_path: Union[str, NoneType] = ' ' ,
79
+ onnx_graph: Union[onnx.onnx_ml_pb2.ModelProto, NoneType] = None
79
80
) -> onnx.onnx_ml_pb2.ModelProto
80
81
81
82
Parameters
@@ -98,6 +99,11 @@ extraction(
98
99
If not specified, .onnx is not output.
99
100
Default: ' '
100
101
102
+ onnx_graph: Optional[onnx.ModelProto]
103
+ onnx.ModelProto.
104
+ Either input_onnx_file_path or onnx_graph must be specified.
105
+ onnx_graph If specified, ignore input_onnx_file_path and process onnx_graph.
106
+
101
107
Returns
102
108
-------
103
109
extracted_graph: onnx.ModelProto
@@ -114,6 +120,7 @@ $ sne4onnx \
114
120
```
115
121
116
122
## 5. In-script Execution
123
+ ### 5-1. Use ONNX files
117
124
``` python
118
125
from sne4onnx import extraction
119
126
@@ -124,6 +131,17 @@ extracted_graph = extraction(
124
131
output_onnx_file_path = ' output.onnx' ,
125
132
)
126
133
```
134
+ ### 5-2. Use onnx.ModelProto
135
+ ``` python
136
+ from sne4onnx import extraction
137
+
138
+ extracted_graph = extraction(
139
+ input_op_names = [' aaa' , ' bbb' , ' ccc' ],
140
+ output_op_names = [' ddd' , ' eee' , ' fff' ],
141
+ output_onnx_file_path = ' output.onnx' ,
142
+ onnx_graph = graph,
143
+ )
144
+ ```
127
145
128
146
## 6. Samples
129
147
### 6-1. Pre-extraction
@@ -147,6 +165,8 @@ $ sne4onnx \
147
165
148
166
## 7. Reference
149
167
1 . https://github.com/onnx/onnx/blob/main/docs/PythonAPIOverview.md
150
- 2 . https://github.com/PINTO0309/snd4onnx
151
- 3 . https://github.com/PINTO0309/scs4onnx
152
- 4 . https://github.com/PINTO0309/snc4onnx
168
+ 2 . https://docs.nvidia.com/deeplearning/tensorrt/onnx-graphsurgeon/docs/index.html
169
+ 3 . https://github.com/NVIDIA/TensorRT/tree/main/tools/onnx-graphsurgeon
170
+ 4 . https://github.com/PINTO0309/snd4onnx
171
+ 5 . https://github.com/PINTO0309/scs4onnx
172
+ 6 . https://github.com/PINTO0309/snc4onnx
0 commit comments