Skip to content

Reference for ultralytics/utils/callbacks/neptune.py

Improvements

This page is sourced from https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/callbacks/neptune.py. Have an improvement or example to add? Open a Pull Request — thank you! 🙏


function ultralytics.utils.callbacks.neptune._log_scalars

def _log_scalars(scalars: dict, step: int = 0) -> None

Log scalars to the NeptuneAI experiment logger.

Args

NameTypeDescriptionDefault
scalarsdictDictionary of scalar values to log to NeptuneAI.required
stepint, optionalThe current step or iteration number for logging.0

Examples

>>> metrics = {"mAP": 0.85, "loss": 0.32}
>>> _log_scalars(metrics, step=100)
Source code in ultralytics/utils/callbacks/neptune.pyView on GitHub
def _log_scalars(scalars: dict, step: int = 0) -> None:
    """Log scalars to the NeptuneAI experiment logger.

    Args:
        scalars (dict): Dictionary of scalar values to log to NeptuneAI.
        step (int, optional): The current step or iteration number for logging.

    Examples:
        >>> metrics = {"mAP": 0.85, "loss": 0.32}
        >>> _log_scalars(metrics, step=100)
    """
    if run:
        for k, v in scalars.items():
            run[k].append(value=v, step=step)





function ultralytics.utils.callbacks.neptune._log_images

def _log_images(imgs_dict: dict, group: str = "") -> None

Log images to the NeptuneAI experiment logger.

This function logs image data to Neptune.ai when a valid Neptune run is active. Images are organized under the specified group name.

Args

NameTypeDescriptionDefault
imgs_dictdictDictionary of images to log, with keys as image names and values as image data.required
groupstr, optionalGroup name to organize images under in the Neptune UI.""

Examples

>>> # Log validation images
>>> _log_images({"val_batch": img_tensor}, group="validation")
Source code in ultralytics/utils/callbacks/neptune.pyView on GitHub
def _log_images(imgs_dict: dict, group: str = "") -> None:
    """Log images to the NeptuneAI experiment logger.

    This function logs image data to Neptune.ai when a valid Neptune run is active. Images are organized under the
    specified group name.

    Args:
        imgs_dict (dict): Dictionary of images to log, with keys as image names and values as image data.
        group (str, optional): Group name to organize images under in the Neptune UI.

    Examples:
        >>> # Log validation images
        >>> _log_images({"val_batch": img_tensor}, group="validation")
    """
    if run:
        for k, v in imgs_dict.items():
            run[f"{group}/{k}"].upload(File(v))





function ultralytics.utils.callbacks.neptune._log_plot

def _log_plot(title: str, plot_path: str) -> None

Log plots to the NeptuneAI experiment logger.

Args

NameTypeDescriptionDefault
titlestrrequired
plot_pathstrrequired
Source code in ultralytics/utils/callbacks/neptune.pyView on GitHub
def _log_plot(title: str, plot_path: str) -> None:
    """Log plots to the NeptuneAI experiment logger."""
    import matplotlib.image as mpimg
    import matplotlib.pyplot as plt

    img = mpimg.imread(plot_path)
    fig = plt.figure()
    ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect="auto", xticks=[], yticks=[])  # no ticks
    ax.imshow(img)
    run[f"Plots/{title}"].upload(fig)





function ultralytics.utils.callbacks.neptune.on_pretrain_routine_start

def on_pretrain_routine_start(trainer) -> None

Initialize NeptuneAI run and log hyperparameters before training starts.

Args

NameTypeDescriptionDefault
trainerrequired
Source code in ultralytics/utils/callbacks/neptune.pyView on GitHub
def on_pretrain_routine_start(trainer) -> None:
    """Initialize NeptuneAI run and log hyperparameters before training starts."""
    try:
        global run
        run = neptune.init_run(
            project=trainer.args.project or "Ultralytics",
            name=trainer.args.name,
            tags=["Ultralytics"],
        )
        run["Configuration/Hyperparameters"] = {k: "" if v is None else v for k, v in vars(trainer.args).items()}
    except Exception as e:
        LOGGER.warning(f"NeptuneAI installed but not initialized correctly, not logging this run. {e}")





function ultralytics.utils.callbacks.neptune.on_train_epoch_end

def on_train_epoch_end(trainer) -> None

Log training metrics and learning rate at the end of each training epoch.

Args

NameTypeDescriptionDefault
trainerrequired
Source code in ultralytics/utils/callbacks/neptune.pyView on GitHub
def on_train_epoch_end(trainer) -> None:
    """Log training metrics and learning rate at the 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)
    if trainer.epoch == 1:
        _log_images({f.stem: str(f) for f in trainer.save_dir.glob("train_batch*.jpg")}, "Mosaic")





function ultralytics.utils.callbacks.neptune.on_fit_epoch_end

def on_fit_epoch_end(trainer) -> None

Log model info and validation metrics at the end of each fit epoch.

Args

NameTypeDescriptionDefault
trainerrequired
Source code in ultralytics/utils/callbacks/neptune.pyView on GitHub
def on_fit_epoch_end(trainer) -> None:
    """Log model info and validation metrics at the end of each fit epoch."""
    if run and trainer.epoch == 0:
        from ultralytics.utils.torch_utils import model_info_for_loggers

        run["Configuration/Model"] = model_info_for_loggers(trainer)
    _log_scalars(trainer.metrics, trainer.epoch + 1)





function ultralytics.utils.callbacks.neptune.on_val_end

def on_val_end(validator) -> None

Log validation images at the end of validation.

Args

NameTypeDescriptionDefault
validatorrequired
Source code in ultralytics/utils/callbacks/neptune.pyView on GitHub
def on_val_end(validator) -> None:
    """Log validation images at the end of validation."""
    if run:
        # Log val_labels and val_pred
        _log_images({f.stem: str(f) for f in validator.save_dir.glob("val*.jpg")}, "Validation")





function ultralytics.utils.callbacks.neptune.on_train_end

def on_train_end(trainer) -> None

Log final results, plots, and model weights at the end of training.

Args

NameTypeDescriptionDefault
trainerrequired
Source code in ultralytics/utils/callbacks/neptune.pyView on GitHub
def on_train_end(trainer) -> None:
    """Log final results, plots, and model weights at the end of training."""
    if run:
        # Log final results, CM matrix + PR plots
        for f in [*trainer.plots.keys(), *trainer.validator.plots.keys()]:
            if "batch" not in f.name:
                _log_plot(title=f.stem, plot_path=f)
        # Log the final model
        run[f"weights/{trainer.args.name or trainer.args.task}/{trainer.best.name}"].upload(File(str(trainer.best)))





📅 Created 2 years ago ✏️ Updated 10 days ago
glenn-jocherjk4eBurhan-Q