ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
51.25k stars 16.44k forks source link

Adding more images worsen performance on test set. Is this a sneaky overfitting? #12205

Closed baldellimtt closed 1 year ago

baldellimtt commented 1 year ago

Search before asking

Question

I'm using yolov5 to develop an object detector on my own dataset. I was using transfer learning starting from yolov5m, 25k labelled images and I had good performance and generalization capabilities of the model.

Now I've added more over 10k labelled images, changed nothing (same model, same augmentations) and I have this unseen behaviour: recall and precision are good (around 0.9), mAP too (0.95) on train and validation set, but now results on test set are terrible. I can't use the model at the moment, because is missing a lot and "easy" objects that previous models detected.

What am I missing? It seems like adding data had worsen (a lot) performance.

Additional

No response

github-actions[bot] commented 1 year ago

👋 Hello @baldellimtt, 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 a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Requirements

Python>=3.8.0 with all requirements.txt installed including PyTorch>=1.8. 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

YOLOv5 CI

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

Introducing YOLOv8 🚀

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics
glenn-jocher commented 1 year ago

@baldellimtt it's common to encounter unexpected changes in performance after adding more training data to a model. This could be due to overfitting or other factors.

To address this issue, you could try the following steps:

  1. Investigate the data: Check if the newly added data is significantly different from the original dataset. Ensure that the images are properly labeled and that there are no inconsistencies or errors in the annotations.

  2. Analyze the performance metrics: Examine the precision, recall, and mAP on the test set for different object classes. Identify if there are specific classes that are performing poorly after adding more data. This analysis might help pinpoint the problem.

  3. Evaluate model capacity: The model's capacity might not be suitable for handling the increased data. You can try using a larger model variant, such as yolov5l or yolov5x, to see if it improves performance.

  4. Optimize hyperparameters: Adjusting hyperparameters like learning rate, batch size, or augmentation techniques could help improve model performance. Experiment with different settings and monitor the impact on the test set.

  5. Inspect model losses: Analyze the model's training loss curves to check if there are any signs of overfitting. If overfitting is suspected, techniques like regularization (e.g., weight decay or dropout) might be beneficial.

Remember to validate your findings with statistical significance and fine-tune your approach based on the observed results.

Additionally, consider seeking assistance from the YOLO community or the Ultralytics team, as they have extensive experience and can provide valuable insights.

baldellimtt commented 1 year ago

@glenn-jocher thank you for your answer! I just stop to investigate at first point in your answer; it turned up I had a consistent number of images that should be labelled without corresponding txt. I then implemented sanity check script of my dataset and everything was ok.

glenn-jocher commented 1 year ago

Glad to hear that the issue was resolved, @baldellimtt! It's great that you were able to identify the problem with the missing labels. Conducting a sanity check on your dataset is always a good practice to ensure data consistency and accuracy. If you have any more questions or need further assistance, feel free to ask. Keep up the good work!

watertianyi commented 1 year ago

数据集实施了健全性检查脚本 What does it mean that the data set has implemented a sanity check script? I also experienced the over-fitting situation you mentioned, and misjudgments occurred in similar target detection.

baldellimtt commented 1 year ago

@seawater668 it turned out that was not overfitting but mislabeling; I've found that approximatley 200 images had "lost" labels, and there were tens of images not correctly labelled. I have now implemented scripts that check if for every txt file I have the corresponding image; for every background image I apply my best model to check for true positive image that fell in beckground images; that was exactly my problem.

glenn-jocher commented 1 year ago

@seawater668, thank you for sharing your experience. I'm glad to hear that you were able to identify the issue with mislabeling in your dataset. Implementing a sanity check script that verifies if each text file has a corresponding image is a good practice to ensure data integrity. Additionally, utilizing your best model to check for true positive images that fell into the background images is a clever approach to identify misjudgments.

It's important to thoroughly check and validate the quality and accuracy of the labels in your dataset to ensure reliable training results. By addressing the mislabeling issue, you should be able to improve the performance of your model.

If you have any further questions or need assistance, feel free to ask. Keep up the great work!

watertianyi commented 1 year ago

@seawater668事实证明,这不是过度拟合,而是贴错标签;我发现大约 200 张图像“丢失”了标签,并且有数十张图像未正确标记。我现在已经实现了脚本来检查每个 txt 文件是否有相应的图像;对于每张背景图像,我都会应用最好的模型来检查背景图像中是否有真正的正图像;这正是我的问题。

There were a lot of similar data misdetections during my test. I don’t know how to solve it. Can I increase the data set?

glenn-jocher commented 1 year ago

@seawater668 increasing the dataset size can be a potential solution to address misdetections. By adding more diverse and representative data to your training set, you provide the model with a better understanding of the objects it needs to detect. This can help improve its accuracy and robustness.

However, before increasing the dataset size, it's important to ensure the quality and accuracy of the existing data. Validate the labels and annotations to avoid misjudgments and mislabeling. Implementing a robust data preprocessing pipeline, including data augmentation techniques, can also help improve the model's performance.

Additionally, consider other factors that might be influencing the misdetections, such as model architecture, hyperparameters, or training strategies. Experimenting with different model variants, adjusting hyperparameters, and optimizing the training process might also lead to improved results.

If you have further questions or need more specific recommendations, please provide more details about your dataset, training setup, and any other relevant information.

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 ⭐