-
-
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
Question about calculating mAP at test time #3042
Comments
👋 Hello @huuquan1994, 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://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com. RequirementsPython 3.8 or later with all requirements.txt dependencies installed, including $ pip install -r requirements.txt EnvironmentsYOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf 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), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit. |
@huuquan1994 yes you're right, the comments should be swapped! Can you send a quick PR for this bug you spotted? Thanks! The predictions are sorted by confidence here: Lines 32 to 33 in b18ca31
|
Thanks, @glenn-jocher for your comments fix. For my first question, I understood that the predictions are sorted by confidence at the Supposed that I have 1 test image with 1 class and 6 ground-truth bounding boxes. I tried to print out the prediction results (after NMS). # Search for detections
if pi.shape[0]:
# Prediction to target ious
ious, i = box_iou(predn[pi, :4], tbox[ti]).max(1) # best ious, indices
# Append detections
detected_set = set()
# Print out all IoU values that > 0.5 (iouv[0])
print(ious[ious > iouv[0]])
# Print out all (targeted) IoU indices that > 0.5 (iouv[0])
print(ti[i[ious > iouv[0]]])
for j in (ious > iouv[0]).nonzero(as_tuple=False):
d = ti[i[j]] # detected target
if d.item() not in detected_set:
detected_set.add(d.item())
detected.append(d)
correct[pi[j]] = ious[j] > iouv # iou_thres is 1xn
if len(detected) == nl: # all targets already located in image
break
# Print detected for further mAP calculation
print(detected) My outputs are:
The corresponding IoU values of the detected targets are [0.91536, 0.72824, 0.84568, 0.64040, 0.75937, 0.55075] (which were the first elements in the list (if correctly located)) But if we consider the best IoU values for the detected boxes ([3, 2, 0, 5, 1, 4]), shouldn't they be [0.91536, 0.72824, 0.84568, 0.72601, 0.75937, 0.87954]? |
@huuquan1994 there's no IoU sorting, the sorting is by prediction confidence. |
@glenn-jocher thanks for your reply! I wonder if this affects the result of the Anyway, I just want to understand YOLOv5 better and if there's no IoU sorting, your code is perfect 😊 |
@huuquan1994 I'm not sure I understand your question correctly. Can you submit a PR with your proposed changes so that we can see and evaluate the changes against the baseline code? Thanks! |
@glenn-jocher sure, I'll do it soon! |
❔Question
Thank you for your work, I really enjoyed running the codes.
I was trying to understand the way we calculate mAP by reading the test.py
At line 197, as I understood, the IoU values (
ious
) wasn't sorted before the further process (lines 199-211).Therefore, I think it doesn't guarantee that we find the best IoU (or a detected box) for a ground-truth box.
For example, a detected box is considered correct if the IoU with a ground-truth box is >= 0.5. However, there are possibilities that we detected multiple boxes with different IoU values. In this case, I think we should assign the box with the highest IoU as the correctly detected box.
Will the code affect the result of calculating mAP?
Additional context
The comments in lines 191-192 (
# prediction indices
,# target indices
) should be swapped, shouldn't they?The text was updated successfully, but these errors were encountered: