ultralytics / yolov5

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.76k stars 16.34k forks source link

Error During TensorFlow SavedModel and TFLite Export: TFDetect.__init__() got multiple values for argument 'w' and 'NoneType' object has no attribute 'outputs' #13303

Open computerVision3 opened 2 months ago

computerVision3 commented 2 months ago

Search before asking

Question

I encountered errors while attempting to export a YOLOv5 model to TensorFlow SavedModel and TFLite formats. The model is a YOLOv5 with FPN, and the export process fails with the following errors:

TensorFlow SavedModel: export failure ❌ 1.5s: TFDetect.__init__() got multiple values for argument 'w'

TensorFlow Lite: export failure ❌ 0.0s: 'NoneType' object has no attribute 'call' Traceback (most recent call last): File "/home/ai/Masood/Pipes/yolov5_old/export.py", line 1542, in <module> main(opt) File "/home/ai/Masood/Pipes/yolov5_old/export.py", line 1537, in main run(**vars(opt)) File "/home/ai/.local/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context return func(*args, **kwargs) File "/home/ai/Masood/Pipes/yolov5_old/export.py", line 1450, in run add_tflite_metadata(f[8] or f[7], metadata, num_outputs=len(s_model.outputs)) AttributeError: 'NoneType' object has no attribute 'outputs'

Additional

yolov5fpn.yaml

nc: 80 # number of classes depth_multiple: 1.0 # model depth multiple width_multiple: 1.0 # layer channel multiple anchors:

YOLOv5 v6.0 backbone

backbone: [ [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 [-1, 3, C3, [128]], [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 [-1, 6, C3, [256]], [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 [-1, 9, C3, [512]], [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 [-1, 3, C3, [1024]], [-1, 1, SPPF, [1024, 5]], # 9 ]

YOLOv5 v6.0 FPN head

head: [ [-1, 3, C3, [1024, False]], # 10 (P5/32-large)

[-1, 1, nn.Upsample, [None, 2, "nearest"]],
[[-1, 6], 1, Concat, [1]],  # cat backbone P4
[-1, 1, Conv, [512, 1, 1]],
[-1, 3, C3, [512, False]],  # 14 (P4/16-medium)

[-1, 1, nn.Upsample, [None, 2, "nearest"]],
[[-1, 4], 1, Concat, [1]],  # cat backbone P3
[-1, 1, Conv, [256, 1, 1]],
[-1, 3, C3, [256, False]],  # 18 (P3/8-small)

# Add a new layer for P2/4 detection
[-1, 1, nn.Upsample, [None, 2, "nearest"]],
[[-1, 2], 1, Concat, [1]],  # cat backbone P2
[-1, 1, Conv, [128, 1, 1]],
[-1, 3, C3, [128, False]],  # 22 P2/4-small

# [[18, 14, 10], 1, Detect, [nc, anchors, [128, 256, 512, 1024]]],  # Detect(P3, P4, P5)
[[22, 18, 14, 10], 1, Detect, [nc, anchors, [128, 256, 512, 1024]]]  # Detect(P2, P3, P4, P5)

]

glenn-jocher commented 2 months ago

@computerVision3 it seems you're encountering issues with exporting to TensorFlow formats. Please ensure you're using the latest YOLOv5 version and verify your custom model configuration aligns with the export requirements. If the issue persists, consider simplifying your model or checking for any recent updates or fixes in the repository. For further guidance, refer to the YOLOv5 export documentation.