-
Notifications
You must be signed in to change notification settings - Fork 2
/
aggregate.py
68 lines (59 loc) · 1.73 KB
/
aggregate.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
from pathlib import Path
from pandas.io.json import json_normalize
import pandas as pd
import json
import argparse
def museval2df(json_path):
with open(json_path) as json_file:
json_string = json.loads(json_file.read())
df = json_normalize(
json_string['targets'],
['frames'],
['name']
)
df = pd.melt(
pd.concat(
[
df.drop(['metrics'], axis=1),
df['metrics'].apply(pd.Series)
],
axis=1
),
var_name='metric',
value_name='score',
id_vars=['time', 'name'],
value_vars=['SDR', 'SAR', 'ISR', 'SIR']
)
df['track'] = json_path.stem
df = df.rename(index=str, columns={"name": "target"})
return df
def aggregate(input_dirs, output_path=None):
data = []
for path in input_dirs:
p = Path(path)
print(p.stem)
if p.exists():
json_paths = p.glob('**/*.json')
for json_path in json_paths:
df = museval2df(json_path)
df['method'] = p.stem
data.append(df)
df = pd.concat(data, ignore_index=True)
if output_path is not None:
df.to_pickle(output_path)
return df
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Aggregate Folder')
parser.add_argument(
'submission_dirs',
help='directories of submissions',
nargs='+',
type=str
)
parser.add_argument(
'--out',
help='saves dataframe to disk',
type=str
)
args = parser.parse_args()
df = aggregate(args.submission_dirs, output_path=args.out)