python - MlFlow 如何手动读取指标
问题描述
我尝试以这种方式读取指标:
data, info = mlflow.get_run(run_id)
print(data[1].metrics)
# example of output: {'loss': 0.01}
但它只得到最后一个值。是否可以手动读取特定指标的所有步骤?
解决方案
我遇到了同样的问题,并且能够使用 using 获取指标的所有值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)
get_metric_history(run_id, key)[source] 返回与给定指标记录的所有值相对应的指标对象列表。
参数 run_id – 运行的唯一标识符
key – 运行中的指标名称
如果已记录,则返回 mlflow.entities.Metric 实体的列表,否则为空列表
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)
推荐阅读
- javascript - 使用快递从搜索表单重定向?
- c - 声明和定义 C Lang
- python - 使用python将csv数据读入与csv文件相同的列
- servicestack - ServiceStack 热重载打字稿
- typescript - 从 Typescript 中的非静态方法调用静态方法
- apache - Apache:在应用了 RewriteCond 的情况下使用 VirtualHost 重定向到 URL?
- excel - Excel 集合变量
- java - Kotlin 类在 variant.javaCompiler.doLast 上不可用
- python - Tensorflow 无法在 GPU 上启动会话
- windows - 在 Python 中获取文件复制的输入