From 50497218c25682458ea35b02dcc5d8a364f34591 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 9 Oct 2024 16:19:52 +0200 Subject: [PATCH] `ultralytics 8.3.9` add training `time` to results CSV (#16803) Signed-off-by: UltralyticsAssistant Co-authored-by: UltralyticsAssistant --- ultralytics/__init__.py | 2 +- ultralytics/engine/trainer.py | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index f9b56ba63b..7b7b0c1bfb 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics YOLO 🚀, AGPL-3.0 license -__version__ = "8.3.8" +__version__ = "8.3.9" import os diff --git a/ultralytics/engine/trainer.py b/ultralytics/engine/trainer.py index aadf63b023..352067397f 100644 --- a/ultralytics/engine/trainer.py +++ b/ultralytics/engine/trainer.py @@ -469,11 +469,9 @@ class BaseTrainer: if RANK in {-1, 0}: # Do final val with best.pt - epochs = epoch - self.start_epoch + 1 # total training epochs - seconds = time.time() - self.train_time_start # total training seconds - LOGGER.info(f"\n{epochs} epochs completed in {seconds / 3600:.3f} hours.") + seconds = time.time() - self.train_time_start + LOGGER.info(f"\n{epoch - self.start_epoch + 1} epochs completed in {seconds / 3600:.3f} hours.") self.final_eval() - self.validator.metrics.training = {"epochs": epochs, "seconds": seconds} # add training speed if self.args.plots: self.plot_metrics() self.run_callbacks("on_train_end") @@ -504,7 +502,7 @@ class BaseTrainer: """Read results.csv into a dict using pandas.""" import pandas as pd # scope for faster 'import ultralytics' - return {k.strip(): v for k, v in pd.read_csv(self.csv).to_dict(orient="list").items()} + return pd.read_csv(self.csv).to_dict(orient="list") def save_model(self): """Save model training checkpoints with additional metadata.""" @@ -654,10 +652,11 @@ class BaseTrainer: def save_metrics(self, metrics): """Saves training metrics to a CSV file.""" keys, vals = list(metrics.keys()), list(metrics.values()) - n = len(metrics) + 1 # number of cols - s = "" if self.csv.exists() else (("%23s," * n % tuple(["epoch"] + keys)).rstrip(",") + "\n") # header + n = len(metrics) + 2 # number of cols + s = "" if self.csv.exists() else (("%s," * n % tuple(["epoch", "time"] + keys)).rstrip(",") + "\n") # header + t = time.time() - self.train_time_start with open(self.csv, "a") as f: - f.write(s + ("%23.5g," * n % tuple([self.epoch + 1] + vals)).rstrip(",") + "\n") + f.write(s + ("%.6g," * n % tuple([self.epoch + 1, t] + vals)).rstrip(",") + "\n") def plot_metrics(self): """Plot and display metrics visually."""