Skip to content

Commit

Permalink
Add ConfusionMatrix normalize=True flag (ultralytics#3586)
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed Jun 11, 2021
1 parent b3d7fc2 commit f3413e9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@ def process_batch(self, detections, labels):
def matrix(self):
return self.matrix

def plot(self, save_dir='', names=()):
def plot(self, normalize=True, save_dir='', names=()):
try:
import seaborn as sn

array = self.matrix / (self.matrix.sum(0).reshape(1, self.nc + 1) + 1E-6) # normalize

if normalize:
array = self.matrix / (self.matrix.sum(0).reshape(1, self.nc + 1) + 1E-6) # normalize columns
array[array < 0.005] = np.nan # don't annotate (would appear as 0.00)

fig = plt.figure(figsize=(12, 9), tight_layout=True)
Expand Down

0 comments on commit f3413e9

Please sign in to comment.