-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresults.py
136 lines (113 loc) · 4.46 KB
/
results.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
from options.results_options import get_arguments
import numpy as np
import os
import pandas as pd
args = get_arguments()
methods_default = [
'fixmatch_with_al_augmentations_based',
'fixmatch_with_al_augmentations_based_pretrained',
'fixmatch_with_al_augmentations_based_pretrained_simclr',
'fixmatch_with_al_augmentations_based_pretrained_autoencoder'
]
def ratio_class_wise_metrics(metric, classes, dataset):
logs = os.listdir(args.log_path)
dump_log = []
for i, method in enumerate(methods_default):
dump_log.append([])
for filename in logs:
if f"{dataset}@resnet@{method}" != filename.split('-')[1] or 'epoch' in filename or 'ae-loss' in filename:
continue
df = pd.read_csv(os.path.join(args.log_path, filename), index_col=0)
for j, cls in enumerate(classes):
dump_log[i].append([])
dump = df[cls][metric].tolist()
max_metric = 0
for k, m in enumerate(dump):
max_metric = m if m > max_metric else max_metric
dump[k] = max_metric
dump_log[i][j].append(dump)
metrics_log = []
for i, method in enumerate(methods_default):
metrics_log.append([])
if len(dump_log[i]) == 0:
continue
for j, cls in enumerate(classes):
metrics_log[i].append([])
dump = np.array(dump_log[i][j])
mean = dump.mean(axis=0)
std = dump.std(axis=0)
metrics_log[i][j].append((mean - std))
metrics_log[i][j].append(mean)
metrics_log[i][j].append((mean + std))
return metrics_log
def ratio_metrics(metric, dataset, cls, methods):
logs = os.listdir(args.log_path)
dump_log = []
for i, method in enumerate(methods):
dump_log.append([])
for filename in logs:
if f"{dataset}@resnet@{method}" != filename.split('-')[1] or 'epoch' in filename or 'ae-loss' in filename \
or 'class-nums' in filename:
continue
df = pd.read_csv(os.path.join(args.log_path, filename), index_col=0)
print(filename)
dump = df[cls][metric].tolist()
max_metric = 0
try:
enumerate(dump)
except Exception:
dump = np.array([0 for i in range(9)])
for k in range(9):
if k >= len(dump):
dump += [max_metric]
else:
max_metric = dump[k] if dump[k] > max_metric else max_metric
dump[k] = max_metric
dump_log[i].append(dump[:9])
metrics_log = []
for i, method in enumerate(methods):
metrics_log.append([])
if len(dump_log[i]) == 0:
continue
dump = np.array(dump_log[i])
try:
mean = dump.mean(axis=0)
std = dump.std(axis=0)
except Exception:
mean = np.array([0 for i in range(9)])
std = np.array([0 for i in range(9)])
metrics_log[i].append((mean - std))
metrics_log[i].append(mean)
metrics_log[i].append((mean + std))
return metrics_log
# noinspection PyTypeChecker
def epoch_class_wise_loss(classes, method, dataset):
logs = os.listdir(args.log_path)
dump_log = []
for i, cls in enumerate(classes):
dump_log.append([[], []])
for filename in logs:
if f"{dataset}@resnet@{method}" != filename.split('-')[1] or \
'epoch' not in filename or 'ae-loss' in filename:
continue
df = pd.read_csv(os.path.join(args.log_path, filename), index_col=0)
dump_log[i][0].append(df[f'{cls}-train-loss']['0'].tolist())
dump_log[i][1].append(df[f'{cls}-val-loss']['0'].tolist())
metrics_log = []
for i, cls in enumerate(classes):
metrics_log.append([[], []])
dump = np.array(dump_log[i][0][0])
metrics_log[i][0].extend(dump.tolist())
dump = np.array(dump_log[i][1][0])
metrics_log[i][1].extend(dump.tolist())
return metrics_log
def ae_loss(dataset):
logs = os.listdir(args.log_path)
dump_log = []
for filename in logs:
if 'ae-loss' not in filename or dataset not in filename:
continue
df = pd.read_csv(os.path.join(args.log_path, filename), index_col=0)
for col in df.columns:
dump_log.append(df[col].tolist())
return dump_log