Ryan Avery
commited on
Commit
•
2c56ad5
1
Parent(s):
ab86cec
Confusion matrix background axis swap (#2114)
Browse files- utils/metrics.py +4 -4
utils/metrics.py
CHANGED
@@ -147,12 +147,12 @@ class ConfusionMatrix:
|
|
147 |
if n and sum(j) == 1:
|
148 |
self.matrix[gc, detection_classes[m1[j]]] += 1 # correct
|
149 |
else:
|
150 |
-
self.matrix[
|
151 |
|
152 |
if n:
|
153 |
for i, dc in enumerate(detection_classes):
|
154 |
if not any(m1 == i):
|
155 |
-
self.matrix[self.nc
|
156 |
|
157 |
def matrix(self):
|
158 |
return self.matrix
|
@@ -168,8 +168,8 @@ class ConfusionMatrix:
|
|
168 |
sn.set(font_scale=1.0 if self.nc < 50 else 0.8) # for label size
|
169 |
labels = (0 < len(names) < 99) and len(names) == self.nc # apply names to ticklabels
|
170 |
sn.heatmap(array, annot=self.nc < 30, annot_kws={"size": 8}, cmap='Blues', fmt='.2f', square=True,
|
171 |
-
xticklabels=names + ['background
|
172 |
-
yticklabels=names + ['background
|
173 |
fig.axes[0].set_xlabel('True')
|
174 |
fig.axes[0].set_ylabel('Predicted')
|
175 |
fig.savefig(Path(save_dir) / 'confusion_matrix.png', dpi=250)
|
|
|
147 |
if n and sum(j) == 1:
|
148 |
self.matrix[gc, detection_classes[m1[j]]] += 1 # correct
|
149 |
else:
|
150 |
+
self.matrix[self.nc, gc] += 1 # background FP
|
151 |
|
152 |
if n:
|
153 |
for i, dc in enumerate(detection_classes):
|
154 |
if not any(m1 == i):
|
155 |
+
self.matrix[dc, self.nc] += 1 # background FN
|
156 |
|
157 |
def matrix(self):
|
158 |
return self.matrix
|
|
|
168 |
sn.set(font_scale=1.0 if self.nc < 50 else 0.8) # for label size
|
169 |
labels = (0 < len(names) < 99) and len(names) == self.nc # apply names to ticklabels
|
170 |
sn.heatmap(array, annot=self.nc < 30, annot_kws={"size": 8}, cmap='Blues', fmt='.2f', square=True,
|
171 |
+
xticklabels=names + ['background FP'] if labels else "auto",
|
172 |
+
yticklabels=names + ['background FN'] if labels else "auto").set_facecolor((1, 1, 1))
|
173 |
fig.axes[0].set_xlabel('True')
|
174 |
fig.axes[0].set_ylabel('Predicted')
|
175 |
fig.savefig(Path(save_dir) / 'confusion_matrix.png', dpi=250)
|