Skip to content
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

Fix confusion matrix update when no predictions are made #8748

Merged
merged 6 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ def process_batch(self, detections, labels):
if not any(m1 == i):
self.matrix[dc, self.nc] += 1 # background FN

def process_batch_no_detections(self, labels):
"""
Updates confusion matrix when model made zero predictions but the image contains groundtruth objects.
Every label passed in is considered a False Negative (a missed detection)
Arguments:
labels (Array[M, 1]), [class]
Returns:
None, updates confusion matrix accordingly
"""
gt_classes = labels.int()
for i, gc in enumerate(gt_classes):
self.matrix[self.nc, gc] += 1 # background FN

def matrix(self):
return self.matrix

Expand Down
2 changes: 2 additions & 0 deletions val.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def run(
if npr == 0:
if nl:
stats.append((correct, *torch.zeros((2, 0), device=device), labels[:, 0]))
if plots:
confusion_matrix.process_batch_no_detections(labels[:, 0])
continue

# Predictions
Expand Down