W&B updates (#2895)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
single_channel
Ayush Chaurasia 2 years ago committed by GitHub
parent 90ec434ebb
commit 6c65934b55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,4 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license # Ultralytics YOLO 🚀, AGPL-3.0 license
from ultralytics.yolo.utils import TESTS_RUNNING from ultralytics.yolo.utils import TESTS_RUNNING
from ultralytics.yolo.utils.torch_utils import model_info_for_loggers from ultralytics.yolo.utils.torch_utils import model_info_for_loggers
@ -11,6 +10,16 @@ try:
except (ImportError, AssertionError): except (ImportError, AssertionError):
wb = None wb = None
_processed_plots = {}
def _log_plots(plots, step):
for name, params in plots.items():
timestamp = params['timestamp']
if _processed_plots.get(name, None) != timestamp:
wb.run.log({name.stem: wb.Image(str(name))}, step=step)
_processed_plots[name] = timestamp
def on_pretrain_routine_start(trainer): def on_pretrain_routine_start(trainer):
"""Initiate and start project if module is present.""" """Initiate and start project if module is present."""
@ -20,6 +29,8 @@ def on_pretrain_routine_start(trainer):
def on_fit_epoch_end(trainer): def on_fit_epoch_end(trainer):
"""Logs training metrics and model information at the end of an epoch.""" """Logs training metrics and model information at the end of an epoch."""
wb.run.log(trainer.metrics, step=trainer.epoch + 1) wb.run.log(trainer.metrics, step=trainer.epoch + 1)
_log_plots(trainer.plots, step=trainer.epoch + 1)
_log_plots(trainer.validator.plots, step=trainer.epoch + 1)
if trainer.epoch == 0: if trainer.epoch == 0:
wb.run.log(model_info_for_loggers(trainer), step=trainer.epoch + 1) wb.run.log(model_info_for_loggers(trainer), step=trainer.epoch + 1)
@ -29,13 +40,13 @@ def on_train_epoch_end(trainer):
wb.run.log(trainer.label_loss_items(trainer.tloss, prefix='train'), step=trainer.epoch + 1) wb.run.log(trainer.label_loss_items(trainer.tloss, prefix='train'), step=trainer.epoch + 1)
wb.run.log(trainer.lr, step=trainer.epoch + 1) wb.run.log(trainer.lr, step=trainer.epoch + 1)
if trainer.epoch == 1: if trainer.epoch == 1:
wb.run.log({f.stem: wb.Image(str(f)) _log_plots(trainer.plots, step=trainer.epoch + 1)
for f in trainer.save_dir.glob('train_batch*.jpg')},
step=trainer.epoch + 1)
def on_train_end(trainer): def on_train_end(trainer):
"""Save the best model as an artifact at end of training.""" """Save the best model as an artifact at end of training."""
_log_plots(trainer.validator.plots, step=trainer.epoch + 1)
_log_plots(trainer.plots, step=trainer.epoch + 1)
art = wb.Artifact(type='model', name=f'run_{wb.run.id}_model') art = wb.Artifact(type='model', name=f'run_{wb.run.id}_model')
if trainer.best.exists(): if trainer.best.exists():
art.add_file(trainer.best) art.add_file(trainer.best)

@ -707,8 +707,14 @@ class DetMetrics(SimpleClass):
def process(self, tp, conf, pred_cls, target_cls): def process(self, tp, conf, pred_cls, target_cls):
"""Process predicted results for object detection and update metrics.""" """Process predicted results for object detection and update metrics."""
results = ap_per_class(tp, conf, pred_cls, target_cls, plot=self.plot, save_dir=self.save_dir, results = ap_per_class(tp,
names=self.names)[2:] conf,
pred_cls,
target_cls,
plot=self.plot,
save_dir=self.save_dir,
names=self.names,
on_plot=self.on_plot)[2:]
self.box.nc = len(self.names) self.box.nc = len(self.names)
self.box.update(results) self.box.update(results)

Loading…
Cancel
Save