glenn-jocher
commited on
Commit
•
bb5ebc2
1
Parent(s):
11e7c7b
Close `matplotlib` plots after opening (#4612)
Browse files* Close plots
* Replace fig.close() for plt.close()
- utils/metrics.py +3 -0
- utils/plots.py +3 -1
utils/metrics.py
CHANGED
@@ -178,6 +178,7 @@ class ConfusionMatrix:
|
|
178 |
fig.axes[0].set_xlabel('True')
|
179 |
fig.axes[0].set_ylabel('Predicted')
|
180 |
fig.savefig(Path(save_dir) / 'confusion_matrix.png', dpi=250)
|
|
|
181 |
except Exception as e:
|
182 |
print(f'WARNING: ConfusionMatrix plot failure: {e}')
|
183 |
|
@@ -308,6 +309,7 @@ def plot_pr_curve(px, py, ap, save_dir='pr_curve.png', names=()):
|
|
308 |
ax.set_ylim(0, 1)
|
309 |
plt.legend(bbox_to_anchor=(1.04, 1), loc="upper left")
|
310 |
fig.savefig(Path(save_dir), dpi=250)
|
|
|
311 |
|
312 |
|
313 |
def plot_mc_curve(px, py, save_dir='mc_curve.png', names=(), xlabel='Confidence', ylabel='Metric'):
|
@@ -328,3 +330,4 @@ def plot_mc_curve(px, py, save_dir='mc_curve.png', names=(), xlabel='Confidence'
|
|
328 |
ax.set_ylim(0, 1)
|
329 |
plt.legend(bbox_to_anchor=(1.04, 1), loc="upper left")
|
330 |
fig.savefig(Path(save_dir), dpi=250)
|
|
|
|
178 |
fig.axes[0].set_xlabel('True')
|
179 |
fig.axes[0].set_ylabel('Predicted')
|
180 |
fig.savefig(Path(save_dir) / 'confusion_matrix.png', dpi=250)
|
181 |
+
plt.close()
|
182 |
except Exception as e:
|
183 |
print(f'WARNING: ConfusionMatrix plot failure: {e}')
|
184 |
|
|
|
309 |
ax.set_ylim(0, 1)
|
310 |
plt.legend(bbox_to_anchor=(1.04, 1), loc="upper left")
|
311 |
fig.savefig(Path(save_dir), dpi=250)
|
312 |
+
plt.close()
|
313 |
|
314 |
|
315 |
def plot_mc_curve(px, py, save_dir='mc_curve.png', names=(), xlabel='Confidence', ylabel='Metric'):
|
|
|
330 |
ax.set_ylim(0, 1)
|
331 |
plt.legend(bbox_to_anchor=(1.04, 1), loc="upper left")
|
332 |
fig.savefig(Path(save_dir), dpi=250)
|
333 |
+
plt.close()
|
utils/plots.py
CHANGED
@@ -345,7 +345,6 @@ def profile_idetection(start=0, stop=0, labels=(), save_dir=''):
|
|
345 |
a.remove()
|
346 |
except Exception as e:
|
347 |
print('Warning: Plotting error for %s; %s' % (f, e))
|
348 |
-
|
349 |
ax[1].legend()
|
350 |
plt.savefig(Path(save_dir) / 'idetection_profile.png', dpi=200)
|
351 |
|
@@ -371,6 +370,7 @@ def plot_evolve(evolve_csv=Path('path/to/evolve.csv')): # from utils.plots impo
|
|
371 |
print('%15s: %.3g' % (k, mu))
|
372 |
f = evolve_csv.with_suffix('.png') # filename
|
373 |
plt.savefig(f, dpi=200)
|
|
|
374 |
print(f'Saved {f}')
|
375 |
|
376 |
|
@@ -397,6 +397,7 @@ def plot_results(file='path/to/results.csv', dir=''):
|
|
397 |
print(f'Warning: Plotting error for {f}: {e}')
|
398 |
ax[1].legend()
|
399 |
fig.savefig(save_dir / 'results.png', dpi=200)
|
|
|
400 |
|
401 |
|
402 |
def feature_visualization(x, module_type, stage, n=32, save_dir=Path('runs/detect/exp')):
|
@@ -423,3 +424,4 @@ def feature_visualization(x, module_type, stage, n=32, save_dir=Path('runs/detec
|
|
423 |
|
424 |
print(f'Saving {save_dir / f}... ({n}/{channels})')
|
425 |
plt.savefig(save_dir / f, dpi=300, bbox_inches='tight')
|
|
|
|
345 |
a.remove()
|
346 |
except Exception as e:
|
347 |
print('Warning: Plotting error for %s; %s' % (f, e))
|
|
|
348 |
ax[1].legend()
|
349 |
plt.savefig(Path(save_dir) / 'idetection_profile.png', dpi=200)
|
350 |
|
|
|
370 |
print('%15s: %.3g' % (k, mu))
|
371 |
f = evolve_csv.with_suffix('.png') # filename
|
372 |
plt.savefig(f, dpi=200)
|
373 |
+
plt.close()
|
374 |
print(f'Saved {f}')
|
375 |
|
376 |
|
|
|
397 |
print(f'Warning: Plotting error for {f}: {e}')
|
398 |
ax[1].legend()
|
399 |
fig.savefig(save_dir / 'results.png', dpi=200)
|
400 |
+
plt.close()
|
401 |
|
402 |
|
403 |
def feature_visualization(x, module_type, stage, n=32, save_dir=Path('runs/detect/exp')):
|
|
|
424 |
|
425 |
print(f'Saving {save_dir / f}... ({n}/{channels})')
|
426 |
plt.savefig(save_dir / f, dpi=300, bbox_inches='tight')
|
427 |
+
plt.close()
|