Skip to content

Commit

Permalink
added tfx param mkdown
Browse files Browse the repository at this point in the history
  • Loading branch information
williamFalcon committed Jun 29, 2019
1 parent 1998dec commit abc8fb3
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions test_tube/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
# Experiment object
# -----------------------------

# def __init__(self, logdir=None, comment='', purge_step=None, max_queue=10,
# flush_secs=120, filename_suffix='', write_to_disk=True, **kwargs):

class Experiment(SummaryWriter):
def __init__(
self,
Expand All @@ -40,6 +39,7 @@ def __init__(
global _ROOT
_ROOT = save_dir

self.tag_markdown_saved = False
self.no_save_dir = save_dir is None
self.metrics = []
self.tags = {}
Expand Down Expand Up @@ -263,10 +263,36 @@ def save(self):
df = pd.DataFrame(self.metrics)
df.to_csv(metrics_file_path, index=False)

# whenever we save, we also save tfx

# save TFX scalars
self.export_scalars_to_json(self.get_tensorboardx_scalars_path(self.name, self.version))

# until hparam plugin is fixed, generate hparams as text
if not self.tag_markdown_saved and len(self.tags) > 0:
self.tag_markdown_saved = True
self.add_text('hparams', self.__generate_tfx_meta_log())

def __generate_tfx_meta_log(self):
header = f'''###### {self.name}, version {self.version}\n---\n'''
desc = ''
if self.description is not None:
desc = f'''#####*{self.description}*\n'''
params = f'''##### Hyperparameters\n'''

row_header = '''parameter|value\n-|-\n'''
rows = [row_header]
for k, v in self.tags.items():
row = f'''{k}|{v}\n'''
rows.append(row)

all_rows = [
header,
desc,
params
]
all_rows.extend(rows)
mkdown_log = ''.join(all_rows)
return mkdown_log

def __save_images(self, metrics):
"""
Save tags that have a png_ prefix (as images)
Expand Down Expand Up @@ -388,9 +414,13 @@ def __hash__(self):
if __name__ == '__main__':
import math
from time import sleep
e = Experiment()
e = Experiment(description='my description')
e.tag({'lr': 0.02, 'layers': 4})

for n_iter in range(2000):
e.log({'xsinx': n_iter * np.sin(n_iter)})
e.log({'testtt': n_iter * np.sin(n_iter)})
print('done')
e.save()
e.save()
e.close()

os._exit(1)

0 comments on commit abc8fb3

Please sign in to comment.