-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_table_from_metrics.py
179 lines (152 loc) · 8.5 KB
/
make_table_from_metrics.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import numpy as np
import re
import argparse
from enum import Enum
from glob import glob
from itertools import chain
from collections import defaultdict
from scipy.stats import kendalltau
class MetricsParser(object):
REGEX_PARSER = re.compile(r"([\w\b]+)_(cifar100|cifar10|ImageNet16-120)")
KNOWN_EXPERIMENTS = {
"cond_ntk_v1": ("Condition number of NTK (draft)\cite{chen2020tenas}", 11),
"regs_num": ("Expected number of ReLU regions\cite{chen2020tenas}", 12),
"acc_nngp_v1": ("Accuracy of NNGP (draft)\cite{park2020towards}", 13),
"snip": ("Snip\cite{abdelfattah2021zerocost}", 14),
"grasp": ("Grasp\cite{abdelfattah2021zerocost}", 15),
"fisher": ("Fisher\cite{abdelfattah2021zerocost}", 16),
"synflow": ("SynFlow\cite{tanaka2020pruning}", 17),
"logsynflow": ("LogSynFlow\cite{cavagnero2022freerea}", 18),
"zen_score": ("Zen-Score\cite{ming_zennas_iccv2021}", 19),
"acc_ntk": ("Accuracy of NTK\cite{jacot2018neural}", 21),
"mse_ntk": ("MSEA of NTK", 22),
"lga_ntk": ("Label-Gradient Alignment of NTK\cite{mok2022demystifying}", 23),
"fro_ntk": ("Frobenius norm of NTK\cite{xu2021knas}", 24),
"mean_ntk": ("Mean value of NTK\cite{xu2021knas}", 25),
"cond_ntk": ("Condition number of NTK\cite{chen2020tenas}", 26),
"eig_ntk": ("Eigenvalue score of NTK", 27),
"acc_ntk_corr": ("Accuracy of NTK(correlation)", 32),
"mse_ntk_corr": ("MSEA of NTK(correlation)", 32),
"lga_ntk_corr": ("Label-Gradient Alignment of NTK(correlation)", 33),
"fro_ntk_corr": ("Frobenius norm of NTK(correlation)", 34),
"mean_ntk_corr": ("Mean value of NTK(correlation)", 35),
"cond_ntk_corr": ("Condition number of NTK(correlation)", 36),
"eig_ntk_corr": ("Eigenvalue score of NTK(correlation)\cite{mellor2021neural}", 37),
"acc_nngp": ("Accuracy of NNGP\cite{park2020towards}", 41),
"mse_nngp": ("MSEA of NNGP", 42),
"lga_nngp": ("Label-Gradient Alignment of NNGP", 43),
"fro_nngp": ("Frobenius norm of NNGP", 44),
"mean_nngp": ("Mean value of NNGP", 45),
"cond_nngp": ("Condition number of NNGP", 46),
"eig_nngp": ("Eigenvalue score of NNGP", 47),
"acc_nngp_corr": ("Accuracy of NNGP(correlation)", 51),
"mse_nngp_corr": ("MSEA of NNGP(correlation)", 52),
"lga_nngp_corr": ("Label-Gradient Alignment of NNGP(correlation)", 53),
"fro_nngp_corr": ("Frobenius norm of NNGP(correlation)", 54),
"mean_nngp_corr": ("Mean value of NNGP(correlation)", 55),
"cond_nngp_corr": ("Condition number of NNGP(correlation)", 56),
"eig_nngp_corr": ("Eigenvalue score of NNGP(correlation)", 57),
"acc_nngp_read": ("Accuracy of NNGP(readout)", 61),
"mse_nngp_read": ("MSEA of NNGP(readout)", 62),
"lga_nngp_read": ("Label-Gradient Alignment of NNGP(readout)",63),
"fro_nngp_read": ("Frobenius norm of NNGP(readout)", 64),
"mean_nngp_read": ("Mean value of NNGP(readout)", 65),
"cond_nngp_read": ("Condition number of NNGP(readout)", 66),
"eig_nngp_read": ("Eigenvalue score of NNGP(readout)", 67),
"acc_nngp_read_corr": ("Accuracy of NNGP(readout, correlation)", 71),
"mse_nngp_read_corr": ("MSEA of NNGP(readout, correlation)", 72),
"lga_nngp_read_corr": ("Label-Gradient Alignment of NNGP(readout, correlation)", 73),
"fro_nngp_read_corr": ("Frobenius norm of NNGP(readout, correlation)", 74),
"mean_nngp_read_corr": ("Mean value of NNGP(readout, correlation)", 75),
"cond_nngp_read_corr": ("Condition number of NNGP(readout, correlation)", 76),
"eig_nngp_read_corr": ("Eigenvalue score of NNGP(readout, correlation)", 77),
"acc_nngp_train": ("Accuracy of NNGP(10 train batches)", 81),
"mse_nngp_train": ("MSEA of NNGP(10 train batches)", 82),
"lga_nngp_train": ("Label-Gradient Alignment of NNGP(10 train batches)", 83),
"fro_nngp_train": ("Frobenius norm of NNGP(10 train batches)", 84),
"mean_nngp_train": ("Mean value of NNGP(10 train batches)", 85),
"cond_nngp_train": ("Condition number of NNGP (10 train batches)", 86),
"eig_nngp_train": ("Eigenvalue score of NNGP (10 train batches)", 87),
"acc_nngp_bb": ("Accuracy of NNGP(more batches)", 91),
"mse_nngp_bb": ("MSEA of NNGP(more batches)", 92),
"lga_nngp_bb": ("Label-Gradient Alignment of NNGP(more batches)", 93),
"fro_nngp_bb": ("Frobenius norm of NNGP(more batches)", 94),
"mean_nngp_bb": ("Mean value of NNGP(more batches)", 95),
"cond_nngp_bb": ("Condition number of NNGP(more batches)", 96),
"eig_nngp_bb": ("Eigenvalue score of NNGP(more batches)", 97),
"acc_nngp_train_it": ("Accuracy of NNGP(20 train iterations)", 101),
"mse_nngp_train_it": ("MSEA of NNGP(20 train iterations)", 102),
"lga_nngp_train_it": ("Label-Gradient Alignment of NNGP(20 train iterations)", 103),
"fro_nngp_train_it": ("Frobenius norm of NNGP(20 train iterations)", 104),
"mean_nngp_train_it": ("Mean value of NNGP(20 train iterations)", 105),
"cond_nngp_train_it": ("Condition number of NNGP(20 train iterations)", 106),
"eig_nngp_train_it": ("Eigenvalue score of NNGP(20 train iterations)", 107),
"regs_dist_full" : ("ReLU regions distance(1 batch)\cite{mellor2021neural}", 111),
"regs_dist_max": ("ReLU regions distance(3 batches, max over batch)", 112),
"regs_dist_mean": ("ReLU regions distance(3 batches, mean over batch)", 113),
}
def __call__(self, path):
match = MetricsParser.REGEX_PARSER.search(path)
if match is None:
return None, None
experiment, dataset = match.groups()
experiment, position = MetricsParser.KNOWN_EXPERIMENTS.get(experiment, (experiment, 10000))
return experiment, dataset, position
def correlation_pearson(accuracy, metric):
return np.corrcoef(accuracy, metric)[0, 1]
def correlation_kt(accuracy, metric):
return kendalltau(accuracy, metric)[0]
def main(input: str, output: str):
parser = MetricsParser()
experiments = defaultdict(dict)
positions = {}
for i in input:
experiment, dataset, position = parser(i)
experiments[experiment][dataset] = i
positions[experiment] = position
for experiment in experiments:
for dataset in experiments[experiment]:
path = experiments[experiment][dataset]
data = np.load(path, allow_pickle=True)
times = data["times"]
metric = data["metric"]
accuracy = data["accuracy"]
corr_p = correlation_pearson(accuracy, metric)
corr_kt = correlation_kt(accuracy, metric)
experiments[experiment][dataset] = {
"time": float(np.mean(times)),
"correlation_pearson": corr_p,
"correlation_kt": corr_kt,
}
table_head = r""" \begin{tabular}{l|c|c|c|c|c|c}
\hline
\multirow{2}{*}{Methods} & \multicolumn{2}{c|}{CIFAR-10} & \multicolumn{2}{c|}{CIFAR-100} & \multicolumn{2}{c}{ImageNet16-120} \\ \cline{2-7}
& Kend-$\tau$ & Time (sec) & Kend-$\tau$ & Time (sec) & Kend-$\tau$ & Time (sec) \\ \hline
"""
table_bottom =r"\end{tabular}"
table_lines = []
for experiment in experiments:
to_write = [f"{experiment} & "]
for dataset in ["cifar10", "cifar100", "ImageNet16-120"]:
description = experiments[experiment].get(dataset, None)
if description is None:
to_write.append("& & ")
continue
to_write.append("{correlation_kt:.03f} & {time:.02f} & ".format(**description))
to_write[-1] = to_write[-1][:-2]
to_write.append(r"\\ \hline")
to_write.append("\n")
table_lines.append(("".join(to_write), positions.get(experiment, 10000)))
table_lines = [x[0] for x in sorted(table_lines, key=lambda x: x[1])]
with open(output, "w") as file:
file.write(table_head)
file.writelines(table_lines)
file.write(table_bottom)
if __name__ == "__main__":
parser = argparse.ArgumentParser("LaTeX metric table builder")
parser.add_argument("-o", "--output", type=str, default="table.tex", help="output file with table")
parser.add_argument("input", nargs="+", type=str, help="input mask to npz files")
args = parser.parse_args()
output = args.output
input = chain(*[glob(inp) for inp in args.input])
main(input, output)