Self-Created Tools to convert ONNX files (NCHW) to TensorFlow/TFLite/Keras format (NHWC). The purpose of this tool is to solve the massive Transpose extrapolation problem in onnx-tensorflow (onnx-tf). I don't need a Star, but give me a pull request.
Add an ultra-slow conversion mode to strictly avoid shape unmatch errors and precision errors.
Background
Since the internal processing has already implemented a number of fairly complex workarounds to avoid conversion errors, we have not dared to implement a correction process for accuracy errors at this time in order not to further increase the complexity of the logic. Instead, I have implemented a mechanism whereby the user visually identifies which operation's channel transpositions cause problems, and the user changes the behavior of the tool himself.
However, I cannot overlook the situation where accuracy errors remain despite successful model transformations, and I hope to eradicate them in the future. The work to change the behavior of the tool by the users themselves with the users' visibility of the problem areas is very costly.
Since the internal processing mechanism needs to be significantly revised, we intend to implement many additional test modifications gradually in minor version upgrades to the extent that they do not affect the existing processing.
Idea
Add all OPs of ONNX to the output OP of the graph.
Run ONNX inference with dummy tensor only once to get the sample inference results for all OPs.
Always compare the contents of the ONNX output tensor and TensorFlow output tensor before converting each OP.
Search for the channel arrangement with the lowest accuracy error.
The Transpose OP is excluded from the search because the value to be compared does not change.
Not implemented for Constant and ConstantOfShape.
Other than the above, OPs that do not involve conversion of values are excluded from processing.
For error correction, the same method as for pre_process_transpose_perm is used to check all combinations that pre-transpose the input tensor to the corresponding OP.
If the target OP is specified in parameter_replacement.json, omit processing.
Remove any intrinsic processing already implemented in MatMul.
OPs with both attribute and tensor values, such as Softmax, attempt correction in the following order: attribute value change first, then tensor transposition.
Issue Type
Others
onnx2tf version number
1.7.x
onnx version number
1.13.0
tensorflow version number
2.10.0
Download URL for ONNX
N/A
Parameter Replacement JSON
Description
Background
Since the internal processing has already implemented a number of fairly complex workarounds to avoid conversion errors, we have not dared to implement a correction process for accuracy errors at this time in order not to further increase the complexity of the logic. Instead, I have implemented a mechanism whereby the user visually identifies which operation's channel transpositions cause problems, and the user changes the behavior of the tool himself.
However, I cannot overlook the situation where accuracy errors remain despite successful model transformations, and I hope to eradicate them in the future. The work to change the behavior of the tool by the users themselves with the users' visibility of the problem areas is very costly.
Since the internal processing mechanism needs to be significantly revised, we intend to implement many additional test modifications gradually in minor version upgrades to the extent that they do not affect the existing processing.
Idea
Transpose
OP is excluded from the search because the value to be compared does not change.Constant
andConstantOfShape
.pre_process_transpose_perm
is used to check all combinations that pre-transpose the input tensor to the corresponding OP.parameter_replacement.json
, omit processing.MatMul
.Softmax
, attempt correction in the following order: attribute value change first, then tensor transposition.