-
Notifications
You must be signed in to change notification settings - Fork 12
/
eval.py
50 lines (45 loc) · 1.64 KB
/
eval.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
import os
import cv2
from tqdm import tqdm
from py_sod_metrics import MAE, Emeasure, Fmeasure, Smeasure, WeightedFmeasure
method='FSPNet'
for _data_name in ['CAMO','CHAMELEON','COD10K','NC4K']:
print("eval-dataset: {}".format(_data_name))
mask_root = '/patch_to_GT/TestDataset/{}/{}/'.format(_data_name,"GT") # change path
pred_root = '/patch_to_pred/results/{}/{}/'.format(method, _data_name) # change path
mask_name_list = sorted(os.listdir(mask_root))
FM = Fmeasure()
WFM = WeightedFmeasure()
SM = Smeasure()
EM = Emeasure()
M = MAE()
for mask_name in tqdm(mask_name_list, total=len(mask_name_list)):
mask_path = os.path.join(mask_root, mask_name)
pred_path = os.path.join(pred_root, mask_name)
mask = cv2.imread(mask_path, cv2.IMREAD_GRAYSCALE)
pred = cv2.imread(pred_path, cv2.IMREAD_GRAYSCALE)
FM.step(pred=pred, gt=mask)
WFM.step(pred=pred, gt=mask)
SM.step(pred=pred, gt=mask)
EM.step(pred=pred, gt=mask)
M.step(pred=pred, gt=mask)
fm = FM.get_results()["fm"]
wfm = WFM.get_results()["wfm"]
sm = SM.get_results()["sm"]
em = EM.get_results()["em"]
mae = M.get_results()["mae"]
results = {
"Smeasure": sm,
"wFmeasure": wfm,
"MAE": mae,
"adpEm": em["adp"],
"meanEm": em["curve"].mean(),
"maxEm": em["curve"].max(),
"adpFm": fm["adp"],
"meanFm": fm["curve"].mean(),
"maxFm": fm["curve"].max(),
}
print(results)
file=open("/path_to_eval_results/eval_results.txt", "a")
file.write(method+' '+_data_name+' '+str(results)+'\n')
print("Eval finished!")