1
1
from collections import defaultdict
2
2
from enum import Enum
3
- from typing import List , Dict , NamedTuple , Any
3
+ from typing import List , Dict , NamedTuple , Any , Optional
4
4
import numpy as np
5
5
import abc
6
6
import csv
@@ -211,11 +211,14 @@ def add_property(
211
211
) -> None :
212
212
if property_type == StatsPropertyType .HYPERPARAMETERS :
213
213
assert isinstance (value , dict )
214
- text = self ._dict_to_tensorboard ("Hyperparameters" , value )
214
+ summary = self ._dict_to_tensorboard ("Hyperparameters" , value )
215
215
self ._maybe_create_summary_writer (category )
216
- self .summary_writers [category ].add_summary (text , 0 )
216
+ if summary is not None :
217
+ self .summary_writers [category ].add_summary (summary , 0 )
217
218
218
- def _dict_to_tensorboard (self , name : str , input_dict : Dict [str , Any ]) -> str :
219
+ def _dict_to_tensorboard (
220
+ self , name : str , input_dict : Dict [str , Any ]
221
+ ) -> Optional [bytes ]:
219
222
"""
220
223
Convert a dict to a Tensorboard-encoded string.
221
224
:param name: The name of the text.
@@ -232,8 +235,10 @@ def _dict_to_tensorboard(self, name: str, input_dict: Dict[str, Any]) -> str:
232
235
s = sess .run (s_op )
233
236
return s
234
237
except Exception :
235
- logger .warning ("Could not write text summary for Tensorboard." )
236
- return ""
238
+ logger .warning (
239
+ f"Could not write { name } summary for Tensorboard: { input_dict } "
240
+ )
241
+ return None
237
242
238
243
239
244
class CSVWriter (StatsWriter ):
0 commit comments