NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI · #4407 most downloaded on PyPI
A tool for converting ONNX files to LiteRT/TFLite/TensorFlow, PyTorch native code (nn.Module), TorchScript (.pt), state_dict (.pt), Exported Program (.pt2), and Dynamo ONNX. It also supports direct conversion from LiteRT to PyTorch.
Last release 6 days ago
14 Sep 2026
Release timing varies
gaps range from 8 days to 2 months
Nearly every release is documented
notes for 60 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
4 years old
629 releases · first in 2022
Fixed so that the URL for downloading the flatc binary is changed for each CPU architecture to be built. by @PINTO0309 in https://github.com/PINTO0309
GatherElements
GatherElements by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/739Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.26.7...1.26.8
Fixed the broadcast processing when x_scale is 1D 1Elem.
DequantizeLinear
x_scale is 1D 1Elem.onnx2tf -i best.onnx -ois images:1,3,512,640
x_scale is 1D 1Elem by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/735Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.26.6...1.26.7
One column per quarter.
arm64 hosted runner image deploy test
flatc arm64 binaryFull Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.26.5...1.26.6
Enable selection of V4 and V5 for NonMaxSuppression. ` -snms {v4,v5}, --switch_nms_version {v4,v5} Switch the NMS version to V4 or V5 to convert. e.g.
NonMaxSuppression
NonMaxSuppression. -snms {v4,v5}, --switch_nms_version {v4,v5}
Switch the NMS version to V4 or V5 to convert.
e.g.
NonMaxSuppressionV4(default): --switch_nms_version v4
NonMaxSuppressionV5: --switch_nms_version v5
TensorFlow.js / tfjs - register_all_kernels.ts
wasm
https://github.com/tensorflow/tfjs/blob/master/tfjs-backend-wasm/src/register_all_kernels.ts#L116-L118
webgl
https://github.com/tensorflow/tfjs/blob/master/tfjs-backend-webgl/src/register_all_kernels.ts#L120-L122
webgpu
https://github.com/tensorflow/tfjs/blob/master/tfjs-backend-webgpu/src/register_all_kernels.ts#L122-L123
NonMaxSuppression by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/732Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.26.4...1.26.5
Problems when transforming dynamic input models and quantifying static models #729
Add
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.26.3...1.26.4
MatMul Fix incorrect tensor expansion in MatMul operation
MatMul
Fix incorrect tensor expansion in MatMul operationThe MatMul operation was incorrectly handling 1-dimensional tensors by expanding
the wrong input tensor. When handling a 1D input tensor (shape [256]), it was
erroneously expanding input_tensor_2 (shape [256, 254]) instead of input_tensor_1,
leading to incorrect shape transformations.
Changed:
input_tensor_1 = tf.expand_dims(input_tensor_2, axis=0)
to
input_tensor_1 = tf.expand_dims(input_tensor_1, axis=0)
This ensures the correct tensor is expanded when handling 1D inputs.
Before:
Input1 shape: [256] -> incorrectly became [1,256,254]
Input2 shape: [256,254] remained unchanged
After:
Input1 shape: [256] -> correctly becomes [1,256]
Input2 shape: [256,254] remains unchanged
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.26.2...1.26.3
Supports multi-batch quantization of image input. ` onnx2tf \ -i batch_size_2.onnx \ -oiqt \ -cind images test.npy [[[[0.485,0.456,0.406]]]] [[[[0.229
onnx2tf \
-i batch_size_2.onnx \
-oiqt \
-cind images test.npy [[[[0.485,0.456,0.406]]]] [[[[0.229,0.224,0.225]]]]
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.26.1...1.26.2
Added Float32 as an option for input and output types after quantization. ```bash -iqd {int8,uint8,float32}, --input_quant_dtype {int8,uint8,float32}
Float32 as an option for input and output types after quantization.-iqd {int8,uint8,float32}, --input_quant_dtype {int8,uint8,float32}
Input dtypes when doing Full INT8 Quantization.
"int8"(default) or "uint8" or "float32"
-oqd {int8,uint8,float32}, --output_quant_dtype {int8,uint8,float32}
Output dtypes when doing Full INT8 Quantization.
"int8"(default) or "uint8" or "float32"
input_quant_dtype, output_quant_dtype by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/706replace_slice.json reference by @emmanuel-ferdman in https://github.com/PINTO0309/onnx2tf/pull/708Float32 option by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/712Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.26.0...1.26.1
The input and output quantization types can now be specified with separate, different parameters for input and output.
API changed
input_output_quant_dtypeinput_quant_dtypeoutput_quant_dtypeConv
Conv.{
"format_version": 1,
"operations": [
{
"op_name": "wa/conv/Conv",
"param_target": "outputs",
"param_name": "output",
"post_process_transpose_perm": [0,3,1,2]
}
]
}
onnx2tf -i model_conv.onnx -kat input -prf replace_conv.json
Mul
Mul.
README corrections due to API changes (I'll get serious from tomorrow) #702
Conv by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/704Mul by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/705Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.15...1.26.0
Fixed to force switch between X and Y when X: np.ndarray, Y: Tensor ` onnx2tf -i 1005_s0_nonar_text_decoder.onnx -cotof ` !image
Mul, Add
X and Y when X: np.ndarray, Y: Tensoronnx2tf -i 1005_s0_nonar_text_decoder.onnx -cotof
X and Y when X: np.ndarray, Y: Tensor by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/699Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.14...1.25.15
Dealing with garbage-like broken structures in ONNX (ArgMin) #695
ArgMin
ArgMin) #695Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.13...1.25.14
Dealing with garbage-like broken structures in ONNX. !image !image
ArgMax, Faltten
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.12...1.25.13
Improved handling when axis attribute is not defined and the batch size of the first dimension is undefined.
Flatten
axis attribute is not defined and the batch size of the first dimension is undefined.wget https://github.com/PINTO0309/onnx2tf/releases/download/0.0.2/resnet18-v1-7.onnx
onnx2tf -i resnet18-v1-7.onnx
ls -lh saved_model/
assets
fingerprint.pb
resnet18-v1-7_float16.tflite
resnet18-v1-7_float32.tflite
saved_model.pb
variables
TF_CPP_MIN_LOG_LEVEL=3 \
saved_model_cli show \
--dir saved_model \
--signature_def serving_default \
--tag_set serve
The given SavedModel SignatureDef contains the following input(s):
inputs['data'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 224, 224, 3)
name: serving_default_data:0
The given SavedModel SignatureDef contains the following output(s):
outputs['output_0'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 1000)
name: PartitionedCall:0
Method name is: tensorflow/serving/predict
axis attribute is not defined and the batch size of the first dimension is undefined. by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/692Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.11...1.25.12
Improved the conversion stability of BatchNormalization.
BatchNormalization
BatchNormalization.BatchNormalization. by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/690Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.10...1.25.11
Addressed the issue of missing conversions when multi-dimensional flattening is performed and the batch size of the first dimension is an undefined di
Flatten
| ONNX | TFLite |
|---|---|
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.9...1.25.10
https://huggingface.co/onnx-community/metric3d-vit-small/blob/main/onnx/model.onnx
Add, Sub
1e-4.
y = (200 - x) - 200 operation caused an incorrect Sub merge operation to be performed.Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.8...1.25.9
Fixed problem of being stuck in an infinite loop.
Shape
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.7...1.25.8
Expand, BatchNormalization, Gather
Expand, BatchNormalization, Gather
AveragePool
Only very few edge cases are supported.
The dynamic tensor AveragePool is difficult to replace exactly with TensorFlow's AveragePooling.
I have fixed and released the critical problems except for AveragePool, but AveragePool (with ceil_mode=1) with dynamic tensor as input is extremely difficult to fix due to compatibility issues with TensorFlow.
The problem is that the error was not occurring in the AveragePool (with ceil_mode=1) where the conversion error should have occurred, and the latest onnx2tf should now generate a conversion error in the AveragePool (with ceil_mode=1).
INFO: 39 / 1464
INFO: onnx_op_type: AveragePool onnx_op_name: wa/xvector/block1/tdnnd1/cam_layer/AveragePool
INFO: input_name.1: wa/xvector/block1/tdnnd1/nonlinear2/relu/Relu_output_0 shape: [1, 128, 'unk__71'] dtype: float32
INFO: output_name.1: wa/xvector/block1/tdnnd1/cam_layer/AveragePool_output_0 shape: [1, 128, 'unk__77'] dtype: float32
ERROR: The trace log is below.
Traceback (most recent call last):
File "/home/xxxxx/git/onnx2tf/onnx2tf/utils/common_functions.py", line 312, in print_wrapper_func
result = func(*args, **kwargs)
File "/home/xxxxx/git/onnx2tf/onnx2tf/utils/common_functions.py", line 385, in inverted_operation_enable_disable_wrapper_func
result = func(*args, **kwargs)
File "/home/xxxxx/git/onnx2tf/onnx2tf/utils/common_functions.py", line 55, in get_replacement_parameter_wrapper_func
func(*args, **kwargs)
File "/home/xxxxx/git/onnx2tf/onnx2tf/ops/AveragePool.py", line 171, in make_node
output_spatial_shape = [
File "/home/xxxxx/git/onnx2tf/onnx2tf/ops/AveragePool.py", line 172, in <listcomp>
func((i + pb + pe - d * (k - 1) - 1) / s + 1)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
ERROR: input_onnx_file_path: ../cam++_vin.onnx
ERROR: onnx_op_name: wa/xvector/block1/tdnnd1/cam_layer/AveragePool
ERROR: Read this and deal with it. https://github.com/PINTO0309/onnx2tf#parameter-replacement
ERROR: Alternatively, if the input OP has a dynamic dimension, use the -b or -ois option to rewrite it to a static shape and try again.
ERROR: If the input OP of ONNX before conversion is NHWC or an irregular channel arrangement other than NCHW, use the -kt or -kat option.
ERROR: Also, for models that include NonMaxSuppression in the post-processing, try the -onwdt option.
Expand, BatchNormalization, Gather by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/675Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.6...1.25.7
Bug fix for Dynamic Resize optimization pattern. https://github.com/yakhyo/face-parsing
Concat
Bug fix for Dynamic Resize optimization pattern.
https://github.com/yakhyo/face-parsing
| ONNX | TFLite |
|---|---|
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.5...1.25.6
Fixed NHWC flag judgment bug in Transpose of ViT for 3D tensor
Transpose
Transpose of ViT for 3D tensorFull Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.4...1.25.5
Addition of automatic INT8 calibration process for RGBA 4-channel images.
mean = np.asarray([[[[0.485, 0.456, 0.406, 0.000]]]], dtype=np.float32)
std = np.asarray([[[[0.229, 0.224, 0.225, 1.000]]]], dtype=np.float32)
new_element_array = np.full((*calib_data.shape[:-1], 1), 0.500, dtype=np.float32)
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.3...1.25.4
Improved conversion stability for Transpose -> Softmax -> Transpose combinations.
Improvements to ScatterND.
Improved conversion stability for Transpose -> Softmax -> Transpose combinations.
Improved error message regarding OP name error when GroupConvolution is included.
Change -osd option to True by default.
ERROR: Generation of saved_model failed because the OP name does not match the following pattern. ^[A-Za-z0-9.][A-Za-z0-9_.\\/>-]*$
ERROR: /model.22/cv2.2/cv2.2.2/Conv/kernel
ERROR: Please convert again with the `-osd` or `--output_signaturedefs` option.
ScatterND, Transpose -> Softmax -> Transpose combinations by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/669Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.2...1.25.3
Support for DepthToSpace (CRD mode) transformation of dynamic tensors with multiple undefined dimensions.
DepthToSpace
DepthToSpace (CRD mode) transformation of dynamic tensors with multiple undefined dimensions.float32 [batch_size,3,height,width]float32 [batch_size,3,height,width]| ONNX | TFLite |
|---|---|
| <br> |
DepthToSpace transformation of dynamic tensors with multiple undefined dimensions by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/668Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.1...1.25.2
Add -inimc / --input_names_to_interrupt_model_conversion option. By specifying ONNX input or output names, only the middle part of the model can be co
Add -inimc / --input_names_to_interrupt_model_conversion option.
By specifying ONNX input or output names, only the middle part of the model can be converted. This is useful when you want to see what output is obtained in what part of the model after conversion, or when debugging the model conversion operation itself.
For example, take a model with multiple inputs and multiple outputs as shown in the figure below to try a partial transformation.
To convert by specifying only the input name to start the conversion
wget https://github.com/PINTO0309/onnx2tf/releases/download/1.25.0/cf_fus.onnx
onnx2tf -i cf_fus.onnx -inimc 448 -coion
To convert by specifying only the output name to end the conversion
wget https://github.com/PINTO0309/onnx2tf/releases/download/1.25.0/cf_fus.onnx
onnx2tf -i cf_fus.onnx -onimc dep_sec -coion
To perform a conversion by specifying the input name to start the conversion and the output name to end the conversion
wget https://github.com/PINTO0309/onnx2tf/releases/download/1.25.0/cf_fus.onnx
onnx2tf -i cf_fus.onnx -inimc 448 -onimc velocity -coion
-inimc option by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/667Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.25.0...1.25.1
Add type hints by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/665
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.24.1...1.25.0
Optimization of four consecutive arithmetic operations using scalar values following Gemm and MatMul.
Optimization of four consecutive arithmetic operations using scalar values following Gemm and MatMul.
If no change occurs in the shape of the input tensor and the output tensor after the operation, skip the broadcast regardless of whether the previous operation was Gemm or not. It should be effective no matter how many arithmetic operations on scalar values are performed in succession.
repro_new_onnx_model_v2_2.onnx repro_new_onnx_model_v2_2.onnx.zip
Without -b option
| ONNX | TFLite |
|---|---|
With -b 1 option
| ONNX | TFLite |
|---|---|
ViT-B-16__openai_partial.onnx ViT-B-16__openai_partial_cut.onnx.zip
| ONNX | TFLite |
|---|---|
Gemm and MatMul by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/664Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.24.0...1.24.1
Significantly upgraded Flatbuffer schema_v3 v2.11.0 -> v2.17.0
StableHLOFullyConnected - quantized_bias_typeFull Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.23.3...1.24.0
Disable arm64/aarch64 containers
GroupConvolution conversion bug on -osd and -oiqt.Error when without -dgc: onnx2tf.py -i shufflenet-9.onnx -oiqt #657
[CI] GitHub Actions fails to build ARM64/aarch64 docker image #653
https://github.com/PINTO0309/onnx2tf/actions/runs/9729858105/job/26852247647
https://github.com/PINTO0309/onnx2tf/actions/runs/9771330921/job/26973945295
GroupConvolution conversion bug on -osd and -oiqt by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/661Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.23.2...1.23.3
Temporary deletion arm64 by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/660
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.23.1...1.23.2
Fix arm64 by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/659
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.23.0...1.23.1
Generation of saved_model with GroupConvolution and Full Integer Quantization without -dgc, -osd.
saved_model with GroupConvolution and Full Integer Quantization without -dgc, -osd.GroupConvolution + Dynamic Input [1, None, None, 3]saved_model with GroupConvolution and Full Integer Quantization without --dgc by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/655Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.22.6...1.23.0
Support for INT8 auto-calibration of models with undefined dimensions in the input OP. !image
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.22.5...1.22.6
Workaround to the problem of TensorFlow corrupting the FlatBuffer input/output order during INT8 quantization.
Workaround to the problem of TensorFlow corrupting the FlatBuffer input/output order during INT8 quantization.
Determination of the number of inputs/outputs of the same shape.
Correct name discrepancies based on shape if multiple inputs/outputs shapes do not overlap.
However, if there are inputs/outputs containing undefined dimensions, workaround is skipped because correction is not possible.
Input and Output Name Order Swapping with -coion option #650
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.22.4...1.22.5
Implemented the ability to forcibly estimate the shape of com.microsoft v1 modules for which onnx.shape_inference.infer_shapes(x) does not work correc
FusedConv, Resize
com.microsoft v1 modules for which onnx.shape_inference.infer_shapes(x) does not work correctly. e.g. FusedConv
Resize operations like garbage. (Not perfect, but only for a very few edge cases)
com.microsoft v1 modules for which onnx.shape_inference.infer_shapes(x) does not work correctly. by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/646Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.22.3...1.22.4
Fix multi-platform image push by @ysohma in https://github.com/PINTO0309/onnx2tf/pull/639
Multi-Arch Docker Image
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.22.0...1.22.3
Docker Image (arm64, Apple Silicon Mac) Distributed docker image is not compatible with ARM environments such as Apple Silicon Mac. Although Docker of
Docker Image (arm64, Apple Silicon Mac)
Distributed docker image is not compatible with ARM environments such as Apple Silicon Mac.
Although Docker offers emulation for x86/amd64 environments, onnx2tf within this emulation mode results in an error, as shown below:
$ root@39d07181ce27:/# onnx2tf -h
> Illegal instruction
This issue is suspected to be caused by the dependency of PyPI TensorFlow on x86-specific instruction sets.
To address this, I've augmented the release process with GitHub Actions to include building and pushing Docker images for Arm64 architecture. This make it possible to execute onnx2tf with docker on Arm64 hosts.
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.21.6...1.22.0
MatMulInteger Currently, MatMulInteger is implemented as tf matmul with int32 inputs/outputs, which leads to generation of Flex(Batch)MatMul ops.
MatMulInteger
Currently, MatMulInteger is implemented as tf matmul with int32 inputs/outputs, which leads to generation of Flex(Batch)MatMul ops.
When -rtpo MatMulInteger is specified, inputs of MatMulInteger are casted to float32 instead, allowing the node to be converted to the builtin FullyConnected or BatchMatMul ops.
ONNX input:
Before:
After:
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.21.5...1.21.6
Nothing published for this version
Add -odrqt, --output-dynamic-range-quantized-tflite option. While output_integer_quantized_tflite already enables dynamic range quantization output, t
Add -odrqt, --output-dynamic-range-quantized-tflite option.
While output_integer_quantized_tflite already enables dynamic range quantization output, the option also triggers checks for calibration data, which is only required for full integer quantization, and causes errors when no calibration data is provided.
This is undesirable if only dynamic quantization is wanted.
A new option (-odrqt, --output-dynamic-range-quantized-tflite) is added to only enable dynamic range quant output, which doesn't need calibration data.
Before:
$ onnx2tf -i some_model_with_non_regular_input_shape.onnx -oiqt
(other output omitted)
Model conversion started ============================================================
INFO: input_op_name: input shape: [1] dtype: float32
ERROR: For INT8 quantization, the input data type must be Float32. Also, if --custom_input_op_name_np_data_path is not specified, all input OPs must assume 4D tensor image data. INPUT Name: input INPUT Shape: [1] INPUT dtype: float32
After:
$ onnx2tf -i some_model_with_non_regular_input_shape.onnx -odrqt
(other output omitted)
saved_model output started ==========================================================
saved_model output complete!
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
W0000 00:00:1715853625.734342 7691 tf_tfl_flatbuffer_helpers.cc:390] Ignored output_format.
W0000 00:00:1715853625.734397 7691 tf_tfl_flatbuffer_helpers.cc:393] Ignored drop_control_dependency.
Float32 tflite output complete!
W0000 00:00:1715853629.274694 7691 tf_tfl_flatbuffer_helpers.cc:390] Ignored output_format.
W0000 00:00:1715853629.274724 7691 tf_tfl_flatbuffer_helpers.cc:393] Ignored drop_control_dependency.
Float16 tflite output complete!
W0000 00:00:1715853631.535535 7691 tf_tfl_flatbuffer_helpers.cc:390] Ignored output_format.
W0000 00:00:1715853631.535568 7691 tf_tfl_flatbuffer_helpers.cc:393] Ignored drop_control_dependency.
Dynamic Range Quantization tflite output complete!
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.21.3...1.21.4
Significantly faster flatbuffer update speed with -coion option Currently, the copy_onnx_input_output_names_to_tflite flag converts the tflite model t
Significantly faster flatbuffer update speed with -coion option
Currently, the copy_onnx_input_output_names_to_tflite flag converts the tflite model to json for modification, and then convert it back. For large models, the conversions take a long time and consume a large amount of disk space.
Flatbuffers provides Python API allowing reading and writing model files as Python objects directly. We can run flatc --python --gen-object-api to generate Python object API from the downloaded schema file and use it to read the model, add signature defs, and write it back.
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.21.2...1.21.3
Added automatic error correction.
GatherElements
GatherElements by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/630Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.21.1...1.21.2
Bring Constant layers unconnected to the model into the model.
Constant
Bring Constant layers unconnected to the model into the model.
It is assumed that the -nuo option is specified because running onnxsim will remove constants from the ONNX file.
Wrap constants in a Lambda layer and force them into the model.
Convert test
onnx2tf -i toy_with_constant.onnx -nuo -cotof
| ONNX | TFLite |
|---|---|
Inference test
import tensorflow as tf
import numpy as np
from pprint import pprint
interpreter = tf.lite.Interpreter(model_path="saved_model/toy_with_constant_float32.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
interpreter.set_tensor(
tensor_index=input_details[0]['index'],
value=np.ones(tuple(input_details[0]['shape']), dtype=np.float32)
)
interpreter.invoke()
variable_output = interpreter.get_tensor(output_details[0]['index'])
constant_output = interpreter.get_tensor(output_details[1]['index'])
print("=================")
print("Variable Output:")
pprint(variable_output)
print("=================")
print("Constant Output:")
pprint(constant_output)
=================
Variable Output:
array([[-0.02787317, -0.05505124, 0.05421712, 0.03526559, -0.14131774,
0.0019211 , 0.08399964, 0.00433664, -0.00984338, -0.03370604]],
dtype=float32)
=================
Constant Output:
array([1., 2., 3., 4., 5.], dtype=float32)
Fix Typo by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/625
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.20.10...1.21.0
pip install -U sng4onnx>=1.0.4 sne4onnx>=1.0.13 !image
pip install -U sng4onnx>=1.0.4 sne4onnx>=1.0.13
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.20.9...1.20.10
Tensor processing of dynamic shapes is supported.
Tile, Reshape
Tile, dynamic Reshape by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/623Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.20.8...1.20.9
Improved conversion stability of subgraphs of If operations.
If
If operations.onnx2tf \
-i maskrcnn_resnet50_fpn.onnx \
-onimc boxes.55 onnx::Shape_3316 3315 onnx::Loop_3751
If operations. by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/622Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.20.7...1.20.8
Optimization of torch.nn.PixelUnshuffle.
Optimization of torch.nn.PixelUnshuffle.
| ONNX | Before<br>tflite | After<br>tflite |
|---|---|---|
ReduceL1, ReduceL2, ReduceLogSum, ReduceLogSumExp, ReduceMax, ReduceMean, ReduceMin, ReduceProd, ReduceSum, ReduceSumSquaretorch.nn.PixelUnshuffle by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/621Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.20.6...1.20.7
Improved conversion stability when H, W and D of MaxPool and AveragePool contain undefined dimensions.
MaxPool, AveragePool
H, W and D of MaxPool and AveragePool contain undefined dimensions.[N, 3, H, W]Split operation with fixed values.Slice, you won't be able to do proper inferencing.
H, W and D of MaxPool and AveragePool contain undefined dimensions by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/620Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.20.5...1.20.6
Distribute test data files to GitHub releases.
calibration_image_sample_data_20x128x128x3_float32.npy[experimental, Breaking change] tf.keras -> tf_keras
tf.keras -> tf_keraspip install tf-keras~=2.16tf.keras is obsolete.tf.keras -> tf_keras by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/618Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.20.3...1.20.4
ReduceL1, ReduceL2, ReduceLogSum, ReduceLogSumExp, ReduceMax, ReduceMean, ReduceMin, ReduceProd, ReduceSum, ReduceSumSquare
ReduceL1, ReduceL2, ReduceLogSum, ReduceLogSumExp, ReduceMax, ReduceMean, ReduceMin, ReduceProd, ReduceSum, ReduceSumSquare
axes conversion when an unknown dimension order other than NCHW is input to ReduceXXX.axes dimensional transpositions.axes conversion when an unknown dimension order other than NCHW is input to ReduceXXX by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/617Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.20.2...1.20.3
Support for resizing to undefined size (but only in 4D) !image !image
Resize
size (but only in 4D)
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.20.1...1.20.2
onnx2tf.py, common_functions.py
onnx2tf.py, common_functions.py
domain and ir_version.domain and ir_version were rewritten to the latest version during model optimization operation (onnx_graphsurgeon).domain and ir_version by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/612Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.20.0...1.20.1
https://github.com/tensorflow/tensorflow/releases/tag/v2.16.1
TensorFlow==2.16.1, Keras 3.0TensorFlow==2.16.1.Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.19.16...1.20.0
Workaround for bug in TensorFlow quantization logic.
TensorFlow==2.15.0 or TensorFlow==2.15.0.post1.# representative_dataset_gen
def representative_dataset_gen():
for idx in range(data_count):
yield_data_dict = {}
for model_input_name in model_input_name_list:
calib_data, mean, std = calib_data_dict[model_input_name]
normalized_calib_data: np.ndarray = (calib_data[idx] - mean) / std
yield_data_dict[model_input_name] = tf.cast(tf.convert_to_tensor(normalized_calib_data), tf.float32)
yield yield_data_dict
EagerTensor object has no attribute 'astype'.
If you are looking for numpy-related methods, please run the following:
tf.experimental.numpy.experimental_enable_numpy_behavior()
File "/home/xxxx/.local/lib/python3.10/site-packages/tensorflow/python/framework/tensor.py", line 256, in __getattr__
raise AttributeError(
File "/home/xxxx/git/onnx2tf/onnx2tf/onnx2tf.py", line 1436, in representative_dataset_gen
yield_data_dict[model_input_name] = normalized_calib_data.astype(np.float32)
File "/home/xxxx/.local/lib/python3.10/site-packages/tensorflow/lite/python/optimize/calibrator.py", line 101, in _feed_tensors
for sample in dataset_gen():
File "/home/xxxx/.local/lib/python3.10/site-packages/tensorflow/lite/python/optimize/calibrator.py", line 254, in calibrate
self._feed_tensors(dataset_gen, resize_input=True)
File "/home/xxxx/.local/lib/python3.10/site-packages/tensorflow/lite/python/convert_phase.py", line 215, in wrapper
raise error from None # Re-throws the exception.
File "/home/xxxx/.local/lib/python3.10/site-packages/tensorflow/lite/python/convert_phase.py", line 215, in wrapper
raise error from None # Re-throws the exception.
File "/home/xxxx/.local/lib/python3.10/site-packages/tensorflow/lite/python/lite.py", line 735, in _quantize
calibrated = calibrate_quantize.calibrate(
File "/home/xxxx/.local/lib/python3.10/site-packages/tensorflow/lite/python/lite.py", line 1037, in _optimize_tflite_model
model = self._quantize(
File "/home/xxxx/.local/lib/python3.10/site-packages/tensorflow/lite/python/convert_phase.py", line 215, in wrapper
raise error from None # Re-throws the exception.
File "/home/xxxx/.local/lib/python3.10/site-packages/tensorflow/lite/python/convert_phase.py", line 215, in wrapper
raise error from None # Re-throws the exception.
File "/home/xxxx/.local/lib/python3.10/site-packages/tensorflow/lite/python/lite.py", line 1332, in _convert_from_saved_model
return self._optimize_tflite_model(
File "/home/xxxx/.local/lib/python3.10/site-packages/tensorflow/lite/python/lite.py", line 1465, in convert
return self._convert_from_saved_model(graph_def)
File "/home/xxxx/.local/lib/python3.10/site-packages/tensorflow/lite/python/lite.py", line 1093, in _convert_and_export_metrics
result = convert_func(self, *args, **kwargs)
File "/home/xxxx/.local/lib/python3.10/site-packages/tensorflow/lite/python/lite.py", line 1139, in wrapper
return self._convert_and_export_metrics(convert_func, *args, **kwargs)
File "/home/xxxx/git/onnx2tf/onnx2tf/onnx2tf.py", line 1449, in convert
tflite_model = converter.convert()
File "/home/xxxx/git/onnx2tf/onnx2tf/onnx2tf.py", line 2327, in main
model = convert(
File "/home/xxxx/git/onnx2tf/onnx2tf/onnx2tf.py", line 2381, in <module>
main()
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main (Current frame)
return _run_code(code, main_globals, None,
AttributeError: EagerTensor object has no attribute 'astype'.
If you are looking for numpy-related methods, please run the following:
tf.experimental.numpy.experimental_enable_numpy_behavior()
If the modifications are made as suggested by the error message, the main flow of model transformation will be significantly disrupted. The following sentence shall not be added to the logic
tf.experimental.numpy.experimental_enable_numpy_behavior()
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.19.15...1.19.16
Adjusted behavior when Split assumes splitting into multiple sizes.
Split
Adjusted behavior when Split assumes splitting into multiple sizes.
Fixed a bug that caused a list of constants to be transposed to NCHW when the tensor is split by multiple irregular constant sizes.
https://github.com/PINTO0309/onnx2tf/files/14542513/topformer_small_512x512_160k_2x8_ade20k_512in.onnx.zip
ONNX Split operation converts to a tf StridedSlice operation with outputs in the wrong order. #588
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.19.14...1.19.15
Fixed a bug that caused very few elements to diverge to Nan, resulting in inconsistent output. ``` onnx_tensor[0, 3, 1, 26] 97.723495
Celu
Nan, resulting in inconsistent output.onnx_tensor[0, 3, 1, 26]
97.723495
tf_transposed_tensor[0, 3, 1, 26]
nan
TensorFlow operator combinations were reviewed.
onnx2tf -i poc.onnx -cotof
Celu, onnxruntime==1.17.1 by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/603Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.19.13...1.19.14
Gather ONNX Gather changes output shape by removing the singled out dimension. When converting to TF using strided_slice, the extra dimension is kept.
Gather
ONNX Gather changes output shape by removing the singled out dimension. When converting to TF using strided_slice, the extra dimension is kept.
ONNX: [1,50,768] -> Gather (index=0) -> [1,768]
TF: [1,50,768] -> StridedSlice (... ) -> [1,1,768]
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.19.12...1.19.13
fix for float64 error by @khatami-mehrdad in https://github.com/PINTO0309/onnx2tf/pull/593
Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.19.11...1.19.12
Support for 1D MaxPoolWithArgmax
MaxPoolWithArgmax
MaxPoolWithArgmaxmax_pool_with_argmax as standard.MaxPoolWithArgmax by @PINTO0309 in https://github.com/PINTO0309/onnx2tf/pull/580Full Changelog: https://github.com/PINTO0309/onnx2tf/compare/1.19.10...1.19.11
Your coding agent can read these notes before it upgrades. Set up the MCP server →