跳至内容

参考资料 ultralytics/utils/callbacks/hub.py

备注

该文件可在https://github.com/ultralytics/ultralytics/blob/main/ ultralytics/utils/callbacks/ hub.py 上获取。如果您发现问题,请通过提交 Pull Request🛠️ 帮助修复。谢谢🙏!



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)