defon_pretrain_routine_end(trainer):"""Logs training parameters to MLflow."""globalmlflow,run,run_id,experiment_nameifos.environ.get('MLFLOW_TRACKING_URI')isNone:mlflow=Noneifmlflow:mlflow_location=os.environ['MLFLOW_TRACKING_URI']# "http://192.168.xxx.xxx:5000"mlflow.set_tracking_uri(mlflow_location)experiment_name=trainer.args.projector'/Shared/YOLOv8'experiment=mlflow.get_experiment_by_name(experiment_name)ifexperimentisNone:mlflow.create_experiment(experiment_name)mlflow.set_experiment(experiment_name)prefix=colorstr('MLFlow: ')try:run,active_run=mlflow,mlflow.active_run()ifnotactive_run:active_run=mlflow.start_run(experiment_id=experiment.experiment_id)run_id=active_run.info.run_idLOGGER.info(f'{prefix}Using run_id({run_id}) at {mlflow_location}')run.log_params(vars(trainer.model.args))exceptExceptionaserr:LOGGER.error(f'{prefix}Failing init - {repr(err)}')LOGGER.warning(f'{prefix}Continuing without Mlflow')
on_fit_epoch_end
Logs training metrics to Mlflow.
Source code in ultralytics/yolo/utils/callbacks/mlflow.py
defon_fit_epoch_end(trainer):"""Logs training metrics to Mlflow."""ifmlflow:metrics_dict={f"{re.sub('[()]','',k)}":float(v)fork,vintrainer.metrics.items()}run.log_metrics(metrics=metrics_dict,step=trainer.epoch)
on_train_end
Called at end of train loop to log model artifact info.
Source code in ultralytics/yolo/utils/callbacks/mlflow.py
defon_train_end(trainer):"""Called at end of train loop to log model artifact info."""ifmlflow:root_dir=Path(__file__).resolve().parents[3]run.log_artifact(trainer.last)run.log_artifact(trainer.best)run.pyfunc.log_model(artifact_path=experiment_name,code_path=[str(root_dir)],artifacts={'model_path':str(trainer.save_dir)},python_model=run.pyfunc.PythonModel())
Created 2023-04-16, Updated 2023-05-17 Authors: Glenn Jocher (4)