-
Notifications
You must be signed in to change notification settings - Fork 752
Expand file tree
/
Copy pathexport_utils.py
More file actions
37 lines (30 loc) · 1.22 KB
/
export_utils.py
File metadata and controls
37 lines (30 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# coding=utf-8
# Copyright 2020 The TF-Agents Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utils to export metrics."""
from absl import logging
def export_metrics(step, metrics, loss_info=None):
"""Exports the metrics and loss information to logging.info.
Args:
step: Integer denoting the round at which we log the metrics.
metrics: List of `TF metrics` to log.
loss_info: An optional instance of `LossInfo` whose value is logged.
"""
def logging_at_step_fn(name, value):
logging_msg = f'[step={step}] {name} = {value}.'
logging.info(logging_msg)
for metric in metrics:
logging_at_step_fn(metric.name, metric.result())
if loss_info is not None:
logging_at_step_fn('loss', loss_info.loss)