我正在尝试使用 Mlflow 记录评估期间的步骤,但只能记录最后一步。使用 mlflow.tensorflow.autolog() 我可以在保存检查点时记录一些指标(如丢失),每 100 个步骤在 RunConfig 中定义。但是,我还需要每评估模型 100 步保存一次准确度和 top3error。这是我的代码:
def top3error(features, labels, predictions):
return {'top3error': tf.metrics.mean(tf.nn.in_top_k(predictions=predictions['logits'],
targets=labels,
k=3))}
# Log metrics
mlflow.tensorflow.autolog()
with mlflow.start_run():
steps = 1000
mlflow.log_param("Steps", steps)
'''Training & Validation'''
train_spec = tf.estimator.TrainSpec(input_fn=generate_input_fn(train),
max_steps=steps)
eval_spec = tf.estimator.EvalSpec(name='validation',
input_fn=generate_input_fn(test, num_epochs=1))
tf.logging.info("Starting Run...")
results = tf.estimator.train_and_evaluate(m, train_spec, eval_spec)
'''Log Run'''
mlflow.log_metric("accuracy", results[0]['accuracy'])
mlflow.log_metric("top3error", results[0]['top3error'])
这是模型中使用的 RunConfig:
config=tf.estimator.RunConfig(
model_dir=model_dir,
save_checkpoints_steps=100,
)
提前致谢