浏览代码

[bugfix] summary writer no longer crashes if Hyperparameters could not be written (#4265)

* Bug fix, returnning an empty string in case of error breaks the summary writter

* addressing comments
/release_5_branch
Arthur Juliani 4 年前
当前提交
5d797091
共有 1 个文件被更改,包括 11 次插入6 次删除
  1. 17
      ml-agents/mlagents/trainers/stats.py

17
ml-agents/mlagents/trainers/stats.py


from collections import defaultdict
from enum import Enum
from typing import List, Dict, NamedTuple, Any
from typing import List, Dict, NamedTuple, Any, Optional
import numpy as np
import abc
import csv

) -> None:
if property_type == StatsPropertyType.HYPERPARAMETERS:
assert isinstance(value, dict)
text = self._dict_to_tensorboard("Hyperparameters", value)
summary = self._dict_to_tensorboard("Hyperparameters", value)
self.summary_writers[category].add_summary(text, 0)
if summary is not None:
self.summary_writers[category].add_summary(summary, 0)
def _dict_to_tensorboard(self, name: str, input_dict: Dict[str, Any]) -> str:
def _dict_to_tensorboard(
self, name: str, input_dict: Dict[str, Any]
) -> Optional[bytes]:
"""
Convert a dict to a Tensorboard-encoded string.
:param name: The name of the text.

s = sess.run(s_op)
return s
except Exception:
logger.warning("Could not write text summary for Tensorboard.")
return ""
logger.warning(
f"Could not write {name} summary for Tensorboard: {input_dict}"
)
return None
class CSVWriter(StatsWriter):

正在加载...
取消
保存