Skip to content

Commit

Permalink
Beautify dumped config json
Browse files Browse the repository at this point in the history
  • Loading branch information
mdw771 committed May 22, 2024
1 parent fe8a051 commit 7a1b371
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions generic_trainer/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def get_serializable_dict(self):
v = self.__dict__[key]
if not self.__class__.is_jsonable(v):
if isinstance(v, (tuple, list)):
v = '_'.join([str(x) for x in v])
v = [str(x) for x in v]
elif isinstance(v, OptionContainer):
v = v.get_serializable_dict()
else:
v = str(v)
d[key] = v
Expand All @@ -48,7 +50,7 @@ def dump_to_json(self, filename):
try:
f = open(filename, 'w')
d = self.get_serializable_dict()
json.dump(d, f)
json.dump(d, f, indent=4, separators=(',', ': '))
f.close()
except:
print('Failed to dump json.')
Expand All @@ -63,6 +65,23 @@ def load_from_json(self, filename):
self.__dict__[key] = d[key]
f.close()

def string_to_object(self, key, value):
"""
Create an object based on the string value of a config key.
:param key: str.
:param value: str.
:return: object.
"""
pass

def object_to_string(self, key):
"""
Convert an object in a config key to string.
:param key: str.
:return: str.
"""
pass


# =============================
# Model parameter classes
Expand Down

0 comments on commit 7a1b371

Please sign in to comment.