-
Notifications
You must be signed in to change notification settings - Fork 10
/
evaluate.py
66 lines (55 loc) · 1.95 KB
/
evaluate.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
# -*- coding: utf-8 -*-
#! /usr/bin/python3
"""
@author: pqxu
edited by: cx
"""
import numpy as np
import os
from PIL import Image
from util import *
import re
P_num = args.seq_length-args.seq_start
Size = (args.img_size,args.img_size)
Detect_r = 180*256/461
Threshold = args.threshold
Hit = np.zeros((P_num),dtype = np.int64)
Miss = np.zeros((P_num),dtype = np.int64)
Falsealarm = np.zeros((P_num),dtype = np.int64)
def initcircle(shape,r):
shape = shape[1]
center = (shape - 1)/2.0
x = np.array(shape*[np.arange(shape)])
y = np.transpose(x,(1,0))
x = x - center
y = y - center
output = np.sqrt(x**2 + y**2)
output = np.uint8(output<r)
return output,x,y
Circle,x,y = initcircle(Size,Detect_r)
def main(dir):
for root, dir, files in os.walk(dir):
# print root
for file in files:
if file.find('_') == -1:
filename = os.path.join(root, file)
truth = np.asarray(Image.open(filename))*Circle
truth_is = (truth>=Threshold)
truth_not = (truth<Threshold)
for i in range(P_num):
p_namei = filename[:-4] + '_' + str(i) + '.png'
if os.path.isfile(p_namei):
p_i = np.asarray(Image.open(p_namei))*Circle
p_i_is = (p_i>=Threshold*0.93 - i)
p_i_not = (p_i<Threshold*0.93 - i)
hit_i = np.sum(np.logical_and(truth_is,p_i_is))
miss_i = np.sum(np.logical_and(truth_is,p_i_not))
falsealarm_i = np.sum(np.logical_and(truth_not,p_i_is))
Hit[i] += hit_i
Miss[i] += miss_i
Falsealarm[i] += falsealarm_i
if __name__ == '__main__':
main(args.img_dir)
print('csi:',Hit/np.float64(Hit+Falsealarm+Miss))
print('pod:',Hit/np.float64(Hit+Miss))
print('far:',Falsealarm/np.float64(Hit + Falsealarm))