-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval.py
More file actions
108 lines (68 loc) · 2.34 KB
/
eval.py
File metadata and controls
108 lines (68 loc) · 2.34 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# -*- coding: utf-8 -*-
# author: K
from common import testing_dir, testing_batch_size, image_size
from recognizer import inference, accuracy, loss, dropout_prob
from image_preprocessing import inputs
from PIL import Image
import numpy as np
import tensorflow as tf
def predict_image(sess, logits):
print sess.run(tf.argmax(logits, 1))
def predict(saver, logits):
with tf.Session() as sess:
ckpt = tf.train.get_checkpoint_state("./model/")
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess, ckpt.model_checkpoint_path)
print "Model Loaded!"
else:
print "Model Not Found"
return
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess, coord = coord)
print sess.run(tf.argmax(logits, 1))
coord.request_stop()
coord.join(threads, stop_grace_period_secs = 10)
def eval_once(saver, logits, acc, labels):
with tf.Session() as sess:
ckpt = tf.train.get_checkpoint_state("./model/")
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess, ckpt.model_checkpoint_path)
print "Model Loaded!"
else:
print "Model Not Found!"
return
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess, coord = coord)
l = tf.argmax(labels,1)
p = tf.argmax(logits,1)
print sess.run([l,p, tf.equal(l,p), acc])
coord.request_stop()
coord.join(threads, stop_grace_period_secs = 10)
def eval_average(saver, logits, acc, labels):
with tf.Session() as sess:
ckpt = tf.train.get_checkpoint_state("./model/")
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess, ckpt.model_checkpoint_path)
print "Model Loaded"
else:
print "Model Not Found"
return
res_list = []
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess, coord = coord)
for i in range(30):
l = tf.argmax(labels, 1)
p = tf.argmax(logits, 1)
res_list.append(sess.run([acc], feed_dict = {dropout_prob: 1.0}))
coord.request_stop()
coord.join(threads, stop_grace_period_secs = 10)
print np.mean(res_list)
if __name__ == '__main__':
images, labels = inputs(testing_dir, image_size, testing_batch_size, True)
logits = inference(images, 2, image_size)
acc = accuracy(logits, labels)
saver = tf.train.Saver()
#predict_image(saver, logits)
#eval_once(saver, logits, acc, labels)
#predict(saver, logits)
eval_average(saver, logits, acc, labels)