-
Notifications
You must be signed in to change notification settings - Fork 1
/
eval.py
32 lines (26 loc) · 1.1 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
'''
A Convolutional Network implementation example using TensorFlow library.
This example is using the MNIST database of handwritten digits
(http://yann.lecun.com/exdb/mnist/)
Author: Aymeric Damien
Project: https://github.com/aymericdamien/TensorFlow-Examples/
'''
from __future__ import print_function
import tensorflow as tf
# Import MNIST data
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/mnist", one_hot=True)
# Launch the graph
with tf.Session() as sess:
tf.saved_model.loader.load(sess, ["EVALUATING"], "/model/cnn_model")
# Retrieve placeholder tensor by name
graph = tf.get_default_graph()
x = graph.get_tensor_by_name("x:0")
y = graph.get_tensor_by_name("y:0")
accuracy = graph.get_tensor_by_name("accuracy:0")
keep_prob = graph.get_tensor_by_name("keep_prob:0")
# Calculate accuracy for 256 mnist test images
print("Testing Accuracy:", \
sess.run(accuracy, feed_dict={x: mnist.test.images[:256],
y: mnist.test.labels[:256],
keep_prob: 1.}))