Created
February 1, 2021 14:16
-
-
Save dmitrysarov/d846812b85892cbd0fa2a9c8478394f7 to your computer and use it in GitHub Desktop.
Print sacred experiments from FileObserver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import os | |
import json | |
def flatten_dict(d): | |
""" | |
transform dict of dicts to single level dict | |
""" | |
fd = {} | |
for k, v in d.items(): | |
if isinstance(v, dict): | |
fd_ = flatten_dict(v) | |
fd_ = {f'{k}.{k_}': v_ for k_, v_ in fd_.items()} | |
fd.update(fd_) | |
else: | |
fd.update({k: v}) | |
return fd | |
root_path = '/project/gnn/GNN_tracking/sacred_log/' | |
experiments_struct = {} | |
for p in os.listdir(root_path): | |
ex_st = {} | |
if p.isdigit(): | |
for p_ in os.listdir(os.path.join(root_path, p)): | |
if p_.endswith('.json'): | |
with open(os.path.join(root_path, p, p_), 'r') as f: | |
data = json.load(f) | |
ex_st.update(flatten_dict(data)) | |
experiments_struct[p] = ex_st | |
df = pd.DataFrame.from_dict(experiments_struct, orient='index') | |
# cols = [c for c in df.columns if not c.lower().startswith('meta')] | |
# drop columns where identical | |
for column in df.columns: | |
df[column] = df[column].apply(str) # convert lists to hashable str | |
df=df[[i for i in df if len(set(df[i]))>1]] | |
pd.set_option('display.max_rows', len(df)) | |
pd.set_option('display.max_columns', len(df.columns)) | |
# pd.set_option('display.max_colwidth', -1) | |
df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment