def_log_debug_samples(files,title='Debug Samples')->None:""" Log files (images) as debug samples in the ClearML task. Args: files (list): A list of file paths in PosixPath format. title (str): A title that groups together images with the same values. """task=Task.current_task()iftask:forfinfiles:iff.exists():it=re.search(r'_batch(\d+)',f.name)iteration=int(it.groups()[0])ifitelse0task.get_logger().report_image(title=title,series=f.name.replace(it.group(),''),local_path=str(f),iteration=iteration)
_log_plot
Log an image as a plot in the plot section of ClearML.
Parameters:
Name
Type
Description
Default
title
str
The title of the plot.
required
plot_path
str
The path to the saved image file.
required
Source code in ultralytics/yolo/utils/callbacks/clearml.py
def_log_plot(title,plot_path)->None:""" Log an image as a plot in the plot section of ClearML. Args: title (str): The title of the plot. plot_path (str): The path to the saved image file. """img=mpimg.imread(plot_path)fig=plt.figure()ax=fig.add_axes([0,0,1,1],frameon=False,aspect='auto',xticks=[],yticks=[])# no ticksax.imshow(img)Task.current_task().get_logger().report_matplotlib_figure(title=title,series='',figure=fig,report_interactive=False)
on_pretrain_routine_start
Runs at start of pretraining routine; initializes and connects/ logs task to ClearML.
Source code in ultralytics/yolo/utils/callbacks/clearml.py
defon_pretrain_routine_start(trainer):"""Runs at start of pretraining routine; initializes and connects/ logs task to ClearML."""try:task=Task.current_task()iftask:# Make sure the automatic pytorch and matplotlib bindings are disabled!# We are logging these plots and model files manually in the integrationPatchPyTorchModelIO.update_current_task(None)PatchedMatplotlib.update_current_task(None)else:task=Task.init(project_name=trainer.args.projector'YOLOv8',task_name=trainer.args.name,tags=['YOLOv8'],output_uri=True,reuse_last_task_id=False,auto_connect_frameworks={'pytorch':False,'matplotlib':False})LOGGER.warning('ClearML Initialized a new task. If you want to run remotely, ''please add clearml-init and connect your arguments before initializing YOLO.')task.connect(vars(trainer.args),name='General')exceptExceptionase:LOGGER.warning(f'WARNING ⚠️ ClearML installed but not initialized correctly, not logging this run. {e}')
on_train_epoch_end
Source code in ultralytics/yolo/utils/callbacks/clearml.py
defon_train_epoch_end(trainer):task=Task.current_task()iftask:"""Logs debug samples for the first epoch of YOLO training."""iftrainer.epoch==1:_log_debug_samples(sorted(trainer.save_dir.glob('train_batch*.jpg')),'Mosaic')"""Report the current training progress."""fork,vintrainer.validator.metrics.results_dict.items():task.get_logger().report_scalar('train',k,v,iteration=trainer.epoch)
on_fit_epoch_end
Reports model information to logger at the end of an epoch.
Source code in ultralytics/yolo/utils/callbacks/clearml.py
defon_fit_epoch_end(trainer):"""Reports model information to logger at the end of an epoch."""task=Task.current_task()iftask:# You should have access to the validation bboxes under jdicttask.get_logger().report_scalar(title='Epoch Time',series='Epoch Time',value=trainer.epoch_time,iteration=trainer.epoch)iftrainer.epoch==0:fork,vinmodel_info_for_loggers(trainer).items():task.get_logger().report_single_value(k,v)
on_val_end
Logs validation results including labels and predictions.
Source code in ultralytics/yolo/utils/callbacks/clearml.py
defon_val_end(validator):"""Logs validation results including labels and predictions."""ifTask.current_task():# Log val_labels and val_pred_log_debug_samples(sorted(validator.save_dir.glob('val*.jpg')),'Validation')
on_train_end
Logs final model and its name on training completion.
Source code in ultralytics/yolo/utils/callbacks/clearml.py
defon_train_end(trainer):"""Logs final model and its name on training completion."""task=Task.current_task()iftask:# Log final results, CM matrix + PR plotsfiles=['results.png','confusion_matrix.png','confusion_matrix_normalized.png',*(f'{x}_curve.png'forxin('F1','PR','P','R'))]files=[(trainer.save_dir/f)forfinfilesif(trainer.save_dir/f).exists()]# filterforfinfiles:_log_plot(title=f.stem,plot_path=f)# Report final metricsfork,vintrainer.validator.metrics.results_dict.items():task.get_logger().report_single_value(k,v)# Log the final modeltask.update_output_model(model_path=str(trainer.best),model_name=trainer.args.name,auto_delete_file=False)
Created 2023-04-16, Updated 2023-05-17 Authors: Glenn Jocher (3)