─░├žeri─če ge├ž

Referans i├žin ultralytics/utils/callbacks/mlflow.py

Not

Bu dosya https://github.com/ultralytics/ultralytics/blob/main/ ultralytics/utils/callbacks/mlflow .py adresinde mevcuttur. Bir sorun tespit ederseniz l├╝tfen bir ├çekme ─░ste─či ­čŤá´ŞĆ ile katk─▒da bulunarak d├╝zeltilmesine yard─▒mc─▒ olun. Te┼čekk├╝rler ­čÖĆ!



ultralytics.utils.callbacks.mlflow.sanitize_dict(x)

Sanitize dictionary keys by removing parentheses and converting values to floats.

Kaynak kodu ultralytics/utils/callbacks/mlflow.py
def sanitize_dict(x):
    """Sanitize dictionary keys by removing parentheses and converting values to floats."""
    return {k.replace("(", "").replace(")", ""): float(v) for k, v in x.items()}



ultralytics.utils.callbacks.mlflow.on_pretrain_routine_end(trainer)

├ľn e─čitim rutininin sonunda e─čitim parametrelerini MLflow'a g├╝nl├╝─če kaydedin.

Bu fonksiyon, ortam de─či┼čkenlerine ve e─čitici arg├╝manlar─▒na dayal─▒ olarak MLflow g├╝nl├╝─č├╝n├╝ ayarlar. ─░zleme URI'sini ayarlar, deney ad─▒ ve ├žal─▒┼čt─▒rma ad─▒n─▒ girdikten sonra, zaten etkin de─čilse MLflow ├žal─▒┼čt─▒rmas─▒n─▒ ba┼člat─▒r. Son olarak parametreleri g├╝nl├╝─če kaydeder e─čitmenden.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
trainer BaseTrainer

G├╝nl├╝─če kaydedilecek arg├╝manlar─▒ ve parametreleri i├žeren e─čitim nesnesi.

gerekli
K├╝resel

mlflow: G├╝nl├╝k kayd─▒ i├žin kullan─▒lacak i├že aktar─▒lm─▒┼č mlflow mod├╝l├╝.

Ortam De─či┼čkenleri

MLFLOW_TRACKING_URI: MLflow izleme i├žin URI. Ayarlanmam─▒┼čsa, varsay─▒lan de─čer 'runs/mlflow' olur. MLFLOW_EXPERIMENT_NAME: MLflow deneyinin ad─▒. Ayarlanmazsa, varsay─▒lan olarak trainer.args.project olarak ayarlan─▒r. MLFLOW_RUN: MLflow ├žal─▒┼čt─▒rmas─▒n─▒n ad─▒. Ayarlanmam─▒┼čsa, varsay─▒lan olarak trainer.args.name de─čerini al─▒r. MLFLOW_KEEP_RUN_ACTIVE: E─čitimin bitiminden sonra MLflow ├žal─▒┼čmas─▒n─▒n etkin tutulup tutulmayaca─č─▒n─▒ belirten boolean.

Kaynak kodu ultralytics/utils/callbacks/mlflow.py
def on_pretrain_routine_end(trainer):
    """
    Log training parameters to MLflow at the end of the pretraining routine.

    This function sets up MLflow logging based on environment variables and trainer arguments. It sets the tracking URI,
    experiment name, and run name, then starts the MLflow run if not already active. It finally logs the parameters
    from the trainer.

    Args:
        trainer (ultralytics.engine.trainer.BaseTrainer): The training object with arguments and parameters to log.

    Global:
        mlflow: The imported mlflow module to use for logging.

    Environment Variables:
        MLFLOW_TRACKING_URI: The URI for MLflow tracking. If not set, defaults to 'runs/mlflow'.
        MLFLOW_EXPERIMENT_NAME: The name of the MLflow experiment. If not set, defaults to trainer.args.project.
        MLFLOW_RUN: The name of the MLflow run. If not set, defaults to trainer.args.name.
        MLFLOW_KEEP_RUN_ACTIVE: Boolean indicating whether to keep the MLflow run active after the end of training.
    """
    global mlflow

    uri = os.environ.get("MLFLOW_TRACKING_URI") or str(RUNS_DIR / "mlflow")
    LOGGER.debug(f"{PREFIX} tracking uri: {uri}")
    mlflow.set_tracking_uri(uri)

    # Set experiment and run names
    experiment_name = os.environ.get("MLFLOW_EXPERIMENT_NAME") or trainer.args.project or "/Shared/YOLOv8"
    run_name = os.environ.get("MLFLOW_RUN") or trainer.args.name
    mlflow.set_experiment(experiment_name)

    mlflow.autolog()
    try:
        active_run = mlflow.active_run() or mlflow.start_run(run_name=run_name)
        LOGGER.info(f"{PREFIX}logging run_id({active_run.info.run_id}) to {uri}")
        if Path(uri).is_dir():
            LOGGER.info(f"{PREFIX}view at http://127.0.0.1:5000 with 'mlflow server --backend-store-uri {uri}'")
        LOGGER.info(f"{PREFIX}disable with 'yolo settings mlflow=False'")
        mlflow.log_params(dict(trainer.args))
    except Exception as e:
        LOGGER.warning(f"{PREFIX}WARNING ÔÜá´ŞĆ Failed to initialize: {e}\n" f"{PREFIX}WARNING ÔÜá´ŞĆ Not tracking this run")



ultralytics.utils.callbacks.mlflow.on_train_epoch_end(trainer)

Her e─čitim epokunun sonunda e─čitim metriklerini MLflow'a kaydedin.

Kaynak kodu ultralytics/utils/callbacks/mlflow.py
def on_train_epoch_end(trainer):
    """Log training metrics at the end of each train epoch to MLflow."""
    if mlflow:
        mlflow.log_metrics(
            metrics={
                **sanitize_dict(trainer.lr),
                **sanitize_dict(trainer.label_loss_items(trainer.tloss, prefix="train")),
            },
            step=trainer.epoch,
        )



ultralytics.utils.callbacks.mlflow.on_fit_epoch_end(trainer)

Her uyum epokunun sonunda e─čitim metriklerini MLflow'a g├╝nl├╝─če kaydedin.

Kaynak kodu ultralytics/utils/callbacks/mlflow.py
def on_fit_epoch_end(trainer):
    """Log training metrics at the end of each fit epoch to MLflow."""
    if mlflow:
        mlflow.log_metrics(metrics=sanitize_dict(trainer.metrics), step=trainer.epoch)



ultralytics.utils.callbacks.mlflow.on_train_end(trainer)

E─čitimin sonunda model eserlerini g├╝nl├╝─če kaydedin.

Kaynak kodu ultralytics/utils/callbacks/mlflow.py
def on_train_end(trainer):
    """Log model artifacts at the end of the training."""
    if not mlflow:
        return
    mlflow.log_artifact(str(trainer.best.parent))  # log save_dir/weights directory with best.pt and last.pt
    for f in trainer.save_dir.glob("*"):  # log all other files in save_dir
        if f.suffix in {".png", ".jpg", ".csv", ".pt", ".yaml"}:
            mlflow.log_artifact(str(f))
    keep_run_active = os.environ.get("MLFLOW_KEEP_RUN_ACTIVE", "False").lower() == "true"
    if keep_run_active:
        LOGGER.info(f"{PREFIX}mlflow run still alive, remember to close it using mlflow.end_run()")
    else:
        mlflow.end_run()
        LOGGER.debug(f"{PREFIX}mlflow run ended")

    LOGGER.info(
        f"{PREFIX}results logged to {mlflow.get_tracking_uri()}\n{PREFIX}disable with 'yolo settings mlflow=False'"
    )





Created 2023-11-12, Updated 2024-06-17
Authors: glenn-jocher (7), Burhan-Q (1), Laughing-q (1)