6.4. TopsIDEAS onnx fold_constant

描述

onnx模型常量折叠,来源于onnxsim中的常量折叠方法。

命令行

使用方法

usage: topsideas onnx fold_constant [-h] --input_onnx INPUT_ONNX [--output_onnx OUTPUT_ONNX] [--check_n CHECK_N] [--input_shape INPUT_SHAPE [INPUT_SHAPE ...]]
                                    [--input-data-path INPUT_DATA_PATH [INPUT_DATA_PATH ...]] [--skip-shape-inference] [--dynamic-input-shape]

参数

:::{table} topsideas onnx fold_constant 参数列表
:widths: 8 32 20 45

short

long

default

help

-h

--help

show this help message and exit

--input_onnx

None

Provide the original onnx file.

--output_onnx

fold.onnx

Export the modified onnx file.

--check_n

3

Check whether the output is correct with n random inputs.

--input_shape

[]

Overwrite input shapes if not set –dynamic-input-shape, otherwise used for generating random inputs in checking. Format: –input_shape name:shape. For example: –input_shape input1:[1,3,224,224] input2:[4] input3:[]. If omitted, uses the current model inputs.

--input-data-path

None

input data, The value should be ‘input_name1:xxx1.bin’ ‘input_name2:xxx2.bin …’, input data should be a binary data file.

--skip-shape-inference

Skip shape inference. Shape inference causes segfault on some large models.

--dynamic-input-shape

This option enables dynamic input shape support.’Shape’ ops will not be eliminated in this case.Note that ‘–input_shape’ is also needed for generating random inputs and checking equality. If ‘dynamic_input_shape’ is False, the input shape in simplified model will be overwritten by the value of ‘input_shapes’ param.

:::

示例

topsideas onnx fold_constant --input_onnx=demo.onnx --output_onnx=demo_fold.onnx  

:::{figure-md} onnx常量折叠示例

onnx常量折叠示例 :::

API

使用方法

from topsideas.onnx import FoldConstant
result = FoldConstant.run(input_mp)

参数

:::{table} topsideas.onnx.FoldConstant 参数列表
:widths: 25 40 35

argument

type

default

input_mp

onnx.onnx_ml_pb2.ModelProto

check_n

int

3

dynamic_input_shape

bool

None

input_shape

str

None

skip_shape_inference

bool

False

custom_lib

str

None

input_data_path

str

None

RETURN

onnx.onnx_ml_pb2.ModelProto

:::