THU-MIG / yolov10

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

Model Conversion to NCNN: torch.topk Not Supported #279

Open nerbivol opened 2 weeks ago

nerbivol commented 2 weeks ago

I converted my model to NCNN using the following command:

!yolo export model=jameslahm/yolov10n format=ncnn

The output was:

...
############# pass_level1
############# pass_level2
############# pass_level3
############# pass_level4
############# pass_level5
############# pass_ncnn
BinaryOp remainder not supported yet
BinaryOp floor_divide not supported yet
ignore torch.topk torch.topk_57 param dim=-1
ignore torch.topk torch.topk_57 param k=300
ignore torch.topk torch.topk_57 param largest=True
ignore torch.topk torch.topk_57 param sorted=True
ignore torch.gather torch.gather_39 param dim=1
ignore torch.gather torch.gather_40 param dim=1
ignore torch.topk torch.topk_58 param dim=-1
ignore torch.topk torch.topk_58 param k=300
ignore torch.topk torch.topk_58 param largest=True
ignore torch.topk torch.topk_58 param sorted=True
ignore torch.gather torch.gather_41 param dim=1
ignore Tensor.to Tensor.to_8 param copy=False
ignore Tensor.to Tensor.to_8 param dtype=torch.float
NCNN: export success ✅ 10.9s, saved as 'yolov10n_ncnn_model' (9.0 MB)

Export complete (15.4s)
Results saved to /content
Predict:         yolo predict task=detect model=yolov10n_ncnn_model imgsz=640  
Validate:        yolo val task=detect model=yolov10n_ncnn_model imgsz=640 data=None  
Visualize:       https://netron.app
💡 Learn more at https://docs.ultralytics.com/modes/export

However, when I tried to run a prediction with the command:

!yolo predict task=detect model=yolov10n_ncnn_model source=bus.jpg

I received the following error:

Ultralytics YOLOv8.1.34 🚀 Python-3.10.12 torch-2.3.0+cu121 CUDA:0 (Tesla T4, 15102MiB)
Loading yolov10n_ncnn_model for NCNN inference...
layer torch.topk not exists or registered

Here's an image of the model visualization showing the torch.topk layers:

image

Are there any possible ways to replace or bypass torch.topk in this model?


leonnil commented 1 week ago

Thank you for your interest! Does this issue https://github.com/THU-MIG/yolov10/issues/196 help?