colors/scrape.py

56 lines
1.6 KiB
Python
Raw Normal View History

2023-12-31 05:20:28 +00:00
import glob
import shutil
2023-12-31 06:17:15 +00:00
from pathlib import Path
2023-12-31 05:20:28 +00:00
from check import make_image
2024-01-14 03:02:27 +00:00
def get_exps(pattern: str, splitter: str = "_", dry_run: bool = True):
2023-12-31 05:20:28 +00:00
basedir = "/teamspace/jobs/"
chkpt_basedir = "/work/colors/lightning_logs/"
location = basedir + pattern
res = glob.glob(location)
2023-12-31 06:17:15 +00:00
location = location.replace("*", "")
2023-12-31 05:20:28 +00:00
H = [] # hyperparams used
# print(res)
for r in res:
2023-12-31 06:17:15 +00:00
d = r.replace(location, "").split(splitter)
2023-12-31 05:20:28 +00:00
d = list(float(_d) for _d in d)
d[0] = int(d[0])
H.append(d)
for i, r in enumerate(res):
2023-12-31 06:17:15 +00:00
dir_path = Path(
f"/teamspace/studios/this_studio/colors/lightning_logs/version_{i}/"
)
2023-12-31 05:20:28 +00:00
dir_path.mkdir(parents=True, exist_ok=True)
g = glob.glob(r + chkpt_basedir + "*")
logs = glob.glob(g[0] + "/events*")[-1]
2024-01-10 17:50:21 +00:00
source_path = Path(logs)
2024-01-14 03:02:27 +00:00
print(logs)
if not dry_run:
c = g[0] + "/checkpoints"
latest_checkpoint = glob.glob(c + "/*")[-1]
print(latest_checkpoint)
if not dry_run:
shutil.copy(source_path, dir_path)
make_image(latest_checkpoint, f"out/version_{i}")
# make_image(latest_checkpoint, f"out/version_{i}b", color=False)
else:
print("Would copy", source_path, dir_path)
2023-12-31 05:20:28 +00:00
return H
if __name__ == "__main__":
D = get_exps("color_*", "_")
2024-01-10 17:50:21 +00:00
import numpy as np
D = np.array(D)
# print(len(D), "\n", D)
import pandas as pd
df = pd.DataFrame(D)
df.columns = ["batch_size", "alpha", "learning_rate"]
df.to_csv("experiments.csv")
print(df)