Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIoU protected divides #8546

Merged
merged 1 commit into from
Jul 11, 2022
Merged

CIoU protected divides #8546

merged 1 commit into from
Jul 11, 2022

Conversation

glenn-jocher
Copy link
Member

@glenn-jocher glenn-jocher commented Jul 11, 2022

Protected divides in IOU function to resolve #8539

πŸ› οΈ PR Summary

Made with ❀️ by Ultralytics Actions

🌟 Summary

Optimization of bounding box intersection-over-union calculations in YOLOv5.

πŸ“Š Key Changes

  • πŸ“ Removed an epsilon (eps) addition in the width and height calculations of bounding boxes.
  • πŸ” Adjusted the v term in the Complete Intersection over Union (CIoU) loss calculation to prevent division by zero during the aspect ratio term computation.

🎯 Purpose & Impact

  • 🧹 The changes serve to clean up the intersection-over-union (IoU) computation, potentially leading to more accurate bounding box evaluations.
  • πŸ‘¨β€πŸ’» For users and developers, these tweaks might result in slight performance enhancements during model training and evaluation, and more precise object detection metrics.

Protected divides in IOU function to resolve #8539
@UnglvKitDe
Copy link
Contributor

UnglvKitDe commented Jul 11, 2022

@glenn-jocher Looks good! What about lines 232/233 and 250? There, it is also possible to divide with 0. Isn't it?:

yolov5/utils/metrics.py

Lines 232 to 233 in 7dafd1c

inter = (torch.min(b1_x2, b2_x2) - torch.max(b1_x1, b2_x1)).clamp(0) * \
(torch.min(b1_y2, b2_y2) - torch.max(b1_y1, b2_y1)).clamp(0)

return iou - (rho2 / c2 + v * alpha) # CIoU

@glenn-jocher
Copy link
Member Author

@UnglvKitDe 233 is not a divide, the \ symbol means line continuation. The c2 on L250 is already protected by the + eps when it is defined in L244:

c2 = cw ** 2 + ch ** 2 + eps # convex diagonal squared

@glenn-jocher glenn-jocher self-assigned this Jul 11, 2022
@UnglvKitDe
Copy link
Contributor

@glenn-jocher You are right, srry didn't read correctly.

@UnglvKitDe
Copy link
Contributor

@glenn-jocher Thanks for the quick fix!

@glenn-jocher glenn-jocher merged commit a84cd02 into master Jul 11, 2022
@glenn-jocher glenn-jocher deleted the fix/iou_nan branch July 11, 2022 14:07
@glenn-jocher
Copy link
Member Author

@UnglvKitDe PR is merged. Thank you for your contributions to YOLOv5 πŸš€ and Vision AI ⭐

Shivvrat pushed a commit to Shivvrat/epic-yolov5 that referenced this pull request Jul 12, 2022
Protected divides in IOU function to resolve ultralytics#8539
ctjanuhowski pushed a commit to ctjanuhowski/yolov5 that referenced this pull request Sep 8, 2022
Protected divides in IOU function to resolve ultralytics#8539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug loss calculation: 0. in pred follows in NaNs in bbox_iou(...)
2 participants