我使用了 MLflow 并使用下面的函数(来自 pydataberlin)记录了参数。
def train(alpha=0.5, l1_ratio=0.5):
# train a model with given parameters
warnings.filterwarnings("ignore")
np.random.seed(40)
# Read the wine-quality csv file (make sure you're running this from the root of MLflow!)
data_path = "data/wine-quality.csv"
train_x, train_y, test_x, test_y = load_data(data_path)
# Useful for multiple runs (only doing one run in this sample notebook)
with mlflow.start_run():
# Execute ElasticNet
lr = ElasticNet(alpha=alpha, l1_ratio=l1_ratio, random_state=42)
lr.fit(train_x, train_y)
# Evaluate Metrics
predicted_qualities = lr.predict(test_x)
(rmse, mae, r2) = eval_metrics(test_y, predicted_qualities)
# Print out metrics
print("Elasticnet model (alpha=%f, l1_ratio=%f):" % (alpha, l1_ratio))
print(" RMSE: %s" % rmse)
print(" MAE: %s" % mae)
print(" R2: %s" % r2)
# Log parameter, metrics, and model to MLflow
mlflow.log_param(key="alpha", value=alpha)
mlflow.log_param(key="l1_ratio", value=l1_ratio)
mlflow.log_metric(key="rmse", value=rmse)
mlflow.log_metrics({"mae": mae, "r2": r2})
mlflow.log_artifact(data_path)
print("Save to: {}".format(mlflow.get_artifact_uri()))
mlflow.sklearn.log_model(lr, "model")
一旦我使用其参数运行
train()
,在 UI 中我看不到工件,但我可以看到模型及其参数和指标。
在工件选项卡中,它被写入
No Artifacts Recorded Use the log artifact APIs to store file outputs from MLflow runs.
但是在模型文件夹的查找器中,所有工件都与模型Pickle一起存在。
帮助
这段代码不是在本地运行吗?您是否正在移动 mlruns 文件夹?我建议检查 meta.yaml 文件中存在的工件 URI。如果那里的路径不正确,可能会出现此类问题。
我也遇到了同样的问题(
mlflow.pytorch
)。对我来说,它是通过替换 log_model()
和 log_atrifacts()
来修复的。
所以记录该工件的人是:
mlflow.log_metric("metric name", [metric value])
mlflow.pytorch.log_model(model, "model")
mlflow.log_artifacts(output_dir)
此外,对于终端中的
ui
,请cd到mlruns
所在的目录。例如,如果 mlruns
的位置是 ...\your-project\mlruns
:
cd ...\your-project
进入安装
mlflow
的环境。
...\your-project> conda activate [myenv]
然后,运行
mlflow ui
(myenv) ...\your-project> mlflow ui
我也有类似的问题。 更改脚本文件夹后,我的 UI 未显示新的运行。
对我有用的解决方案是在启动新 UI 之前停止所有 MLflow UI,以防您更改文件夹。
我在本地托管的 Jupyter Notebook 中运行相同的 Python 代码,当我在包含 Jupyter Notebook 的目录中运行
mlflow ui
时,问题已解决。
我在运行 mlflow 服务器并在 S3 中存储工件时遇到了这个问题。能够通过安装修复
boto3
我也遇到过 ML Flow UI 不显示任何数据的问题,即使它们是在跟踪 URI 下创建的。希望以下内容对某人有所帮助。
就我而言,我刚刚在项目目录下创建了一个文件夹 mlflow.set_tracking_uri("./model_metrics") 下面用于激活 mlflow。 Experiment_id= mlflow.start_run()
带有实验ID:
运行 MLFlow UI 命令以及 --backend-store-uri=./model_metrics。