-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.py
More file actions
72 lines (60 loc) · 2.46 KB
/
Copy pathtest.py
File metadata and controls
72 lines (60 loc) · 2.46 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import argparse
import logging
import os
import sys
import numpy as np
from PIL import Image
import glob
import matplotlib.pyplot as plt
# python test.py -p /dls/tmp/lqg38422/TEST/gt/ -m /dls/tmp/lqg38422/TEST/gt/
def get_args():
parser = argparse.ArgumentParser(description='Get metrics to evaluate the predictions of the U-Net',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-p', '--dir_pred', dest='dir_pred', type=str, default='/dls/tmp/lqg38422/PREDS/',
help='Path to the folder containing the images (/path/to/preds/)')
parser.add_argument('-m', '--dir_mask', dest='dir_mask', type=str, default='/dls/tmp/lqg38422/TEST/gt/',
help='Path to the folder containing the masks (/path/to/masks/)')
return parser.parse_args()
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
args = get_args()
preds_files = glob.glob(args.dir_pred + "*")
masks_files = glob.glob(args.dir_mask + "*")
background_error = []
crystal_error = []
loop_error = []
liquor_error = []
for n in range(len(preds_files)):
pred = np.array(Image.open(preds_files[n]))
mask = np.array(Image.open(masks_files[n]))
if np.sum(mask == 0) == 0:
error0 = 0
else:
error0 = np.sum(pred[pred == mask] == 0) / np.sum(mask == 0) * 100
if np.sum(mask == 1) == 0:
error1 = 0
else:
error1 = np.sum(pred[pred == mask] == 1) / np.sum(mask == 1) * 100
if np.sum(mask == 2) == 0:
error2 = 0
else:
error2 = np.sum(pred[pred == mask] == 2) / np.sum(mask == 2) * 100
if np.sum(mask == 3) == 0:
error3 = 0
else:
error3 = np.sum(pred[pred == mask] == 3) / np.sum(mask == 3) * 100
background_error.append(error0)
crystal_error.append(error1)
loop_error.append(error2)
liquor_error.append(error3)
plt.figure()
plt.axis([None,None,0,110])
plt.title("Class accuracy (right predictions / total)")
plt.plot(background_error)
plt.plot(crystal_error)
plt.plot(loop_error)
plt.plot(liquor_error)
plt.ylabel('Class accuracy (predict/real)')
plt.xlabel('Frames')
plt.legend(["Background error", "Crystal error", "Loop error", "Liquor error"])
plt.show()