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

Yolov5 loss function #6316

Closed
1 task done
hyeonmin11 opened this issue Jan 16, 2022 · 12 comments
Closed
1 task done

Yolov5 loss function #6316

hyeonmin11 opened this issue Jan 16, 2022 · 12 comments
Labels
question Further information is requested Stale

Comments

@hyeonmin11
Copy link

Search before asking

Question

Does yolov5 loss function uses CIOU loss?
I just thought yolov5 deals with GIOU loss or iou,
But in loss.py Computeloss,
iou = bbox_iou(pbox.T, tbox[i], x1y1x2y2=False, CIoU=True) # iou(prediction, target)
lbox += (1.0 - iou).mean() # iou loss

I saw this.

Additional

No response

@hyeonmin11 hyeonmin11 added the question Further information is requested label Jan 16, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jan 16, 2022

👋 Hello @hyeonmin11, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

@hyeonmin11 seems like you've answered your own question.

@hyeonmin11
Copy link
Author

Thanks

@github-actions
Copy link
Contributor

github-actions bot commented Feb 17, 2022

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐!

@YasmineeBa
Copy link

YasmineeBa commented Apr 13, 2023

Hi, Can someone tell me wich loss function yolov5 used?

@glenn-jocher
Copy link
Member

Hello @YasmineeBa, YOLOv5 by default uses the GIoU loss function, which stands for Generalized Intersection over Union.

The loss function is defined in yolov5/models/yolo.py file, which can be found at https://github.com/ultralytics/yolov5/blob/master/models/yolo.py on line 252.

However, the loss function can also be configured to use other variants of IoU-loss including CIoU-loss and DIoU-loss by changing the configuration file for YOLOv5.

Please refer to https://docs.ultralytics.com/yolov5/loss for more information on YOLOv5’s loss function.

@YasmineeBa
Copy link

YasmineeBa commented Apr 14, 2023 via email

@glenn-jocher
Copy link
Member

You're welcome, @YasmineeBa! If you have any other questions or concerns, feel free to reach out again.

@imPdhar
Copy link

imPdhar commented Mar 5, 2024

Hi @glenn-jocher, Sorry for asking so many questions, Just doing some studying :)! In this issue you say you use GIoU but according to information from other issues I gather you have said that you use MSE for Regression loss, BCE/Focal for Confidence loss, and CE for classification. May I know how GIoU is involved in this?

@glenn-jocher
Copy link
Member

Hello @imPdhar, no worries at all! Questions are a great way to learn, and I'm here to help. 😊

You're correct in your understanding. In YOLOv5, the loss function is a combination of several components tailored to different aspects of the detection task:

  1. Box Regression Loss: This is where GIoU (Generalized Intersection over Union) comes into play. GIoU loss is used to measure the discrepancy between the predicted bounding boxes and the ground truth bounding boxes. It's an improvement over traditional IoU by taking into account the size and shape of the boxes, even when they don't overlap.

  2. Object Confidence Loss: This component uses Binary Cross-Entropy (BCE) or Focal Loss to measure the error in predicting the presence of an object within a bounding box. It helps the model learn to accurately predict the confidence score of having an object within the predicted bounding box.

  3. Classification Loss: For the classes of the detected objects, we use Cross-Entropy (CE) loss to measure the error in classifying the objects into their respective categories.

The combination of these loss components allows YOLOv5 to effectively learn to detect and classify objects in images. GIoU specifically helps in refining the accuracy of the bounding box predictions, making it a crucial part of the overall loss function.

I hope this clarifies how GIoU is involved alongside other loss components in YOLOv5. If you have more questions, feel free to ask!

@litnguyen
Copy link

Thank you @glenn-jocher i use yolov5s for my university capstone project. Appriciate you for actively clarifying all questions

@glenn-jocher
Copy link
Member

@litnguyen you're very welcome! I'm delighted to hear YOLOv5s is part of your university capstone project. If you have any more questions or need further clarification as you progress, don't hesitate to reach out. Best of luck with your project! 😊👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

5 participants