-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathval.py
58 lines (51 loc) · 1.76 KB
/
val.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
# -*- coding: utf-8 -*-
# @Time : 2020/11/21
# @Author : Lart Pang
# @GitHub : https://github.com/lartpang
import os
# os.environ["CUDA_VISIBLE_DEVICES"] = "1"
import cv2
from tqdm import tqdm
# pip install pysodmetrics
from py_sod_metrics import MAE, Emeasure, Fmeasure, Smeasure, WeightedFmeasure
method='mfnet5/56'
# for _data_name in ['COD10K']:
for _data_name in ['CAMO','CHAMELEON','COD10K']:
# for _data_name in ['CAMO','CHAMELEON']:
mask_root = './data/TestDataset/{}/GT'.format(_data_name)
pred_root = './results/{}/{}/GT'.format(method, _data_name)
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,
"meanEm": em["curve"].mean(),
# "adpEm": em["adp"],
# "maxEm": em["curve"].max(),
# "adpFm": fm["adp"],
# "meanFm": fm["curve"].mean(),
# "maxFm": fm["curve"].max(),
}
print(results)
file=open("evalresults.log", "a")
file.write(method+' '+_data_name+' '+str(results)+'\n')