-
Notifications
You must be signed in to change notification settings - Fork 3
/
results_to_csv.py
48 lines (38 loc) · 1.45 KB
/
results_to_csv.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
import os
import glob
import pickle
import pandas as pd
def get_dataframe(data):
columns = ['name', 'feature']
data_keys = list(data.keys())
recall_ks = data[data_keys[0]]['recall_ks']
for k in data.keys():
for sz in recall_ks:
columns.append(f'{k}-recall@{sz}')
columns.append(f'{k}-mAP')
return pd.DataFrame(columns=columns), recall_ks
categories = ['artchive', 'bamfg', 'observed_imagenet', 'unobserved_imagenet']
feats = ['clip', 'dino', 'moco', 'vit', 'sscd']
for c in categories:
subset = sorted(glob.glob(f'results/test_{c}/*.pkl'))
df, recall_ks = None, []
for ff in feats:
small_subset = sorted([n for n in subset if ff in n])
# print(subset)
for s in small_subset:
print(s)
entry = {}
with open(s, 'rb') as f:
data = pickle.load(f)
# lazy load the dataframe
if df is None or recall_ks == []:
df, recall_ks = get_dataframe(data)
name = os.path.basename(s).replace('.pkl', '')
entry['name'] = name
entry['feature'] = ff
for k in data.keys():
for ind, tt in enumerate(recall_ks):
entry[f'{k}-recall@{tt}'] = data[k]['avg_recall'][ind]
entry[f'{k}-mAP'] = data[k]['avg_map']
df = df.append(entry, ignore_index=True)
df.to_csv(f'results/table_{c}.csv')