THU-MIG / yolov10

YOLOv10: Real-Time End-to-End Object Detection
https://arxiv.org/abs/2405.14458
GNU Affero General Public License v3.0
9.5k stars 900 forks source link

ONNX to Tflite conversion #252

Open rabion1234 opened 3 months ago

rabion1234 commented 3 months ago

i converted yolov10x model to ONNX by !yolo export model=/content/ch/yolov10/runs/detect/train/weights/best.pt format=onnx half=True simplify opset=13 workspace=16 device=cpu

after i want to convert my model to tflite by code: !onnx2tf -i "/content/drive/MyDrive/CamScanner/yolov10/runs/detect/train/weights/best.onnx" -o "yolov10s_exported"

but i am getting this error: TypeError: You are passing KerasTensor(type_spec=TensorSpec(shape=(1, 7, 7, 640), dtype=tf.float32, name=None), name='tf.math.multiply_367/Mul:0', description="created by layer 'tf.math.multiply_367'"), an intermediate TF-Keras symbolic input/output, to a TF API that does not allow registering custom dispatchers, such as tf.cond, tf.function, gradient tapes, or tf.map_fn. TF-Keras Functional model construction only supports TF API calls that do support dispatching, such as tf.math.add or tf.reshape. Other APIs cannot be called directly on symbolic Kerasinputs/outputs. You can work around this limitation by putting the operation in a custom TF-Keras layer call and calling that layer on this symbolic input/output.

ERROR: input_onnx_file_path: /content/drive/MyDrive/CamScanner/yolov10/runs/detect/train/weights/best.onnx ERROR: onnx_op_name: /model.11/Resize 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.

R4Ajeti commented 1 month ago

I am having same error on macOS 14 Python 3.12.2 and Python 3.10.13

shivanshu11092003 commented 4 weeks ago

same error please provide solution

blackCmd commented 2 weeks ago

Same error.

moyans commented 1 day ago

Dimensions must be equal, but are 32 and 16 for '{{node tf.math.add_5/Add}} = AddV2[T=DT_FLOAT](Placeholder, Placeholder_1)' with input shapes: [1,16,160,32], [1,16,160,16].

Call arguments received by layer "tf.math.add_5" (type TFOpLambda): • x=tf.Tensor(shape=(1, 16, 160, 32), dtype=float32) • y=tf.Tensor(shape=(1, 16, 160, 16), dtype=float32) • name='/model.2/m.0/Add'

ERROR: input_onnx_file_path: models/yolov10n.onnx ERROR: onnx_op_name: /model.2/m.0/Add 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.