ultralytics / ultralytics

NEW - YOLOv8 🚀 in PyTorch > ONNX > OpenVINO > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
28.08k stars 5.58k forks source link

parameter setting questions yolo8 (box loss gain) #933

Closed noahweber1-debug closed 1 year ago

noahweber1-debug commented 1 year ago

Search before asking

Question

There are 3 hyperparameters that ought to be set:

| box | 7.5 | box loss gain
| cls | 0.5 | cls loss gain (scale with pixels)
| dfl | 1.5 | dfl loss gain

I understand conceptually what these losses are but what I dont understand is:

  1. What do these concrete values represent (i.e. what this 7.5 gain for box loss)
  2. How much should we change this. This question is particularly interesting because I see very different values set for this. For example here the box loss gain was set to 0.05 https://github.com/ultralytics/yolov5/discussions/7319

Additional

No response

Laughing-q commented 1 year ago

@noahweber1-debug hi, as we redesigned the loss part in v8 and the loss values are different from v5 so we also need to re-balanced the losses by redesigned the gains. :)

ziyaxuanyi commented 1 year ago

@Laughing-q I used yolov8m-seg.yaml to train a model on my own dataset which has 4 classes. And all training parameters are default parameters except nc=4.

the result of mask looks good. But the conf of boxes is very low. Do you have any suggestions to improve the conf of boxes?Or what training parameters should I modify?

Should I modify the loss gain to re-balanced the losses?

Laughing-q commented 1 year ago

@ziyaxuanyi

Should I modify the loss gain to re-balanced the losses?

mostly you don't need to modify the loss gain.

Do you have any suggestions to improve the conf of boxes?Or what training parameters should I modify?

this depends on many factors, I recommend you to read the tips in v5 which also applies to v8 models and segmentation. :)

ziyaxuanyi commented 1 year ago

@Laughing-q thank for your answer.

github-actions[bot] commented 1 year ago

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

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 YOLO 🚀 and Vision AI ⭐

Ashutosh1995 commented 6 months ago

@Laughing-q what would you suggest in case my segmentation masks are either convex polygons (rectangle) or concave polygons in the ground truth. I am facing overfitting and I was thinking maybe changing the loss parameters can help there?

Ashutosh1995 commented 3 months ago

@glenn-jocher can you please help in this regard?

glenn-jocher commented 3 months ago

@Ashutosh1995 Adjusting loss parameters might help, but it's also essential to consider other strategies to combat overfitting. You could try implementing data augmentation, adjusting the learning rate, or increasing dropout rates. Experimenting with these methods could provide more stability during training without solely relying on modifying loss gains.

gusmendess commented 2 months ago

@glenn-jocher I'm doing a medical project and for me recall is the most important metric. Setting the parameters like this is a good option?

| box | 10 | box loss gain | cls | 1.0 | cls loss gain (scale with pixels) | dfl | 1.0 | dfl loss gain

glenn-jocher commented 2 months ago

Hi @gusmendess,

It's great to hear about your medical project! Prioritizing recall is crucial in such applications. Adjusting the loss gains can indeed help, but it's essential to balance them carefully. Your proposed settings:

Parameter Value Description
box 10 Box loss gain
cls 1.0 Classification loss gain
dfl 1.0 Distribution focal loss gain

These settings increase the emphasis on the box loss, which might help in improving recall by making the model more sensitive to detecting objects. However, it's also important to monitor the precision to ensure that the increase in recall doesn't lead to too many false positives.

Additionally, consider the following tips to further enhance recall:

  1. Data Augmentation: Apply techniques like rotation, scaling, and flipping to increase the variability in your training data.
  2. Learning Rate: Fine-tune the learning rate to ensure stable training.
  3. Validation Strategy: Use a validation set that closely resembles your test conditions to better gauge model performance.

Experimenting with these parameters and strategies should help you find the optimal balance for your specific dataset and requirements. If you encounter any issues or need further assistance, feel free to share more details or a reproducible example.

Best of luck with your project! 🚀

For more detailed guidance, you can refer to our training tips.