Created
March 16, 2023 10:51
-
-
Save SubhadityaMukherjee/83b4477bbc0cf0786e61a5f4bb895fe1 to your computer and use it in GitHub Desktop.
parse_query_tb_logs
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 os | |
import pandas as pd | |
from tensorboard.backend.event_processing.event_accumulator import EventAccumulator | |
from tqdm import tqdm | |
from pathlib import Path | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import clipboard | |
import base64 | |
from io import BytesIO | |
from PIL import Image | |
main_path = './runs/' | |
def get_event_files(main_path): | |
"""Return a list of event files under the given directory""" | |
all_files = [] | |
for root, _, filenames in os.walk(main_path): | |
for filename in filenames: | |
if "events.out.tfevents" in filename: | |
all_files.append(str(Path(root) / Path(filename))) | |
return all_files | |
def process_event_acc(event_acc): | |
"""Process the EventAccumulator and return a dictionary of tag values""" | |
all_tags = event_acc.Tags() | |
temp_dict = {} | |
for tag in all_tags.keys(): | |
if tag == 'scalars': | |
for subtag in all_tags[tag]: | |
temp_dict[subtag] = [tag[-1] for tag in event_acc.Scalars(tag=subtag)][-1] | |
if tag == 'tensors': | |
for subtag in all_tags[tag]: | |
temp_dict[subtag.replace('/text_summary', "")] = [tag[-1] for tag in event_acc.Tensors(tag=subtag)][0].string_val[0].decode('ascii') | |
if tag == 'images': | |
for subtag in all_tags[tag]: | |
temp_dict[subtag] = Image.open(BytesIO(event_acc.Images(subtag)[1].encoded_image_string)) | |
return temp_dict | |
def process_runs(main_path): | |
""" Iterate over all the runs and return the dataframe""" | |
all_files = get_event_files(main_path=main_path) | |
all_dict = {} | |
for files in tqdm(all_files, total = len(all_files)): | |
event_acc = EventAccumulator(files) | |
event_acc.Reload() | |
temp_dict = process_event_acc(event_acc) | |
all_dict[files] = temp_dict | |
return pd.DataFrame.from_records(all_dict).T.reset_index() | |
combined_df = process_runs(main_path=main_path) | |
# Clean based on your columns | |
combined_df = combined_df[(~pd.isnull(combined_df['experiment_name'])) & (~pd.isnull(combined_df['Loss/Val']))] | |
# Verify images based on your columns | |
filtered_df = combined_df[(~pd.isnull(combined_df['converted_proxy'])) & (~pd.isnull(combined_df['original_images']))] | |
filtered_df.iloc[0].original_images |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment