ultralytics / yolov5

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

Reducing False Positive cases #6731

Closed Sauravpandey98 closed 2 years ago

Sauravpandey98 commented 2 years ago

Search before asking

Question

Hi to all, I am working on the problem of detecting boxes in warehouses.I am using yolov5 for object detection and it is working fine in most of the cases.But I am getting a particular kind of false detections that I am not able to remove.Example of of such case is shown below.Any suggestion to solve this problem would be appreciated.

Ground Truth Ground Truth

Prediction Prediction

Additional

No response

github-actions[bot] commented 2 years ago

👋 Hello @Sauravpandey98, 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 support@ultralytics.com.

Requirements

Python>=3.7.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 commented 2 years ago

@Sauravpandey98 👋 Hello! Thanks for asking about improving YOLOv5 🚀 training results.

Most of the time good results can be obtained with no changes to the models or training settings, provided your dataset is sufficiently large and well labelled. If at first you don't get good results, there are steps you might be able to take to improve, but we always recommend users first train with all default settings before considering any changes. This helps establish a performance baseline and spot areas for improvement.

If you have questions about your training results we recommend you provide the maximum amount of information possible if you expect a helpful response, including results plots (train losses, val losses, P, R, mAP), PR curve, confusion matrix, training mosaics, test results and dataset statistics images such as labels.png. All of these are located in your project/name directory, typically yolov5/runs/train/exp.

We've put together a full guide for users looking to get the best results on their YOLOv5 trainings below.

Dataset

COCO Analysis

Model Selection

Larger models like YOLOv5x and YOLOv5x6 will produce better results in nearly all cases, but have more parameters, require more CUDA memory to train, and are slower to run. For mobile deployments we recommend YOLOv5s/m, for cloud deployments we recommend YOLOv5l/x. See our README table for a full comparison of all models.

YOLOv5 Models

Training Settings

Before modifying anything, first train with default settings to establish a performance baseline. A full list of train.py settings can be found in the train.py argparser.

Further Reading

If you'd like to know more a good place to start is Karpathy's 'Recipe for Training Neural Networks', which has great ideas for training that apply broadly across all ML domains: http://karpathy.github.io/2019/04/25/recipe/

Good luck 🍀 and let us know if you have any other questions!

Guttappa1238 commented 2 years ago

Hi @Sauravpandey98, Give details about size of the dataset and training results/graphs if possible, so that everybody will understand your issue.

For now my suggestion is try to run the detection using yolov5m_Objects365.pt by passing --classes 20 (i.e Storage box). i hope you will get better results.

python path/to/detect.py --weights yolov5m_Objects365.pt --classes 20

Sauravpandey98 commented 2 years ago

yeah thanks @Guttappa1238 and @glenn-jocher for responding. @Guttappa1238 I have tried with yolov5m_Objects365 model .But it is not performing well.

In my dataset , I have only one class i.e "box" as you can see from the example images given in issue.Firstly I have trained a base model using a dataset of 1200 training images and manually tuned the hyper-parameters to find best model.After this I fine tuned the best model on 1000 training images.These prediction result are using the fine tuned model.

Now In my case most of false positive is occurring when the model picks wrinkled polythene wrapping or tapes as edges.So I am asking what changes should I do in my dataset or training strategy to decrease these kind of false positives.

HAN-007 commented 2 years ago

hello, can I learn the original version of the pictures and which model you are using? (image without bbox)

anujdutt9 commented 2 years ago

@Sauravpandey98 Couple of suggestions that might help:

  1. Try to add more images if possible. Increasing the dataset size should help.
  2. Make sure that your annotations are correct and don't have any False labels.
  3. Try to begin with a pre-trained model provided in this repository like a COCO pre-trained YOLOv5s/m/l model and finetune it with your dataset as a whole instead of in 2 phases.
  4. Once you have a good base model then try to make changes to the hyperparameters to see which ones give you the most gains.
  5. Under utils/augmentations.py try to play around with augmentations, specifically under albumentations class. One example could be adding random sun flare, that could mimic the lights falling on the tapes on the boxes that might be a potential cause for the issue. https://albumentations.ai/docs/api_reference/augmentations/transforms/#albumentations.augmentations.transforms.RandomSunFlare
  6. The default fitness will favor mutations that produce higher mAP@0.5:0.95 mostly. You can shift this to F1 or mAP@0.5 to reduce the influence of accurate bounding boxes by modifying the fitness function here: https://github.com/ultralytics/yolov5/blob/747c2653eecfb870b1ed40b1e00e0ef209b036e9/utils/metrics.py#L12-L16

Hope this helps.

Sauravpandey98 commented 2 years ago

@anujdutt9 thanks for suggestions.But I have a query regarding mAP values.So on observation I found that even if the model starts overfitting ( generally it occurs when object loss starts increasing),the mAP@0.5:0.95 continues to increase while the mAP@0.5 remains stable.So suppose If I give same weightage to both the mAP values to calulate fitness,the best fitness would still not be corresponds to minimum loss value. So should I prefer fitness value here or should I use those weights that has max mAP value along with minimum loss.For example in this case: W B Chart 10_03_2022, 11_53_39 W B Chart 10_03_2022, 11_53_21 W B Chart 10_03_2022, 11_53_00 W B Chart 10_03_2022, 11_52_09

glenn-jocher commented 2 years ago

@Sauravpandey98 sure. Some metrics like mAP@0.5:0.95 are more influenced by regression loss than obj loss and vice versa. The default fitness function is most weighted towards the main COCO metric of mAP@0.5:0.95: https://github.com/ultralytics/yolov5/blob/6dd82c025298d219a1eb1fe8e486fb99d5324d34/utils/metrics.py#L15-L19

Ideally all losses would begin to overfit in concert, but in practice each loss will overfit at a different point in training (assuming you train long enough). You can try to balance these manually using the loss gain hyperparameters, or evolve hyperparameters: https://github.com/ultralytics/yolov5/blob/6dd82c025298d219a1eb1fe8e486fb99d5324d34/data/hyps/hyp.scratch-low.yaml#L13-L17

Sauravpandey98 commented 2 years ago

Thanks @glenn-jocher for these insights into loss values.But can you please give me a suggestion? So from the graphs you can see that object loss value started to go up from 100 epoch.While according to above mentioned fitness score I am getting best weights at 196 epoch.

So,should I use weights at 100 epoch or weights at 196 epoch for prediction?

glenn-jocher commented 2 years ago

@Sauravpandey98 not sure I understand your question. If you want the weights that produced the best mAP on the validation set use best.pt. That's the entire point of best.pt.