eval written
This commit is contained in:
@@ -79,20 +79,37 @@ class Config(ConfigParser):
|
||||
super(Config, self).__init__(**kwargs)
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _sort_combined_section_key_mapping(dict_obj):
|
||||
sorted_dict = defaultdict(dict)
|
||||
for key in dict_obj:
|
||||
section, *attr_name = key.split('_')
|
||||
attr_name = '_'.join(attr_name)
|
||||
value = str(dict_obj[key])
|
||||
|
||||
sorted_dict[section][attr_name] = value
|
||||
# noinspection PyTypeChecker
|
||||
return dict(sorted_dict)
|
||||
|
||||
@classmethod
|
||||
def read_namespace(cls, namespace: Namespace):
|
||||
|
||||
space_dict = defaultdict(dict)
|
||||
for key in namespace.__dict__:
|
||||
section, *attr_name = key.split('_')
|
||||
attr_name = '_'.join(attr_name)
|
||||
value = str(namespace.__getattribute__(key))
|
||||
|
||||
space_dict[section][attr_name] = value
|
||||
sorted_dict = cls._sort_combined_section_key_mapping(namespace.__dict__)
|
||||
new_config = cls()
|
||||
new_config.read_dict(space_dict)
|
||||
new_config.read_dict(sorted_dict)
|
||||
return new_config
|
||||
|
||||
def update(self, mapping):
|
||||
sorted_dict = self._sort_combined_section_key_mapping(mapping)
|
||||
for section in sorted_dict:
|
||||
if self.has_section(section):
|
||||
pass
|
||||
else:
|
||||
self.add_section(section)
|
||||
for option, value in sorted_dict[section].items():
|
||||
self.set(section, option, value)
|
||||
return self
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
item = super(Config, self).get(*args, **kwargs)
|
||||
try:
|
||||
@@ -108,5 +125,4 @@ class Config(ConfigParser):
|
||||
|
||||
with path.open('w') as configfile:
|
||||
super().write(configfile)
|
||||
|
||||
return True
|
||||
|
||||
@@ -78,6 +78,14 @@ class Logger(LightningLoggerBase):
|
||||
def log_config_as_ini(self):
|
||||
self.config.write(self.log_dir)
|
||||
|
||||
def log_metric(self, metric_name, metric_value, **kwargs):
|
||||
self.testtubelogger.log_metrics(dict(metric_name=metric_value))
|
||||
self.neptunelogger.log_metric(metric_name, metric_value, **kwargs)
|
||||
|
||||
def log_image(self, name, image, **kwargs):
|
||||
self.neptunelogger.log_image(name, image, **kwargs)
|
||||
image.savefig(self.log_dir / name)
|
||||
|
||||
def save(self):
|
||||
self.testtubelogger.save()
|
||||
self.neptunelogger.save()
|
||||
|
||||
Reference in New Issue
Block a user