-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcollect_data.py
55 lines (42 loc) · 1.57 KB
/
collect_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("-d", "--directory", dest="directory",
help="Directory of log files", metavar="DIR")
args = parser.parse_args()
directory = args.directory
if args.directory is None:
raise FileNotFoundError("Please use the -d flag to specify a directory with the linear probing logs.")
all_results = {}
for filename in os.listdir(directory):
sline = None
resultline = None
searchfile = open(directory + filename, "r")
for line in searchfile:
if "Namespace" in line:
sline = line
if line.startswith("["):
resultline = line
s = sline[11:-2]
sdict = {}
for item in s.split(','):
try:
k, v = item.split("=")
sdict[k.strip()] = eval(v.strip())
except (ValueError, SyntaxError, NameError):
pass
result = max(eval(resultline))
model_name = os.path.dirname(sdict.get("pretrained"))
checkpoint = sdict.get("pretrained").split("/")[-1].split(".")[-3].replace("checkpoint_", "")
epoch = eval(checkpoint.split("_")[0].lstrip("0") or "0")
try:
batch = eval(checkpoint.split("_")[1].lstrip("0") or "0")
checkpoint = (epoch, batch)
except:
checkpoint = epoch
if model_name not in all_results:
all_results[model_name] = [(result, checkpoint)]
else:
all_results.get(model_name).append((result, checkpoint))
for experiment, accuracy in all_results.items():
print(experiment, sorted(accuracy, key=lambda x: x[1]))