def_log_images(path,prefix=''):iflive:name=path.name# Group images by batch to enable sliders in UIifm:=re.search(r'_batch(\d+)',name):ni=m[1]new_stem=re.sub(r'_batch(\d+)','_batch',path.stem)name=(Path(new_stem)/ni).with_suffix(path.suffix)live.log_image(os.path.join(prefix,name),path)
defon_pretrain_routine_start(trainer):try:globallivelive=dvclive.Live(save_dvc_exp=True,cache_images=True)LOGGER.info("DVCLive is detected and auto logging is enabled (run 'yolo settings dvc=False' to disable).")exceptExceptionase:LOGGER.warning(f'WARNING ⚠️ DVCLive installed but not initialized correctly, not logging this run. {e}')
defon_train_end(trainer):iflive:# At the end log the best metrics. It runs validator on the best model internally.all_metrics={**trainer.label_loss_items(trainer.tloss,prefix='train'),**trainer.metrics,**trainer.lr}formetric,valueinall_metrics.items():live.log_metric(metric,value,plot=False)_log_plots(trainer.plots,'val')_log_plots(trainer.validator.plots,'val')_log_confusion_matrix(trainer.validator)iftrainer.best.exists():live.log_artifact(trainer.best,copy=True,type='model')live.end()