-
Notifications
You must be signed in to change notification settings - Fork 7
/
search.py
115 lines (92 loc) · 3.04 KB
/
search.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
import os
from glob import glob
import json
import matplotlib.pyplot as plt
import collections
import pandas as pd
def read(fname):
with open(fname, "r") as json_data:
data = json_data.read().replace("\n", "")
d = json.loads(data)
return d
def isfloat(num):
try:
float(num)
return True
except ValueError:
return False
def boxplot(dict1):
labels, data = [
*zip(*dict1.items())
] # 'transpose' items to parallel key, value lists
# or backwards compatable
labels, data = dict1.keys(), dict1.values()
plt.figure(figsize=(15, 5))
plt.boxplot(data)
plt.xticks(range(1, len(labels) + 1), labels)
for k, v in zip(labels, data):
k = [k] * len(v)
plt.scatter(k, v, s=3, c="black", alpha=0.3)
plt.savefig("/vol/research/dcase2022/project/hhlab/temp.png")
# path = "/vol/research/dcase2022/project/hhlab/logs"
path = "/vol/research/dcase2022/project/hhlab/logs/experiments/runs"
prefix = "Evaluation_report_UoSurrey_unprocessed_VAL_"
folder = "0.9"
# for each in glob(os.path.join(path,"*/*/*/*/*.json")) + glob(os.path.join(path,"*/*/*/*/*/*.json")) + glob(os.path.join(path,"*/*/*/*/*/*/*.json")):
# if(prefix not in each): continue
# res = read(each)
# if(res['overall_scores']['fmeasure'] > 60):
# print(res['overall_scores']['fmeasure'], each)
res_dict = {}
def read_result(folder):
json_file = glob(os.path.join(folder, "*.json"))
if len(json_file) < 1:
return None
ret = []
for each in json_file:
# json_file = json_file[0]
dic = read(each)["scores_per_subset"]
if "PB" not in dic.keys():
return None
ret.append(dic["PB"]["f-measure"])
return ret
result = {}
i = 0
for each in (
glob(os.path.join(path, "*/%s" % folder))
+ glob(os.path.join(path, "*/*/%s" % folder))
+ glob(os.path.join(path, "*/*/*/%s" % folder))
+ glob(os.path.join(path, "*/*/*/*/%s" % folder))
+ glob(os.path.join(path, "*/*/*/*/*/%s" % folder))
+ glob(os.path.join(path, "*/*/*/*/*/*/%s" % folder))
):
res = read_result(each)
if res is None or max(res) < 40:
print(res)
continue
i += 1
if i > 20:
break
dirname = os.path.dirname(each)
for folder in os.listdir(dirname):
# print(folder, isfloat(folder))
if isfloat(folder):
if folder not in res_dict.keys():
res_dict[folder] = []
# print(dirname, folder)
score = read_result(os.path.join(dirname, folder))
if score is None:
continue
# print(max(score), dirname, folder)
result[max(score)] = folder + "_" + dirname
res_dict[folder].append(max(score))
res_dict = collections.OrderedDict(sorted(res_dict.items()))
result = collections.OrderedDict(sorted(result.items()))
# Serializing json
json_object = json.dumps(result, indent=4)
print(json_object)
# df = pd.DataFrame.from_dict(res_dict)
# df.to_csv("threshold.csv")
import ipdb
ipdb.set_trace()
boxplot(res_dict)