def_log_images(imgs_dict,group=""):"""Log scalars to the NeptuneAI experiment logger."""ifrun:fork,vinimgs_dict.items():run[f"{group}/{k}"].upload(File(v))
ultralytics.utils.callbacks.neptune._log_plot
_log_plot(title,plot_path)
Log plots to the NeptuneAI experiment logger.
Parameters:
Name
Type
Description
Default
title
str
Title of the plot.
required
plot_path
PosixPath | str
Path to the saved image file.
required
Source code in ultralytics/utils/callbacks/neptune.py
def_log_plot(title,plot_path):""" Log plots to the NeptuneAI experiment logger. Args: title (str): Title of the plot. plot_path (PosixPath | str): Path to the saved image file. """importmatplotlib.imageasmpimgimportmatplotlib.pyplotaspltimg=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)run[f"Plots/{title}"].upload(fig)
defon_pretrain_routine_start(trainer):"""Callback function called before the training routine starts."""try:globalrunrun=neptune.init_run(project=trainer.args.projector"YOLOv8",name=trainer.args.name,tags=["YOLOv8"])run["Configuration/Hyperparameters"]={k:""ifvisNoneelsevfork,vinvars(trainer.args).items()}exceptExceptionase:LOGGER.warning(f"WARNING ⚠️ NeptuneAI installed but not initialized correctly, not logging this run. {e}")
defon_train_epoch_end(trainer):"""Callback function called at end of each training epoch."""_log_scalars(trainer.label_loss_items(trainer.tloss,prefix="train"),trainer.epoch+1)_log_scalars(trainer.lr,trainer.epoch+1)iftrainer.epoch==1:_log_images({f.stem:str(f)forfintrainer.save_dir.glob("train_batch*.jpg")},"Mosaic")
defon_fit_epoch_end(trainer):"""Callback function called at end of each fit (train+val) epoch."""ifrunandtrainer.epoch==0:fromultralytics.utils.torch_utilsimportmodel_info_for_loggersrun["Configuration/Model"]=model_info_for_loggers(trainer)_log_scalars(trainer.metrics,trainer.epoch+1)
ultralytics.utils.callbacks.neptune.on_val_end
on_val_end(validator)
Callback function called at end of each validation.
Source code in ultralytics/utils/callbacks/neptune.py
defon_val_end(validator):"""Callback function called at end of each validation."""ifrun:# Log val_labels and val_pred_log_images({f.stem:str(f)forfinvalidator.save_dir.glob("val*.jpg")},"Validation")
ultralytics.utils.callbacks.neptune.on_train_end
on_train_end(trainer)
Callback function called at end of training.
Source code in ultralytics/utils/callbacks/neptune.py
defon_train_end(trainer):"""Callback function called at end of training."""ifrun:# 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)# Log the final modelrun[f"weights/{trainer.args.nameortrainer.args.task}/{trainer.best.name}"].upload(File(str(trainer.best)))