-
Notifications
You must be signed in to change notification settings - Fork 1
/
areaundercurve.py
44 lines (37 loc) · 1.57 KB
/
areaundercurve.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
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from sklearn import metrics
flags = tf.app.flags
flags.DEFINE_string('init_checkpoint', None, 'Checkpoint file for model initialization')
flags.DEFINE_integer('flickr', 0, 'On which dataset')
flags.DEFINE_string('datatype', '', 'music or outdoor or old')
FLAGS = flags.FLAGS
'''Given all IoU files compute area under the curve'''
def main(_):
plotdecodeimages()
def plotdecodeimages():
s = FLAGS.init_checkpoint.split('/')[-1]
name = (s.split('_')[1]).split('.ckpt')[0]
if FLAGS.flickr:
name = '{}_{}_{}_{}'.format('UNet', 'test', 'AcousticFrames{}'.format(FLAGS.datatype), name)
else:
name = '{}_{}_{}_{}'.format('UNet', 'testing', 'Acoustictry{}'.format(FLAGS.datatype), name)
data_dir = str.join('/', FLAGS.init_checkpoint.split('/')[:-1] + [name])
value = np.zeros(11)
threshold = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
for i in range(len(threshold)):
with open('{}'.format(data_dir) + "/intersection_{}_accuracy.txt".format(threshold[i]), "r") as outfile:
t = outfile.read()
value[i] = t.split(' ')[1]
value = value[::-1]
threshold = threshold[::-1]
plt.plot(threshold, value)
outImage_path = '{}/auc.png'.format(data_dir, 'testing')
plt.savefig(outImage_path)
auc = metrics.auc(threshold, value)
print('area {:6f}'.format(auc))
with open('{}'.format(data_dir) + "/area.txt", "w") as outfile:
outfile.write('area {:6f}'.format(auc))
if __name__ == '__main__':
tf.app.run()