Skip to content

Commit

Permalink
Fix tick labels for background FN/FP (#9414)
Browse files Browse the repository at this point in the history
* Fix tick labels for background FN/FP

In the confusion matrix.

* Remove FP/FN from the background labels of the confusion matrix

* Update metrics.py

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
  • Loading branch information
hotohoto and glenn-jocher authored Sep 16, 2022
1 parent a1e5f9a commit c7a2d6b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ def process_batch(self, detections, labels):
if n and sum(j) == 1:
self.matrix[detection_classes[m1[j]], gc] += 1 # correct
else:
self.matrix[self.nc, gc] += 1 # background FP
self.matrix[self.nc, gc] += 1 # true background

if n:
for i, dc in enumerate(detection_classes):
if not any(m1 == i):
self.matrix[dc, self.nc] += 1 # background FN
self.matrix[dc, self.nc] += 1 # predicted background

def matrix(self):
return self.matrix
Expand All @@ -197,6 +197,7 @@ def plot(self, normalize=True, save_dir='', names=()):
nc, nn = self.nc, len(names) # number of classes, names
sn.set(font_scale=1.0 if nc < 50 else 0.8) # for label size
labels = (0 < nn < 99) and (nn == nc) # apply names to ticklabels
ticklabels = (names + ['background']) if labels else "auto"
with warnings.catch_warnings():
warnings.simplefilter('ignore') # suppress empty matrix RuntimeWarning: All-NaN slice encountered
sn.heatmap(array,
Expand All @@ -208,8 +209,8 @@ def plot(self, normalize=True, save_dir='', names=()):
fmt='.2f',
square=True,
vmin=0.0,
xticklabels=names + ['background FP'] if labels else "auto",
yticklabels=names + ['background FN'] if labels else "auto").set_facecolor((1, 1, 1))
xticklabels=ticklabels,
yticklabels=ticklabels).set_facecolor((1, 1, 1))
ax.set_ylabel('True')
ax.set_ylabel('Predicted')
ax.set_title('Confusion Matrix')
Expand Down

0 comments on commit c7a2d6b

Please sign in to comment.