forked from nelson1425/EfficientAD
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresults_summarization.py
More file actions
48 lines (36 loc) · 1.53 KB
/
results_summarization.py
File metadata and controls
48 lines (36 loc) · 1.53 KB
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import numpy as np
import os
from common import calculate_f1_max
from sklearn.metrics import roc_auc_score
import csv
def evaluate():
# search the csv files for all classes
files_in_folder = os.listdir(os.getcwd())
predictions_csv_files = [file for file in files_in_folder if file.startswith("predictions") and file.endswith(".csv")]
y_trues = list()
y_scores = list()
f1_scores = list()
print('prediction files on all classes:')
for file in predictions_csv_files:
print(file)
with open(file, 'r') as f:
csv_reader = csv.reader(f)
next(csv_reader)
y_true = list()
y_score = list()
for row in csv_reader:
y_trues.append(float(row[-2]))
y_scores.append(float(row[-1]))
y_true.append(float(row[-2]))
y_score.append(float(row[-1]))
f1, threshold = calculate_f1_max(np.array(y_true), np.array(y_score))
print('image classification F1: {:.4f}, threshold: {:.4f}'.format(f1*100, threshold))
f1_scores.append(f1)
# auc and F1 score
f1, threshold = calculate_f1_max(np.array(y_true), np.array(y_score))
print('Evaluation on all classes of test set, average image classification F1: {:.4f}'.format(np.mean(f1_scores)*100))
print('Evaluation on all classes of test set, global image classification F1: {:.4f}, threshold: {:.4f}'.format(f1*100, threshold))
if __name__ == '__main__':
evaluate()