gpt4 book ai didi

python - MLflow:如何从现有运行中读取指标或参数?

转载 作者:行者123 更新时间:2023-12-05 00:46:25 38 4
gpt4 key购买 nike

我尝试以这种方式读取指标:

 data, info = mlflow.get_run(run_id)
print(data[1].metrics)
# example of output: {'loss': 0.01}

但它只获得最后一个值。是否可以手动读取特定指标的所有步骤?

最佳答案

我遇到了同样的问题,并且能够通过使用 mlflow.tracking.MlflowClient().get_metric_history 获取指标的所有值.这将返回您使用 mlflow.log_metric(key, value) 记录的每个值。

快速示例(未经测试)

import mlflow
trackingDir = 'file:///....'
registryDir = 'file:///...'
runID = 'my run id'
metricKey = 'loss'

client = mlflow.tracking.MlflowClient(
tracking_uri=trackingDir,
registry_uri=registryDir,
)

metrics = client.get_metric_history(runID, metricKey)

From the docs

get_metric_history(run_id, key)[source] Return a list of metricobjects corresponding to all values logged for a given metric.

Parameters run_id – Unique identifier for run

key – Metric name within the run

Returns A list of mlflow.entities.Metric entities if logged, elseempty list

from mlflow.tracking import MlflowClient

def print_metric_info(history):
for m in history:
print("name: {}".format(m.key))
print("value: {}".format(m.value))
print("step: {}".format(m.step))
print("timestamp: {}".format(m.timestamp))
print("--")

# Create a run under the default experiment (whose id is "0"). Since this is low-level
# CRUD operation, the method will create a run. To end the run, you'll have
# to explicitly end it.
client = MlflowClient()
experiment_id = "0"
run = client.create_run(experiment_id)
print("run_id:{}".format(run.info.run_id))
print("--")

# Log couple of metrics, update their initial value, and fetch each
# logged metrics' history.
for k, v in [("m1", 1.5), ("m2", 2.5)]:
client.log_metric(run.info.run_id, k, v, step=0)
client.log_metric(run.info.run_id, k, v + 1, step=1)
print_metric_info(client.get_metric_history(run.info.run_id, k))
client.set_terminated(run.info.run_id)

关于python - MLflow:如何从现有运行中读取指标或参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60616430/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com