PINTO0309 / onnx2tf

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.
MIT License
706 stars 73 forks source link

Supports parameter substitution for post-processing of `Conv` #704

Closed PINTO0309 closed 1 month ago

PINTO0309 commented 1 month ago

1. Content and background

2. Summary of corrections

3. Before/After (If there is an operating log that can be used as a reference)

4. Issue number (only if there is a related issue)

marcoschepis commented 1 month ago

Is this the possiblity to add our own weights after the quantization?

PINTO0309 commented 1 month ago

No. The -prf option only does simple tensor transposition or some other OP substitutions. onnx2tf does not have the ability to add weights. I think adding weights when converting a model with onnx2tf is beyond the scope of the tool's responsibility.

Therefore, it is better to process ONNX files directly. https://github.com/ZhangGe6/onnx-modifier https://github.com/PINTO0309/simple-onnx-processing-tools

marcoschepis commented 1 month ago

Ah thank you, the problem is that when you modify the ONNX and than convert it in tflite, the weights get changed automatically. I was trying to find a way to have the weights I want in the tflite.

PINTO0309 commented 1 month ago

Since the quantization flow is only provided via the TFLiteConverter API, you will likely need to rewrite the Flatbuffer directly after quantization to achieve what you want.

marcoschepis commented 1 month ago

Thank you very much, you've been so much helpful

marcoschepis commented 1 month ago

Since the quantization flow is only provided via the TFLiteConverter API, you will likely need to rewrite the Flatbuffer directly after quantization to achieve what you want.

Sorry to bother you again, I wasn't able to find how to implement the modification of a onnx or tflite via the flatbuffers as you suggested. Cen you explain better? Thank you very much in advance.

PINTO0309 commented 1 month ago

here https://github.com/PINTO0309/onnx2tf/blob/67d5b4c94bef576270e32b5b214f7f8cfcdb57d9/onnx2tf/utils/common_functions.py#L4541

marcoschepis commented 1 month ago

this function writes the operations name, i would like to modify the weights of a layer