-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcompute_stats.py
41 lines (35 loc) · 1.32 KB
/
compute_stats.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
import json
import glob
import argparse
import numpy as np
parser = argparse.ArgumentParser()
parser.add_argument('--outputs', default='./outputs/concepts/refined/aoec/colon/*.json', type=str, help='SKET results file.')
parser.add_argument('--use_case', default='colon', choices=['colon', 'cervix', 'lung', 'celiac'], help='Considered use-case.')
args = parser.parse_args()
def main():
# read SKET results
if '*.json' == args.outputs.split('/')[-1]: # read files
# read file paths
rsfps = glob.glob(args.outputs)
# set dict
rs = {}
for rsfp in rsfps:
with open(rsfp, 'r') as rsf:
rs.update(json.load(rsf))
else: # read file
with open(args.outputs, 'r') as rsf:
rs = json.load(rsf)
stats = []
# loop over reports and store size
for rid, rdata in rs.items():
stats.append(sum([len(sem_data) for sem_cat, sem_data in rdata.items()]))
# convert into numpy
stats = np.array(stats)
print('size: {}'.format(np.size(stats)))
print('max: {}'.format(np.max(stats)))
print('min: {}'.format(np.min(stats)))
print('mean: {}'.format(np.mean(stats)))
print('std: {}'.format(np.std(stats)))
print('tot: {}'.format(np.sum(stats)))
if __name__ == "__main__":
main()