| 263 | |
| 264 | |
| 265 | def plot_labels(labels, save_dir=''): |
| 266 | # plot dataset labels |
| 267 | c, b = labels[:, 0], labels[:, 1:].transpose() # classes, boxes |
| 268 | nc = int(c.max() + 1) # number of classes |
| 269 | |
| 270 | fig, ax = plt.subplots(2, 2, figsize=(8, 8), tight_layout=True) |
| 271 | ax = ax.ravel() |
| 272 | ax[0].hist(c, bins=np.linspace(0, nc, nc + 1) - 0.5, rwidth=0.8) |
| 273 | ax[0].set_xlabel('classes') |
| 274 | ax[1].scatter(b[0], b[1], c=hist2d(b[0], b[1], 90), cmap='jet') |
| 275 | ax[1].set_xlabel('x') |
| 276 | ax[1].set_ylabel('y') |
| 277 | ax[2].scatter(b[2], b[3], c=hist2d(b[2], b[3], 90), cmap='jet') |
| 278 | ax[2].set_xlabel('width') |
| 279 | ax[2].set_ylabel('height') |
| 280 | plt.savefig(Path(save_dir) / 'labels.png', dpi=200) |
| 281 | plt.close() |
| 282 | |
| 283 | # seaborn correlogram |
| 284 | try: |
| 285 | import seaborn as sns |
| 286 | import pandas as pd |
| 287 | x = pd.DataFrame(b.transpose(), columns=['x', 'y', 'width', 'height']) |
| 288 | sns.pairplot(x, corner=True, diag_kind='hist', kind='scatter', markers='o', |
| 289 | plot_kws=dict(s=3, edgecolor=None, linewidth=1, alpha=0.02), |
| 290 | diag_kws=dict(bins=50)) |
| 291 | plt.savefig(Path(save_dir) / 'labels_correlogram.png', dpi=200) |
| 292 | plt.close() |
| 293 | except Exception as e: |
| 294 | pass |
| 295 | |
| 296 | |
| 297 | def plot_evolution(yaml_file='data/hyp.finetune.yaml'): # from utils.general import *; plot_evolution() |