Ignore Seaborn plot warnings (#3576)
* Ignore Seaborn plot warnings * Update plots.py * Update metrics.py
This commit is contained in:
1 parent
4695ca8314
commit
095197bd4a
2 files changed
+10
-7
No files matched your search
+6
-3
@@ -1,5 +1,6 @@
|
|||||||
# Model validation metrics
|
# Model validation metrics
|
||||||
|
|
||||||
|
import warnings
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
@@ -167,9 +168,11 @@ class ConfusionMatrix:
|
|||||||
fig = plt.figure(figsize=(12, 9), tight_layout=True)
|
fig = plt.figure(figsize=(12, 9), tight_layout=True)
|
||||||
sn.set(font_scale=1.0 if self.nc < 50 else 0.8) # for label size
|
sn.set(font_scale=1.0 if self.nc < 50 else 0.8) # for label size
|
||||||
labels = (0 < len(names) < 99) and len(names) == self.nc # apply names to ticklabels
|
labels = (0 < len(names) < 99) and len(names) == self.nc # apply names to ticklabels
|
||||||
sn.heatmap(array, annot=self.nc < 30, annot_kws={"size": 8}, cmap='Blues', fmt='.2f', square=True,
|
with warnings.catch_warnings():
|
||||||
xticklabels=names + ['background FP'] if labels else "auto",
|
warnings.simplefilter('ignore') # suppress empty matrix RuntimeWarning: All-NaN slice encountered
|
||||||
yticklabels=names + ['background FN'] if labels else "auto").set_facecolor((1, 1, 1))
|
sn.heatmap(array, annot=self.nc < 30, annot_kws={"size": 8}, cmap='Blues', fmt='.2f', square=True,
|
||||||
|
xticklabels=names + ['background FP'] if labels else "auto",
|
||||||
|
yticklabels=names + ['background FN'] if labels else "auto").set_facecolor((1, 1, 1))
|
||||||
fig.axes[0].set_xlabel('True')
|
fig.axes[0].set_xlabel('True')
|
||||||
fig.axes[0].set_ylabel('Predicted')
|
fig.axes[0].set_ylabel('Predicted')
|
||||||
fig.savefig(Path(save_dir) / 'confusion_matrix.png', dpi=250)
|
fig.savefig(Path(save_dir) / 'confusion_matrix.png', dpi=250)
|
||||||
|
|||||||
+4
-4
@@ -11,7 +11,7 @@ import matplotlib
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import seaborn as sns
|
import seaborn as sn
|
||||||
import torch
|
import torch
|
||||||
import yaml
|
import yaml
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
@@ -291,7 +291,7 @@ def plot_labels(labels, names=(), save_dir=Path(''), loggers=None):
|
|||||||
x = pd.DataFrame(b.transpose(), columns=['x', 'y', 'width', 'height'])
|
x = pd.DataFrame(b.transpose(), columns=['x', 'y', 'width', 'height'])
|
||||||
|
|
||||||
# seaborn correlogram
|
# seaborn correlogram
|
||||||
sns.pairplot(x, corner=True, diag_kind='auto', kind='hist', diag_kws=dict(bins=50), plot_kws=dict(pmax=0.9))
|
sn.pairplot(x, corner=True, diag_kind='auto', kind='hist', diag_kws=dict(bins=50), plot_kws=dict(pmax=0.9))
|
||||||
plt.savefig(save_dir / 'labels_correlogram.jpg', dpi=200)
|
plt.savefig(save_dir / 'labels_correlogram.jpg', dpi=200)
|
||||||
plt.close()
|
plt.close()
|
||||||
|
|
||||||
@@ -306,8 +306,8 @@ def plot_labels(labels, names=(), save_dir=Path(''), loggers=None):
|
|||||||
ax[0].set_xticklabels(names, rotation=90, fontsize=10)
|
ax[0].set_xticklabels(names, rotation=90, fontsize=10)
|
||||||
else:
|
else:
|
||||||
ax[0].set_xlabel('classes')
|
ax[0].set_xlabel('classes')
|
||||||
sns.histplot(x, x='x', y='y', ax=ax[2], bins=50, pmax=0.9)
|
sn.histplot(x, x='x', y='y', ax=ax[2], bins=50, pmax=0.9)
|
||||||
sns.histplot(x, x='width', y='height', ax=ax[3], bins=50, pmax=0.9)
|
sn.histplot(x, x='width', y='height', ax=ax[3], bins=50, pmax=0.9)
|
||||||
|
|
||||||
# rectangles
|
# rectangles
|
||||||
labels[:, 1:3] = 0.5 # center
|
labels[:, 1:3] = 0.5 # center
|
||||||
|
|||||||
Reference in new issue
Block a user