-
-
Notifications
You must be signed in to change notification settings - Fork 16.1k
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
How do Yolo target assignments to anchors work? #12978
Comments
Hi there! 😊 It sounds like you're diving deep into the workings of YOLOv5 -- that's fantastic! Your understanding is on the right track. YOLOv5 assigns targets to anchors based on the best overlap (IoU, or Intersection over Union) between the target and the predefined anchor shapes. Indeed, each grid cell is initially responsible for detecting objects based on the anchors associated with it. This setup could potentially lead to the issue you mentioned with closely packed small objects. However, YOLOv5 implements several improvements and techniques that enhance its ability to detect small or closely spaced objects. These include:
Given these mechanisms, it's not too surprising that your experiment with the white square and two closely spaced labels resulted in detections for both labels. The model's ability to leverage different anchor shapes and scales, as well as post-processing steps like NMS, can contribute to detecting objects that are close together, overcoming some of the limitations you highlighted. For a deeper dive into the specifics, including anchor assignment and the handling of overlapping detections, the official Ultralytics documentation and source code comments offer a wealth of detail. Check out the docs at https://docs.ultralytics.com/yolov5/ for more in-depth explanations and insights. If you have more questions or need further clarification, feel free to ask. Keep up the great exploration! 🚀 |
Okey, thanks for your answer. I guess then that, if I have two different classes and both classes fit in the available anchors for each cell (let's say there are just two, as the other will be unnecessary,) we would have that each class would go to one of the anchors? I have the intuition that the first class will be targeted to the anchor with best fit and the second class, as this anchor is already taken, will be targeted to the second anchor, but I'm not totally sure. Is this reasoning correct? |
Hey there! 😊 Your intuition is quite on point! When you have two different classes in close proximity within a grid cell, and there are suitable anchors available, YOLOv5 works as follows:
It hinges on the overlap and suitability of each object to the available anchors. So yes, each class could effectively be "assigned" to a different anchor within the same grid cell if the anchors are appropriate fits for their shapes and sizes. This mechanism helps YOLOv5 detect multiple objects of different classes that are close to each other. Keep exploring and asking great questions! 🌟 |
👋 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 ⭐ |
Search before asking
Question
I am trying to understand exactly how does Yolo make its predictions. I have found that yolo assigns each target to an anchor, and that there are 3 anchors per detection head per grid cell. I understand this is what makes Yolo have some problems when detecting small objects that are close, as only one prediction is done per grid cell.
I am not sure if this is how it exactly works, but I think it is something like that. Working in some training experiments, I did not quite understand the results, so I decided to run a minimal experiment to understand this fact. Taking into account Yolo's limitations on detecting close and small objects, I decided to use a black image as input (with noise) and a 10x10 pixels white square located somewhere in the image. I then assigned two labels (5 pixels away one from each other) in the white square.
If what I was understanding was okay, the model should reach, more or less, 50% in P and R, as it should only be able to detect one of the labels. However, the model is able to predict both labels.
How is this happening? Where is the error in my understanding?
Additional
No response
The text was updated successfully, but these errors were encountered: