์ฝ˜ํ…์ธ ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

์ฐธ์กฐ ultralytics/utils/callbacks/hub.py

์ฐธ๊ณ 

์ด ํŒŒ์ผ์€ https://github.com/ultralytics/ ultralytics/blob/main/ ultralytics/utils/callbacks/ hub.py์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฌธ์ œ๋ฅผ ๋ฐœ๊ฒฌํ•˜๋ฉด ํ’€ ๋ฆฌํ€˜์ŠคํŠธ ๐Ÿ› ๏ธ ์— ๊ธฐ์—ฌํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋„๋ก ๋„์™€์ฃผ์„ธ์š”. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐Ÿ™!



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

์—…๋กœ๋“œ ์†๋„ ์ œํ•œ ํƒ€์ด๋จธ๋ฅผ ์‹œ์ž‘ํ•˜๊ธฐ ์ „์— ์ •๋ณด๋ฅผ ๊ธฐ๋กํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/utils/callbacks/hub.py
def on_pretrain_routine_end(trainer):
    """Logs info before starting timer for upload rate limit."""
    session = getattr(trainer, "hub_session", None)
    if session:
        # Start timer for upload rate limit
        session.timers = {
            "metrics": time(),
            "ckpt": time(),
        }  # start timer on session.rate_limit



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

๊ฐ ์—ํฌํฌ๊ฐ€ ๋๋‚  ๋•Œ๋งˆ๋‹ค ๊ต์œก ์ง„ํ–‰๋ฅ  ๋ฉ”ํŠธ๋ฆญ์„ ์—…๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/utils/callbacks/hub.py
def on_fit_epoch_end(trainer):
    """Uploads training progress metrics at the end of each epoch."""
    session = getattr(trainer, "hub_session", None)
    if session:
        # Upload metrics after val end
        all_plots = {
            **trainer.label_loss_items(trainer.tloss, prefix="train"),
            **trainer.metrics,
        }
        if trainer.epoch == 0:
            from ultralytics.utils.torch_utils import model_info_for_loggers

            all_plots = {**all_plots, **model_info_for_loggers(trainer)}

        session.metrics_queue[trainer.epoch] = json.dumps(all_plots)
        if time() - session.timers["metrics"] > session.rate_limits["metrics"]:
            session.upload_metrics()
            session.timers["metrics"] = time()  # reset timer
            session.metrics_queue = {}  # reset queue



ultralytics.utils.callbacks.hub.on_model_save(trainer)

์†๋„ ์ œํ•œ์ด ์žˆ๋Š” Ultralytics HUB ์— ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/utils/callbacks/hub.py
def on_model_save(trainer):
    """Saves checkpoints to Ultralytics HUB with rate limiting."""
    session = getattr(trainer, "hub_session", None)
    if session:
        # Upload checkpoints with rate limiting
        is_best = trainer.best_fitness == trainer.fitness
        if time() - session.timers["ckpt"] > session.rate_limits["ckpt"]:
            LOGGER.info(f"{PREFIX}Uploading checkpoint {HUB_WEB_ROOT}/models/{session.model_id}")
            session.upload_model(trainer.epoch, trainer.last, is_best)
            session.timers["ckpt"] = time()  # reset timer



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

๊ต์œก์ด ๋๋‚˜๋ฉด ์ตœ์ข… ๋ชจ๋ธ๊ณผ ์ง€ํ‘œ๋ฅผ Ultralytics HUB ์— ์—…๋กœ๋“œํ•˜์„ธ์š”.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/utils/callbacks/hub.py
def on_train_end(trainer):
    """Upload final model and metrics to Ultralytics HUB at the end of training."""
    session = getattr(trainer, "hub_session", None)
    if session:
        # Upload final model and metrics with exponential standoff
        LOGGER.info(f"{PREFIX}Syncing final model...")
        session.upload_model(
            trainer.epoch,
            trainer.best,
            map=trainer.metrics.get("metrics/mAP50-95(B)", 0),
            final=True,
        )
        session.alive = False  # stop heartbeats
        LOGGER.info(f"{PREFIX}Done โœ…\n" f"{PREFIX}View model at {session.model_url} ๐Ÿš€")



ultralytics.utils.callbacks.hub.on_train_start(trainer)

์—ด์ฐจ ์ถœ๋ฐœ ์‹œ ์ด๋ฒคํŠธ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/utils/callbacks/hub.py
def on_train_start(trainer):
    """Run events on train start."""
    events(trainer.args)



ultralytics.utils.callbacks.hub.on_val_start(validator)

์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ์‹œ์ž‘ ์‹œ ์ด๋ฒคํŠธ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/utils/callbacks/hub.py
def on_val_start(validator):
    """Runs events on validation start."""
    events(validator.args)



ultralytics.utils.callbacks.hub.on_predict_start(predictor)

์‹œ์ž‘ ์˜ˆ์ธก ์‹œ ์ด๋ฒคํŠธ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/utils/callbacks/hub.py
def on_predict_start(predictor):
    """Run events on predict start."""
    events(predictor.args)



ultralytics.utils.callbacks.hub.on_export_start(exporter)

๋‚ด๋ณด๋‚ด๊ธฐ ์‹œ์ž‘ ์‹œ ์ด๋ฒคํŠธ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/utils/callbacks/hub.py
def on_export_start(exporter):
    """Run events on export start."""
    events(exporter.args)





2023-11-12 ์ƒ์„ฑ, 2023-11-25 ์—…๋ฐ์ดํŠธ๋จ
์ž‘์„ฑ์ž: glenn-jocher (3), Laughing-q (1)