From 8933e4bc6a380e6a2119fb44bdfcf42c761d7d79 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 25 Jul 2021 17:39:55 +0200 Subject: [PATCH 1/9] New CSV Logger --- .gitignore | 1 + train.py | 16 +++------ tutorial.ipynb | 4 +-- utils/loggers/__init__.py | 33 +++++++++++-------- utils/plots.py | 68 +++++++++------------------------------ 5 files changed, 43 insertions(+), 79 deletions(-) diff --git a/.gitignore b/.gitignore index 91299e263b86..b07134d097dd 100755 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ data/* !data/*.sh results*.txt +results*.csv # Datasets ------------------------------------------------------------------------------------------------------------- coco/ diff --git a/train.py b/train.py index 1c48fa49f0f7..ebc0029ede80 100644 --- a/train.py +++ b/train.py @@ -61,7 +61,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary # Directories w = save_dir / 'weights' # weights dir w.mkdir(parents=True, exist_ok=True) # make dir - last, best, results_file = w / 'last.pt', w / 'best.pt', save_dir / 'results.txt' + last, best = w / 'last.pt', w / 'best.pt' # Hyperparameters if isinstance(hyp, str): @@ -88,7 +88,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary # Loggers if RANK in [-1, 0]: - loggers = Loggers(save_dir, results_file, weights, opt, hyp, data_dict, LOGGER).start() # loggers dict + loggers = Loggers(save_dir, weights, opt, hyp, data_dict, LOGGER).start() # loggers dict if loggers.wandb and resume: weights, epochs, hyp, data_dict = opt.weights, opt.epochs, opt.hyp, loggers.wandb.data_dict @@ -167,10 +167,6 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary ema.ema.load_state_dict(ckpt['ema'].float().state_dict()) ema.updates = ckpt['updates'] - # Results - if ckpt.get('training_results') is not None: - results_file.write_text(ckpt['training_results']) # write results.txt - # Epochs start_epoch = ckpt['epoch'] + 1 if resume: @@ -331,9 +327,8 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary if RANK in [-1, 0]: mloss = (mloss * i + loss_items) / (i + 1) # update mean losses mem = f'{torch.cuda.memory_reserved() / 1E9 if torch.cuda.is_available() else 0:.3g}G' # (GB) - s = ('%10s' * 2 + '%10.4g' * 6) % ( - f'{epoch}/{epochs - 1}', mem, *mloss, targets.shape[0], imgs.shape[-1]) - pbar.set_description(s) + pbar.set_description(('%10s' * 2 + '%10.4g' * 6) % ( + f'{epoch}/{epochs - 1}', mem, *mloss, targets.shape[0], imgs.shape[-1])) # Plot if plots: @@ -371,13 +366,12 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary fi = fitness(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] if fi > best_fitness: best_fitness = fi - loggers.on_train_val_end(mloss, results, lr, epoch, s, best_fitness, fi) + loggers.on_train_val_end(mloss, results, lr, epoch, best_fitness, fi) # Save model if (not nosave) or (final_epoch and not evolve): # if save ckpt = {'epoch': epoch, 'best_fitness': best_fitness, - 'training_results': results_file.read_text(), 'model': deepcopy(de_parallel(model)).half(), 'ema': deepcopy(ema.ema).half(), 'updates': ema.updates, diff --git a/tutorial.ipynb b/tutorial.ipynb index f316dc5f550a..c0c5a4003d42 100644 --- a/tutorial.ipynb +++ b/tutorial.ipynb @@ -1074,7 +1074,7 @@ "id": "7KN5ghjE6ZWh" }, "source": [ - "Training results are automatically logged to [Tensorboard](https://www.tensorflow.org/tensorboard) and `runs/train/exp/results.txt`, which is plotted as `results.png` (below) after training completes. You can also plot any `results.txt` file manually:" + "Training results are automatically logged to [Tensorboard](https://www.tensorflow.org/tensorboard) and CSV as `runs/train/exp/results.csv`, which is plotted as `results.png` (below) after training completes. You can also plot any `results.csv` file manually:" ] }, { @@ -1084,7 +1084,7 @@ }, "source": [ "from utils.plots import plot_results \n", - "plot_results(save_dir='runs/train/exp') # plot all results*.txt files in 'runs/train/exp'\n", + "plot_results(save_dir='runs/train/exp') # plot all results*.csv files in 'runs/train/exp'\n", "Image(filename='runs/train/exp/results.png', width=800)" ], "execution_count": null, diff --git a/utils/loggers/__init__.py b/utils/loggers/__init__.py index ceca84c95252..9eb874af6465 100644 --- a/utils/loggers/__init__.py +++ b/utils/loggers/__init__.py @@ -9,7 +9,7 @@ from utils.loggers.wandb.wandb_utils import WandbLogger from utils.torch_utils import de_parallel -LOGGERS = ('txt', 'tb', 'wandb') # text-file, TensorBoard, Weights & Biases +LOGGERS = ('csv', 'tb', 'wandb') # text-file, TensorBoard, Weights & Biases try: import wandb @@ -21,10 +21,8 @@ class Loggers(): # YOLOv5 Loggers class - def __init__(self, save_dir=None, results_file=None, weights=None, opt=None, hyp=None, - data_dict=None, logger=None, include=LOGGERS): + def __init__(self, save_dir=None, weights=None, opt=None, hyp=None, data_dict=None, logger=None, include=LOGGERS): self.save_dir = save_dir - self.results_file = results_file self.weights = weights self.opt = opt self.hyp = hyp @@ -35,7 +33,7 @@ def __init__(self, save_dir=None, results_file=None, weights=None, opt=None, hyp setattr(self, k, None) # init empty logger dictionary def start(self): - self.txt = True # always log to txt + self.csv = True # always log to csv # Message try: @@ -89,21 +87,28 @@ def on_val_end(self): files = sorted(self.save_dir.glob('val*.jpg')) self.wandb.log({"Validation": [wandb.Image(str(f), caption=f.name) for f in files]}) - def on_train_val_end(self, mloss, results, lr, epoch, s, best_fitness, fi): + def on_train_val_end(self, mloss, results, lr, epoch, best_fitness, fi): # Callback runs on validation end during training vals = list(mloss[:-1]) + list(results) + lr - tags = ['train/box_loss', 'train/obj_loss', 'train/cls_loss', # train loss - 'metrics/precision', 'metrics/recall', 'metrics/mAP_0.5', 'metrics/mAP_0.5:0.95', + keys = ['train/box_loss', 'train/obj_loss', 'train/cls_loss', # train loss + 'metrics/precision', 'metrics/recall', 'metrics/mAP_0.5', 'metrics/mAP_0.5:0.95', # metrics 'val/box_loss', 'val/obj_loss', 'val/cls_loss', # val loss 'x/lr0', 'x/lr1', 'x/lr2'] # params - if self.txt: - with open(self.results_file, 'a') as f: - f.write(s + '%10.4g' * 7 % results + '\n') # append metrics, val_loss + x = {k: v for k, v in zip(keys, vals)} # dict + + if self.csv: + file = self.save_dir / 'results.csv' + n = len(x) + 1 # number of cols + s = '' if file.exists() else (('%20s,' * n % tuple(['epoch'] + keys)).rstrip(',') + '\n') # add header + with open(file, 'a') as f: + f.write(s + ('%20.5g,' * n % tuple([epoch] + vals)).rstrip(',') + '\n') + if self.tb: - for x, tag in zip(vals, tags): - self.tb.add_scalar(tag, x, epoch) # TensorBoard + for k, v in x.items(): + self.tb.add_scalar(k, v, epoch) # TensorBoard + if self.wandb: - self.wandb.log({k: v for k, v in zip(tags, vals)}) + self.wandb.log(x) self.wandb.end_epoch(best_result=best_fitness == fi) def on_model_save(self, last, epoch, final_epoch, best_fitness, fi): diff --git a/utils/plots.py b/utils/plots.py index f9fd35fce751..91b5c79df09c 100644 --- a/utils/plots.py +++ b/utils/plots.py @@ -1,7 +1,5 @@ # Plotting utils -import glob -import os from copy import copy from pathlib import Path @@ -387,63 +385,29 @@ def profile_idetection(start=0, stop=0, labels=(), save_dir=''): plt.savefig(Path(save_dir) / 'idetection_profile.png', dpi=200) -def plot_results_overlay(start=0, stop=0): # from utils.plots import *; plot_results_overlay() - # Plot training 'results*.txt', overlaying train and val losses - s = ['train', 'train', 'train', 'Precision', 'mAP@0.5', 'val', 'val', 'val', 'Recall', 'mAP@0.5:0.95'] # legends - t = ['Box', 'Objectness', 'Classification', 'P-R', 'mAP-F1'] # titles - for f in sorted(glob.glob('results*.txt') + glob.glob('../../Downloads/results*.txt')): - results = np.loadtxt(f, usecols=[2, 3, 4, 8, 9, 12, 13, 14, 10, 11], ndmin=2).T - n = results.shape[1] # number of rows - x = range(start, min(stop, n) if stop else n) - fig, ax = plt.subplots(1, 5, figsize=(14, 3.5), tight_layout=True) - ax = ax.ravel() - for i in range(5): - for j in [i, i + 5]: - y = results[j, x] - ax[i].plot(x, y, marker='.', label=s[j]) - # y_smooth = butter_lowpass_filtfilt(y) - # ax[i].plot(x, np.gradient(y_smooth), marker='.', label=s[j]) - - ax[i].set_title(t[i]) - ax[i].legend() - ax[i].set_ylabel(f) if i == 0 else None # add filename - fig.savefig(f.replace('.txt', '.png'), dpi=200) - - -def plot_results(start=0, stop=0, bucket='', id=(), labels=(), save_dir=''): - # Plot training 'results*.txt'. from utils.plots import *; plot_results(save_dir='runs/train/exp') +def plot_results(save_dir=''): + # Plot training 'results*.csv'. from utils.plots import *; plot_results(save_dir='runs/train/exp') + save_dir = Path(save_dir) fig, ax = plt.subplots(2, 5, figsize=(12, 6), tight_layout=True) ax = ax.ravel() - s = ['Box', 'Objectness', 'Classification', 'Precision', 'Recall', - 'val Box', 'val Objectness', 'val Classification', 'mAP@0.5', 'mAP@0.5:0.95'] - if bucket: - # files = ['https://storage.googleapis.com/%s/results%g.txt' % (bucket, x) for x in id] - files = ['results%g.txt' % x for x in id] - c = ('gsutil cp ' + '%s ' * len(files) + '.') % tuple('gs://%s/results%g.txt' % (bucket, x) for x in id) - os.system(c) - else: - files = list(Path(save_dir).glob('results*.txt')) - assert len(files), 'No results.txt files found in %s, nothing to plot.' % os.path.abspath(save_dir) + files = list(save_dir.glob('results*.csv')) + assert len(files), f'No results.csv files found in {save_dir.resolve()}, nothing to plot.' for fi, f in enumerate(files): try: - results = np.loadtxt(f, usecols=[2, 3, 4, 8, 9, 12, 13, 14, 10, 11], ndmin=2).T - n = results.shape[1] # number of rows - x = range(start, min(stop, n) if stop else n) - for i in range(10): - y = results[i, x] - if i in [0, 1, 2, 5, 6, 7]: - y[y == 0] = np.nan # don't show zero loss values - # y /= y[0] # normalize - label = labels[fi] if len(labels) else f.stem - ax[i].plot(x, y, marker='.', label=label, linewidth=2, markersize=8) - ax[i].set_title(s[i]) - # if i in [5, 6, 7]: # share train and val loss y axes + data = pd.read_csv(f) + s = [x.strip() for x in data.columns] + x = data.values[:, 0] + for i, j in enumerate([1, 2, 3, 4, 5, 8, 9, 10, 6, 7]): + y = data.values[:, j] + # y[y == 0] = np.nan # don't show zero values + ax[i].plot(x, y, marker='.', label=f.stem, linewidth=2, markersize=8) + ax[i].set_title(s[j], fontsize=12) + # if j in [8, 9, 10]: # share train and val loss y axes # ax[i].get_shared_y_axes().join(ax[i], ax[i - 5]) except Exception as e: - print('Warning: Plotting error for %s; %s' % (f, e)) - + print(f'Warning: Plotting error for {f}: {e}') ax[1].legend() - fig.savefig(Path(save_dir) / 'results.png', dpi=200) + fig.savefig(save_dir / 'results.png', dpi=200) def feature_visualization(x, module_type, stage, n=32, save_dir=Path('runs/detect/exp')): From 3e7c1246ad3320c3b4085b78c0e6ab54fdf3dc23 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 25 Jul 2021 17:52:54 +0200 Subject: [PATCH 2/9] cleanup --- train.py | 9 ++------- utils/loggers/__init__.py | 5 ++++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/train.py b/train.py index ebc0029ede80..7840e07584cf 100644 --- a/train.py +++ b/train.py @@ -38,7 +38,7 @@ check_requirements, print_mutation, set_logging, one_cycle, colorstr from utils.google_utils import attempt_download from utils.loss import ComputeLoss -from utils.plots import plot_images, plot_labels, plot_results, plot_evolution +from utils.plots import plot_images, plot_labels, plot_evolution from utils.torch_utils import ModelEMA, select_device, intersect_dicts, torch_distributed_zero_first, de_parallel from utils.loggers.wandb.wandb_utils import check_wandb_resume from utils.metrics import fitness @@ -389,9 +389,6 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary # end training ----------------------------------------------------------------------------------------------------- if RANK in [-1, 0]: LOGGER.info(f'{epoch - start_epoch + 1} epochs completed in {(time.time() - t0) / 3600:.3f} hours.\n') - if plots: - plot_results(save_dir=save_dir) # save as results.png - if not evolve: if is_coco: # COCO dataset for m in [last, best] if best.exists() else [last]: # speed, mAP tests @@ -405,13 +402,11 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary save_dir=save_dir, save_json=True, plots=False) - # Strip optimizers for f in last, best: if f.exists(): strip_optimizer(f) # strip optimizers - - loggers.on_train_end(last, best) + loggers.on_train_end(last, best, plots) torch.cuda.empty_cache() return results diff --git a/utils/loggers/__init__.py b/utils/loggers/__init__.py index 9eb874af6465..83ea4558ff0a 100644 --- a/utils/loggers/__init__.py +++ b/utils/loggers/__init__.py @@ -7,6 +7,7 @@ from utils.general import colorstr, emojis from utils.loggers.wandb.wandb_utils import WandbLogger +from utils.plots import plot_results from utils.torch_utils import de_parallel LOGGERS = ('csv', 'tb', 'wandb') # text-file, TensorBoard, Weights & Biases @@ -117,8 +118,10 @@ def on_model_save(self, last, epoch, final_epoch, best_fitness, fi): if ((epoch + 1) % self.opt.save_period == 0 and not final_epoch) and self.opt.save_period != -1: self.wandb.log_model(last.parent, self.opt, epoch, fi, best_model=best_fitness == fi) - def on_train_end(self, last, best): + def on_train_end(self, last, best, plots): # Callback runs on training end + if plots: + plot_results(save_dir=self.save_dir) # save results.png files = ['results.png', 'confusion_matrix.png', *[f'{x}_curve.png' for x in ('F1', 'PR', 'P', 'R')]] files = [(self.save_dir / f) for f in files if (self.save_dir / f).exists()] # filter if self.wandb: From ffa2aa71f60c1824a5856eca0a01aa18b3e2d8e5 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 25 Jul 2021 18:03:18 +0200 Subject: [PATCH 3/9] move batch plots into Logger --- train.py | 13 +++---------- utils/loggers/__init__.py | 23 ++++++++++++++--------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/train.py b/train.py index 7840e07584cf..1cfd3a41c109 100644 --- a/train.py +++ b/train.py @@ -12,7 +12,6 @@ import time from copy import deepcopy from pathlib import Path -from threading import Thread import math import numpy as np @@ -38,7 +37,7 @@ check_requirements, print_mutation, set_logging, one_cycle, colorstr from utils.google_utils import attempt_download from utils.loss import ComputeLoss -from utils.plots import plot_images, plot_labels, plot_evolution +from utils.plots import plot_labels, plot_evolution from utils.torch_utils import ModelEMA, select_device, intersect_dicts, torch_distributed_zero_first, de_parallel from utils.loggers.wandb.wandb_utils import check_wandb_resume from utils.metrics import fitness @@ -323,19 +322,13 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary ema.update(model) last_opt_step = ni - # Print + # Log if RANK in [-1, 0]: mloss = (mloss * i + loss_items) / (i + 1) # update mean losses mem = f'{torch.cuda.memory_reserved() / 1E9 if torch.cuda.is_available() else 0:.3g}G' # (GB) pbar.set_description(('%10s' * 2 + '%10.4g' * 6) % ( f'{epoch}/{epochs - 1}', mem, *mloss, targets.shape[0], imgs.shape[-1])) - - # Plot - if plots: - if ni < 3: - f = save_dir / f'train_batch{ni}.jpg' # filename - Thread(target=plot_images, args=(imgs, targets, paths, f), daemon=True).start() - loggers.on_train_batch_end(ni, model, imgs) + loggers.on_train_batch_end(ni, model, imgs, targets, paths, plots) # end batch ------------------------------------------------------------------------------------------------ diff --git a/utils/loggers/__init__.py b/utils/loggers/__init__.py index 83ea4558ff0a..baa97d14ae25 100644 --- a/utils/loggers/__init__.py +++ b/utils/loggers/__init__.py @@ -1,13 +1,14 @@ # YOLOv5 experiment logging utils import warnings +from threading import Thread import torch from torch.utils.tensorboard import SummaryWriter from utils.general import colorstr, emojis from utils.loggers.wandb.wandb_utils import WandbLogger -from utils.plots import plot_results +from utils.plots import plot_images, plot_results from utils.torch_utils import de_parallel LOGGERS = ('csv', 'tb', 'wandb') # text-file, TensorBoard, Weights & Biases @@ -62,15 +63,19 @@ def start(self): return self - def on_train_batch_end(self, ni, model, imgs): + def on_train_batch_end(self, ni, model, imgs, targets, paths, plots): # Callback runs on train batch end - if ni == 0: - with warnings.catch_warnings(): - warnings.simplefilter('ignore') # suppress jit trace warning - self.tb.add_graph(torch.jit.trace(de_parallel(model), imgs[0:1], strict=False), []) - if self.wandb and ni == 10: - files = sorted(self.save_dir.glob('train*.jpg')) - self.wandb.log({'Mosaics': [wandb.Image(str(f), caption=f.name) for f in files if f.exists()]}) + if plots: + if ni == 0: + with warnings.catch_warnings(): + warnings.simplefilter('ignore') # suppress jit trace warning + self.tb.add_graph(torch.jit.trace(de_parallel(model), imgs[0:1], strict=False), []) + if ni < 3: + f = self.save_dir / f'train_batch{ni}.jpg' # filename + Thread(target=plot_images, args=(imgs, targets, paths, f), daemon=True).start() + if self.wandb and ni == 10: + files = sorted(self.save_dir.glob('train*.jpg')) + self.wandb.log({'Mosaics': [wandb.Image(str(f), caption=f.name) for f in files if f.exists()]}) def on_train_epoch_end(self, epoch): # Callback runs on train epoch end From 18d24e871cab8f374bcc0fe719020b004a1c5435 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 25 Jul 2021 18:08:59 +0200 Subject: [PATCH 4/9] rename comment --- utils/loggers/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/loggers/__init__.py b/utils/loggers/__init__.py index baa97d14ae25..538b1e934187 100644 --- a/utils/loggers/__init__.py +++ b/utils/loggers/__init__.py @@ -94,7 +94,7 @@ def on_val_end(self): self.wandb.log({"Validation": [wandb.Image(str(f), caption=f.name) for f in files]}) def on_train_val_end(self, mloss, results, lr, epoch, best_fitness, fi): - # Callback runs on validation end during training + # Callback runs on val end during training vals = list(mloss[:-1]) + list(results) + lr keys = ['train/box_loss', 'train/obj_loss', 'train/cls_loss', # train loss 'metrics/precision', 'metrics/recall', 'metrics/mAP_0.5', 'metrics/mAP_0.5:0.95', # metrics From faa749749716ffec11fc5df97a1a8928f1b150db Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 25 Jul 2021 18:17:32 +0200 Subject: [PATCH 5/9] Remove total loss from progress bar --- train.py | 6 +++--- utils/loss.py | 3 +-- val.py | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/train.py b/train.py index 1cfd3a41c109..db045c766716 100644 --- a/train.py +++ b/train.py @@ -270,11 +270,11 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary # b = int(random.uniform(0.25 * imgsz, 0.75 * imgsz + gs) // gs * gs) # dataset.mosaic_border = [b - imgsz, -b] # height, width borders - mloss = torch.zeros(4, device=device) # mean losses + mloss = torch.zeros(3, device=device) # mean losses if RANK != -1: train_loader.sampler.set_epoch(epoch) pbar = enumerate(train_loader) - LOGGER.info(('\n' + '%10s' * 8) % ('Epoch', 'gpu_mem', 'box', 'obj', 'cls', 'total', 'labels', 'img_size')) + LOGGER.info(('\n' + '%10s' * 7) % ('Epoch', 'gpu_mem', 'box', 'obj', 'cls', 'labels', 'img_size')) if RANK in [-1, 0]: pbar = tqdm(pbar, total=nb) # progress bar optimizer.zero_grad() @@ -326,7 +326,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary if RANK in [-1, 0]: mloss = (mloss * i + loss_items) / (i + 1) # update mean losses mem = f'{torch.cuda.memory_reserved() / 1E9 if torch.cuda.is_available() else 0:.3g}G' # (GB) - pbar.set_description(('%10s' * 2 + '%10.4g' * 6) % ( + pbar.set_description(('%10s' * 2 + '%10.4g' * 5) % ( f'{epoch}/{epochs - 1}', mem, *mloss, targets.shape[0], imgs.shape[-1])) loggers.on_train_batch_end(ni, model, imgs, targets, paths, plots) diff --git a/utils/loss.py b/utils/loss.py index 22061a11ff27..79e8f24359c1 100644 --- a/utils/loss.py +++ b/utils/loss.py @@ -162,8 +162,7 @@ def __call__(self, p, targets): # predictions, targets, model lcls *= self.hyp['cls'] bs = tobj.shape[0] # batch size - loss = lbox + lobj + lcls - return loss * bs, torch.cat((lbox, lobj, lcls, loss)).detach() + return (lbox + lobj + lcls) * bs, torch.cat((lbox, lobj, lcls)).detach() def build_targets(self, p, targets): # Build targets for compute_loss(), input targets(image,class,x,y,w,h) diff --git a/val.py b/val.py index 2b088dcdf210..f20877e8aa0b 100644 --- a/val.py +++ b/val.py @@ -171,7 +171,7 @@ def run(data, # Compute loss if compute_loss: - loss += compute_loss([x.float() for x in train_out], targets)[1][:3] # box, obj, cls + loss += compute_loss([x.float() for x in train_out], targets)[1] # box, obj, cls # Run NMS targets[:, 2:] *= torch.Tensor([width, height, width, height]).to(device) # to pixels From 03114d1195376aba8d558db1faca6d92a90ded9a Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 25 Jul 2021 18:21:52 +0200 Subject: [PATCH 6/9] mloss :-1 bug fix --- utils/loggers/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/loggers/__init__.py b/utils/loggers/__init__.py index 538b1e934187..759f8f1d01e4 100644 --- a/utils/loggers/__init__.py +++ b/utils/loggers/__init__.py @@ -95,7 +95,7 @@ def on_val_end(self): def on_train_val_end(self, mloss, results, lr, epoch, best_fitness, fi): # Callback runs on val end during training - vals = list(mloss[:-1]) + list(results) + lr + vals = list(mloss) + list(results) + lr keys = ['train/box_loss', 'train/obj_loss', 'train/cls_loss', # train loss 'metrics/precision', 'metrics/recall', 'metrics/mAP_0.5', 'metrics/mAP_0.5:0.95', # metrics 'val/box_loss', 'val/obj_loss', 'val/cls_loss', # val loss From 165d204bf90395697ef1e7ac5305a2dcc11f8b2a Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 25 Jul 2021 18:48:48 +0200 Subject: [PATCH 7/9] Update plot_results() --- utils/plots.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/plots.py b/utils/plots.py index 91b5c79df09c..0687f9b87ba8 100644 --- a/utils/plots.py +++ b/utils/plots.py @@ -385,9 +385,9 @@ def profile_idetection(start=0, stop=0, labels=(), save_dir=''): plt.savefig(Path(save_dir) / 'idetection_profile.png', dpi=200) -def plot_results(save_dir=''): - # Plot training 'results*.csv'. from utils.plots import *; plot_results(save_dir='runs/train/exp') - save_dir = Path(save_dir) +def plot_results(file='path/to/results.csv', save_dir=''): + # Plot training results.csv. Usage: from utils.plots import *; plot_results('path/to/results.csv') + save_dir = Path(file).parent if file else Path(save_dir) fig, ax = plt.subplots(2, 5, figsize=(12, 6), tight_layout=True) ax = ax.ravel() files = list(save_dir.glob('results*.csv')) From 812a28ae8bc5c144173b3c5ed1afa53ad690c65b Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 25 Jul 2021 18:53:24 +0200 Subject: [PATCH 8/9] Update plot_results() --- utils/plots.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/plots.py b/utils/plots.py index 0687f9b87ba8..e13e316314dd 100644 --- a/utils/plots.py +++ b/utils/plots.py @@ -385,9 +385,9 @@ def profile_idetection(start=0, stop=0, labels=(), save_dir=''): plt.savefig(Path(save_dir) / 'idetection_profile.png', dpi=200) -def plot_results(file='path/to/results.csv', save_dir=''): +def plot_results(file='', dir=''): # Plot training results.csv. Usage: from utils.plots import *; plot_results('path/to/results.csv') - save_dir = Path(file).parent if file else Path(save_dir) + save_dir = Path(file).parent if file else Path(dir) fig, ax = plt.subplots(2, 5, figsize=(12, 6), tight_layout=True) ax = ax.ravel() files = list(save_dir.glob('results*.csv')) From 16ec5643e8d73c23b0489d9509bf8253fd4f1e6a Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 25 Jul 2021 19:00:09 +0200 Subject: [PATCH 9/9] plot_results bug fix --- utils/loggers/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/loggers/__init__.py b/utils/loggers/__init__.py index 759f8f1d01e4..29dd4605341b 100644 --- a/utils/loggers/__init__.py +++ b/utils/loggers/__init__.py @@ -126,7 +126,7 @@ def on_model_save(self, last, epoch, final_epoch, best_fitness, fi): def on_train_end(self, last, best, plots): # Callback runs on training end if plots: - plot_results(save_dir=self.save_dir) # save results.png + plot_results(dir=self.save_dir) # save results.png files = ['results.png', 'confusion_matrix.png', *[f'{x}_curve.png' for x in ('F1', 'PR', 'P', 'R')]] files = [(self.save_dir / f) for f in files if (self.save_dir / f).exists()] # filter if self.wandb: