ultralytics / yolov5

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

Detecting Two Objects with the Same Center #8068

Closed nadavkirsch-6over6 closed 2 years ago

nadavkirsch-6over6 commented 2 years ago

Search before asking

Question

Hello,

I have encountered a problem while working with yolov5 on my custom data. The problem is - If there are two objects that have the same center point, the model fails to detect the inner object. The model detects both objects with low confidence and in the exact same shape. I found that increasing the imgsz might help but still, the results are pretty bad. I wanted to ask if there is a known solution to this problem or any ideas you might have since I didn't find any solutions. I am attaching two images, one with the original bounding boxes, and the other with the predicted bounding boxes. In these images I am trying to detect the eye and the iris, and their bounding boxes share almost the exact same center point.

Thank you!

nadav nadav

Additional

No response

github-actions[bot] commented 2 years ago

👋 Hello @nadavkirsch-6over6, 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

@nadavkirsch-6over6 👋 Hello! Thanks for asking about improving YOLOv5 🚀 training results.

Identical centerpoints may result in ambiguity about which box to predict. Some architectures like FCOS attempt to solve this by configuring the prediction space differently, but before considering any exotic solutions I would review the recommendations below to verify your dataset is sufficiently aligned with best practices.

Screen Shot 2022-06-01 at 2 15 41 PM

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!

gillonba commented 2 years ago

How important is it that... you only look once? Would it be a problem to split the job into two models, run the detection with each, and then combine the results?

Alternatively, since you appear to be detecting an eye in addition to a specific part of the eye, perhaps you could detect the eye, cut out the portion of the image in the detection, and then run your second stage detector on just the image of the eye? It would be for more expensive computationally, but much simpler to see what is really happening. Additionally it would be easy to collect a lot of source images of just eyes to build your iris dataset. I am doing something similar to do different classifications on detected objects and am happy with the initial results

github-actions[bot] commented 2 years ago

👋 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 ⭐!

glenn-jocher commented 11 months ago

@gillonba great questions! 🤔

The "only look once" nature of YOLO refers to its approach of predicting all bounding boxes and class probabilities from a single forward pass of the network, combining high levels of precision with real-time speeds. While running two models and combining results can work, it would indeed be more computationally expensive and time-consuming compared to a single, optimized model.

Your alternative approach of first detecting the entire eye and then running a second stage detector on just the eye image is a promising strategy! This two-stage detection method could potentially simplify the detection process and even improve the overall accuracy, while also allowing for easier dataset collection as you mentioned.

Your results sound impressive! It's great to hear that you are happy with the initial outcomes. Keep up the great work and don't hesitate to reach out if you need further assistance!