From 27a4736e968158063a87024be74534a560fc8e84 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 16 Sep 2021 17:55:58 +0200 Subject: [PATCH] Fix val.py study plot (#4831) * Fix val.py study plot * call plot_val_study * Rename plot_study_txt to plot_val_study --- utils/plots.py | 11 +++++++---- val.py | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/utils/plots.py b/utils/plots.py index 1ed88ea7c832..9570fdf27a63 100644 --- a/utils/plots.py +++ b/utils/plots.py @@ -247,15 +247,16 @@ def plot_targets_txt(): # from utils.plots import *; plot_targets_txt() plt.savefig('targets.jpg', dpi=200) -def plot_study_txt(path='', x=None): # from utils.plots import *; plot_study_txt() - # Plot study.txt generated by val.py +def plot_val_study(file='', dir='', x=None): # from utils.plots import *; plot_val_study() + # Plot file=study.txt generated by val.py (or plot all study*.txt in dir) + save_dir = Path(file).parent if file else Path(dir) plot2 = False # plot additional results if plot2: ax = plt.subplots(2, 4, figsize=(10, 6), tight_layout=True)[1].ravel() fig2, ax2 = plt.subplots(1, 1, figsize=(8, 4), tight_layout=True) # for f in [Path(path) / f'study_coco_{x}.txt' for x in ['yolov5s6', 'yolov5m6', 'yolov5l6', 'yolov5x6']]: - for f in sorted(Path(path).glob('study*.txt')): + for f in sorted(save_dir.glob('study*.txt')): y = np.loadtxt(f, dtype=np.float32, usecols=[0, 1, 2, 3, 7, 8, 9], ndmin=2).T x = np.arange(y.shape[1]) if x is None else np.array(x) if plot2: @@ -278,7 +279,9 @@ def plot_study_txt(path='', x=None): # from utils.plots import *; plot_study_tx ax2.set_xlabel('GPU Speed (ms/img)') ax2.set_ylabel('COCO AP val') ax2.legend(loc='lower right') - plt.savefig(str(Path(path).name) + '.png', dpi=300) + f = save_dir / 'study.png' + print(f'Saving {f}...') + plt.savefig(f, dpi=300) def plot_labels(labels, names=(), save_dir=Path('')): diff --git a/val.py b/val.py index 00eb92bb096a..16dd76d680f7 100644 --- a/val.py +++ b/val.py @@ -26,7 +26,7 @@ check_suffix, check_yaml, box_iou, non_max_suppression, scale_coords, xyxy2xywh, xywh2xyxy, set_logging, \ increment_path, colorstr from utils.metrics import ap_per_class, ConfusionMatrix -from utils.plots import plot_images, output_to_target, plot_study_txt +from utils.plots import output_to_target, plot_images, plot_val_study from utils.torch_utils import select_device, time_sync from utils.callbacks import Callbacks @@ -348,7 +348,7 @@ def main(opt): y.append(r + t) # results and times np.savetxt(f, y, fmt='%10.4g') # save os.system('zip -r study.zip study_*.txt') - plot_study_txt(x=x) # plot + plot_val_study(x=x) # plot if __name__ == "__main__":