meituan / YOLOv6

YOLOv6: a single-stage object detection framework dedicated to industrial applications.
GNU General Public License v3.0
5.72k stars 1.04k forks source link

Issue with ONNX to TFLite Conversion: No Detection Results #929

Open hamedgorji opened 1 year ago

hamedgorji commented 1 year ago

Search before asking

Description

Hi guys,

I encountered a similar issue while working with Yolov8. The problem arises during the conversion of the .pt file to a fully quantized .tflite file for inference, as it fails to detect anything. You can find the related pull requests here:

https://github.com/ultralytics/ultralytics/pull/1695 https://github.com/ultralytics/ultralytics/pull/1447

I'm now experiencing the same problem with Yolov6. Could you please help me resolve this issue?

I used the following CL to train and export my model

python tools/train.py --batch 32 --epochs 500 --img-size 320 --conf configs/yolov6n.py --data data/my_dataset.yaml --name test_train --device 0

python deploy/ONNX/export_onnx.py --img 320 --weights runs/train/test_train/weights/best_ckpt.pt --simplify --device 0

Then

ONNX to TFlite
!onnx2tf -i '/content/drive/MyDrive/Model Conversion/best_ckpt.onnx' -cind 'images' '/content/drive/MyDrive/Model Conversion/calibdata.npy' "[[[[0, 0, 0]]]]" "[[[[255, 255,  255]]]]" -oiqt -qt per-tensor

Thanks

Use case

No response

Additional

No response

Are you willing to submit a PR?

hamedgorji commented 1 year ago

Hi @motokimura, I tried the same idea from the yolov8 problem here, but normalizing the input did not work. Have you tried that method on yolov6? I normalized the pred_bboxes (shape of 1, 2100, 4) in effidehead.py (YOLOv6/yolov6/models/effidehead.py) by adding

img_size = torch.tensor([img_w, img_h, img_w, img_h], device=pred_bboxes.device).reshape(1, 1, 4)
pred_bboxes/=img_size

Thanks