6.1. TopsIDEAS onnx extract

描述

按照给定的输入输出tensor提取onnx模型的子图

命令行

使用方法

usage: topsideas onnx extract [-h] --input_onnx INPUT_ONNX [--output_onnx OUTPUT_ONNX] [--inputs INPUT_META [INPUT_META ...]]
                              [--outputs OUTPUT_META [OUTPUT_META ...]] [--infer_shape_mode {onnx,symbolic,static,skip}]

参数

short long default help
-h --help show this help message and exit
--input_onnx None Provide the original onnx file.
--output_onnx subgraph.onnx Export the modified ONNX file.
--inputs [] Input metadata for subgraph (names, shapes, and data types). Use 'auto' to make extract determine these automatically. Format: --inputs NAME:SHAPE:DTYPE. For example: --inputs input0:[1,3,224,224]:float32 input1:[1,3,224,224] input2. If omitted, uses the current model inputs.
--outputs [] Output metadata for subgraph (names and data types). No dataformat provided to make extract determine these automatically. Format: --outputs NAME:DTYPE. For example: --outputs output0:float32 output1. If omitted, uses the current model outputs.
--infer_shape_mode onnx The mode to do shape inference, choices are ['onnx', 'symbolic', 'static', 'skip']. onnx mode use shape inference provided by onnx library, cannot infer dynamic shape. symbolic mode can process more dynamic shapes by symbolic maths. static mode will run inference to collect shapes, which may cause some dynamic dimensions to become static.skip mode will skip shape inference to keep shape info in original onnx file.

示例

topsideas onnx extract --input_onnx=demo.onnx --inputs 'MaxPool:0' --outputs 'concat:0' --output_onnx=demo_subgraph.onnx  

result

API

使用方法

from topsideas.onnx import Extract
result = Extract.run(model, input_meta, output_meta)

参数

argument type default
model onnx.onnx_ml_pb2.ModelProto
input_meta List[str]
output_meta List[str]
infer_shape_mode str onnx
RETURN onnx.onnx_ml_pb2.ModelProto