|
|
@ -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)
|
|
|
|