Fix confusion matrix update when no predictions are made (#8748)
* Fix confusion matrix update when no predictions are made * Update metrics.py * Simply confusion matrix changes * Simply confusion matrix fix Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
1 parent
587a3a37c5
commit
567397d67a
2 files changed
+8
No files matched your search
@@ -139,6 +139,12 @@ class ConfusionMatrix:
|
|||||||
Returns:
|
Returns:
|
||||||
None, updates confusion matrix accordingly
|
None, updates confusion matrix accordingly
|
||||||
"""
|
"""
|
||||||
|
if detections is None:
|
||||||
|
gt_classes = labels.int()
|
||||||
|
for i, gc in enumerate(gt_classes):
|
||||||
|
self.matrix[self.nc, gc] += 1 # background FN
|
||||||
|
return
|
||||||
|
|
||||||
detections = detections[detections[:, 4] > self.conf]
|
detections = detections[detections[:, 4] > self.conf]
|
||||||
gt_classes = labels[:, 0].int()
|
gt_classes = labels[:, 0].int()
|
||||||
detection_classes = detections[:, 5].int()
|
detection_classes = detections[:, 5].int()
|
||||||
|
|||||||
@@ -228,6 +228,8 @@ def run(
|
|||||||
if npr == 0:
|
if npr == 0:
|
||||||
if nl:
|
if nl:
|
||||||
stats.append((correct, *torch.zeros((2, 0), device=device), labels[:, 0]))
|
stats.append((correct, *torch.zeros((2, 0), device=device), labels[:, 0]))
|
||||||
|
if plots:
|
||||||
|
confusion_matrix.process_batch(detections=None, labels=labels[:, 0])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Predictions
|
# Predictions
|
||||||
|
|||||||
Reference in new issue
Block a user