jbutle55 glenn-jocher commited on
Commit
567397d
·
unverified ·
1 Parent(s): 587a3a3

Fix confusion matrix update when no predictions are made (#8748)

Browse files

* 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 <[email protected]>

Files changed (2) hide show
  1. utils/metrics.py +6 -0
  2. val.py +2 -0
utils/metrics.py CHANGED
@@ -139,6 +139,12 @@ class ConfusionMatrix:
139
  Returns:
140
  None, updates confusion matrix accordingly
141
  """
 
 
 
 
 
 
142
  detections = detections[detections[:, 4] > self.conf]
143
  gt_classes = labels[:, 0].int()
144
  detection_classes = detections[:, 5].int()
 
139
  Returns:
140
  None, updates confusion matrix accordingly
141
  """
142
+ if detections is None:
143
+ gt_classes = labels.int()
144
+ for i, gc in enumerate(gt_classes):
145
+ self.matrix[self.nc, gc] += 1 # background FN
146
+ return
147
+
148
  detections = detections[detections[:, 4] > self.conf]
149
  gt_classes = labels[:, 0].int()
150
  detection_classes = detections[:, 5].int()
val.py CHANGED
@@ -228,6 +228,8 @@ def run(
228
  if npr == 0:
229
  if nl:
230
  stats.append((correct, *torch.zeros((2, 0), device=device), labels[:, 0]))
 
 
231
  continue
232
 
233
  # Predictions
 
228
  if npr == 0:
229
  if nl:
230
  stats.append((correct, *torch.zeros((2, 0), device=device), labels[:, 0]))
231
+ if plots:
232
+ confusion_matrix.process_batch(detections=None, labels=labels[:, 0])
233
  continue
234
 
235
  # Predictions