laugh12321 / TensorRT-YOLO

🚀 TensorRT-YOLO: Supports YOLOv3, YOLOv5, YOLOv6, YOLOv7, YOLOv8, YOLOv9, YOLOv10, and PP-YOLOE using TensorRT acceleration with EfficientNMS, CUDA Kernels and CUDA Graphs!
https://github.com/laugh12321/TensorRT-YOLO
GNU General Public License v3.0
383 stars 50 forks source link

[Bug]: AttributeError in YOLOv9 Model Export: 'AutoShape' object has no attribute 'fuse' #8

Closed yaoandy107 closed 4 months ago

yaoandy107 commented 4 months ago

Thanks for your great work! I'm trying to convert the gelan-c to tensorRT, but get the error below

Using cache found in /root/.cache/torch/hub/WongKinYiu_yolov9_main
YOLO 🚀 2024-3-15 Python-3.10.12 torch-2.1.0+cu121 CUDA:0 (Tesla T4, 14931MiB)

Fusing layers... 
Model summary: 387 layers, 25288768 parameters, 0 gradients, 102.1 GFLOPs
Adding AutoShape... 
Traceback (most recent call last):
  File "/content/TensorRT-YOLO/python/export/yolov9/export.py", line 234, in <module>
    Exporter(opt)(model)
  File "/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/content/TensorRT-YOLO/python/export/yolov9/export.py", line 96, in __call__
    model = model.fuse()
  File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1695, in __getattr__
    raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
AttributeError: 'AutoShape' object has no attribute 'fuse'

This is the command I executed

python python/export/yolov9/export.py -w gelan-c.pt -o output -s --dynamic
laugh12321 commented 4 months ago

I followed the instructions you provided and successfully replicated the process. I downloaded the model from YOLOv9, and the execution proceeded smoothly.

I guess the issue might be with model = model.fuse(). Could you please comment out this line?

图片

yaoandy107 commented 4 months ago

@laugh12321 Thank you for your quick response! I create a Colab for you to reproduce https://colab.research.google.com/drive/1QciXnx2nwHkFs2DWOhpTx_V6v1Rp57HX?usp=sharing

yaoandy107 commented 4 months ago

@laugh12321 Thank you very much! Commenting out the line worked! Besides, what is the line for? Will it affect the outcome?

laugh12321 commented 4 months ago

@yaoandy107 You're welcome! I'm glad commenting out the line resolved the issue. Regarding your question, is the "line" you mentioned referring to the 4 warnings displayed in the log? If so, those warnings shouldn't affect the accuracy of the model; they're just notifications.

yaoandy107 commented 4 months ago

@laugh12321 Sorry for not making it clear earlier. I am asking about the line model = model.fuse().

laugh12321 commented 4 months ago

@yaoandy107 Got it, thanks for clarifying! The fuse() function is used to merge convolutional (conv) and batch normalization (bn) layers in order to speed up the model's inference time without affecting accuracy.

laugh12321 commented 4 months ago

@laugh12321 Thank you for your quick response! I create a Colab for you to reproduce https://colab.research.google.com/drive/1QciXnx2nwHkFs2DWOhpTx_V6v1Rp57HX?usp=sharing

Fixed at Fix AttributeError in YOLOv9 Model Export