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|
+
import pandas as pd
|
| 5 |
+
from typing import Dict, List
|
| 6 |
+
import streamlit as st
|
| 7 |
+
from st_aggrid import AgGrid, GridOptionsBuilder
|
| 8 |
+
|
| 9 |
+
def create_config_dataframe(flattened_configs: List[Dict], ids: List[str]) -> pd.DataFrame:
|
| 10 |
+
df = pd.DataFrame(flattened_configs)
|
| 11 |
+
df.columns = [str(col).strip() for col in df.columns]
|
| 12 |
+
df.insert(0, 'id', ids)
|
| 13 |
+
return df
|
| 14 |
+
|
| 15 |
+
def flatten_dict(d, parent_key='', sep='.'):
|
| 16 |
+
items = []
|
| 17 |
+
for k, v in d.items():
|
| 18 |
+
new_key = f"{parent_key}{sep}{k}" if parent_key else k
|
| 19 |
+
if isinstance(v, dict):
|
| 20 |
+
items.extend(flatten_dict(v, new_key, sep=sep).items())
|
| 21 |
+
else:
|
| 22 |
+
items.append((new_key, v))
|
| 23 |
+
return dict(items)
|
| 24 |
+
|
| 25 |
+
@st.cache_data
|
| 26 |
+
def load_config_data():
|
| 27 |
+
log_dir = Path(__file__).parent / '../.bulb/logs'
|
| 28 |
+
configs = []
|
| 29 |
+
dir_ids = []
|
| 30 |
+
|
| 31 |
+
for dir_name in log_dir.glob('*'):
|
| 32 |
+
if not dir_name.is_dir():
|
| 33 |
+
continue
|
| 34 |
+
|
| 35 |
+
config_path = dir_name / 'config.json'
|
| 36 |
+
if not config_path.exists():
|
| 37 |
+
continue
|
| 38 |
+
|
| 39 |
+
with open(config_path, 'r') as f:
|
| 40 |
+
config = json.load(f)
|
| 41 |
+
flattened_config = flatten_dict(config)
|
| 42 |
+
configs.append(flattened_config)
|
| 43 |
+
dir_ids.append(dir_name.name)
|
| 44 |
+
return create_config_dataframe(configs, dir_ids)
|
| 45 |
+
|
| 46 |
+
@st.cache_data
|
| 47 |
+
def load_eval_data():
|
| 48 |
+
log_dir = Path(__file__).parent / '../.bulb/logs'
|
| 49 |
+
scores = []
|
| 50 |
+
dir_ids = []
|
| 51 |
+
|
| 52 |
+
for dir_name in log_dir.glob('*'):
|
| 53 |
+
if not dir_name.is_dir():
|
| 54 |
+
continue
|
| 55 |
+
|
| 56 |
+
eval_path = dir_name / 'eval_log.json'
|
| 57 |
+
if not eval_path.exists():
|
| 58 |
+
continue
|
| 59 |
+
|
| 60 |
+
with open(eval_path, 'r') as f:
|
| 61 |
+
eval_data = json.load(f)
|
| 62 |
+
score_dict = {'test/mean_score': eval_data.get('test/mean_score')}
|
| 63 |
+
scores.append(score_dict)
|
| 64 |
+
dir_ids.append(dir_name.name)
|
| 65 |
+
|
| 66 |
+
return create_config_dataframe(scores, dir_ids)
|
| 67 |
+
|
| 68 |
+
@st.cache_data
|
| 69 |
+
def load_meta_data():
|
| 70 |
+
log_dir = Path(__file__).parent / '../.bulb/logs'
|
| 71 |
+
metas = []
|
| 72 |
+
dir_ids = []
|
| 73 |
+
|
| 74 |
+
for dir_name in log_dir.glob('*'):
|
| 75 |
+
if not dir_name.is_dir():
|
| 76 |
+
continue
|
| 77 |
+
|
| 78 |
+
meta_path = dir_name / 'meta.json'
|
| 79 |
+
if not meta_path.exists():
|
| 80 |
+
continue
|
| 81 |
+
|
| 82 |
+
with open(meta_path, 'r') as f:
|
| 83 |
+
meta = json.load(f)
|
| 84 |
+
metas.append(meta)
|
| 85 |
+
dir_ids.append(dir_name.name)
|
| 86 |
+
return create_config_dataframe(metas, dir_ids)
|
| 87 |
+
|
| 88 |
+
def configure_grid(df):
|
| 89 |
+
gb = GridOptionsBuilder.from_dataframe(df)
|
| 90 |
+
gb.configure_pagination(paginationAutoPageSize=True)
|
| 91 |
+
gb.configure_side_bar()
|
| 92 |
+
gb.configure_default_column(groupable=True, value=True, enableRowGroup=True, aggFunc='sum', editable=False)
|
| 93 |
+
return gb.build()
|
| 94 |
+
|
| 95 |
+
# Load data
|
| 96 |
+
config_df = load_config_data()
|
| 97 |
+
score_df = load_eval_data()
|
| 98 |
+
meta_df = load_meta_data()
|
| 99 |
+
|
| 100 |
+
experiments_df = pd.merge(
|
| 101 |
+
config_df,
|
| 102 |
+
score_df,
|
| 103 |
+
on='id',
|
| 104 |
+
how='inner'
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
# Preprocess data
|
| 108 |
+
columns_to_keep = ['id', 'Filter.name', 'checkpoint', 'model', 'task', 'test/mean_score',
|
| 109 |
+
'tags', 'start_time', 'Filter.threshold', 'Filter.seed', 'dataset']
|
| 110 |
+
filtered_df = experiments_df[columns_to_keep].copy()
|
| 111 |
+
filtered_df['Filter.threshold'] = filtered_df['Filter.threshold'].fillna('None')
|
| 112 |
+
filtered_df['Filter.seed'] = filtered_df['Filter.seed'].fillna('None')
|
| 113 |
+
filtered_df['start_time'] = pd.to_datetime(filtered_df['start_time'], format='%Y%m%d_%H%M%S')
|
| 114 |
+
|
| 115 |
+
# Grouped view
|
| 116 |
+
grouped_df = filtered_df.groupby(['model', 'Filter.name', 'tags', 'task', 'Filter.threshold']).agg({
|
| 117 |
+
'test/mean_score': ['mean', lambda x: list(x)],
|
| 118 |
+
'checkpoint': ('count', list),
|
| 119 |
+
'start_time': ('max', lambda x: sorted(x, reverse=True)),
|
| 120 |
+
'Filter.seed': ('count', list),
|
| 121 |
+
}).reset_index()
|
| 122 |
+
|
| 123 |
+
# Streamlit app
|
| 124 |
+
st.set_page_config(layout="wide")
|
| 125 |
+
st.title("Experiment Results Dashboard")
|
| 126 |
+
|
| 127 |
+
tab1, tab2, tab3 = st.tabs(["Meta Data", "Experiment Results", "Grouped Analysis"])
|
| 128 |
+
|
| 129 |
+
with tab1:
|
| 130 |
+
st.header("Experiment Metadata")
|
| 131 |
+
AgGrid(meta_df.sort_values(['start_time'], ascending=False),
|
| 132 |
+
gridOptions=configure_grid(meta_df),
|
| 133 |
+
height=400,
|
| 134 |
+
fit_columns_on_grid_load=True)
|
| 135 |
+
|
| 136 |
+
with tab2:
|
| 137 |
+
st.header("Filtered Experiment Results")
|
| 138 |
+
AgGrid(filtered_df.sort_values(['start_time'], ascending=False),
|
| 139 |
+
gridOptions=configure_grid(filtered_df),
|
| 140 |
+
height=600,
|
| 141 |
+
fit_columns_on_grid_load=True)
|
| 142 |
+
|
| 143 |
+
with tab3:
|
| 144 |
+
st.header("Grouped Performance Analysis")
|
| 145 |
+
AgGrid(grouped_df.sort_values([('start_time', 'max')], ascending=False),
|
| 146 |
+
gridOptions=configure_grid(grouped_df),
|
| 147 |
+
height=600,
|
| 148 |
+
fit_columns_on_grid_load=True)
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
streamlit
|
| 2 |
pandas
|
| 3 |
plotly
|
|
|
|
|
|
| 1 |
streamlit
|
| 2 |
pandas
|
| 3 |
plotly
|
| 4 |
+
streamlit-aggrid
|