Last active
March 14, 2018 17:14
-
-
Save JoshVarty/c574ce5572e172ce6dae2f02a6921725 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import numpy as np | |
from tensorflow.examples.tutorials.mnist import input_data | |
mnist = input_data.read_data_sets('MNIST_data', one_hot=True) | |
test_images = np.reshape(mnist.test.images, (-1, 28, 28, 1)) | |
test_labels = mnist.test.labels | |
graph = tf.Graph() | |
with tf.Session(graph=graph) as session: | |
saver = tf.train.import_meta_graph('/tmp/vggnet/vgg_net.ckpt.meta') #Create a saver based on a saved graph | |
saver.restore(session, '/tmp/vggnet/vgg_net.ckpt') #Restore the values to this graph | |
input = graph.get_tensor_by_name("input:0") #Get access to the input node | |
labels = graph.get_tensor_by_name("labels:0") #Get access to the labels node | |
batch_size = 100 | |
num_test_batches = int(len(test_images) / 100) | |
total_accuracy = 0 | |
total_cost = 0 | |
for step in range(num_test_batches): | |
offset = (step * batch_size) % (test_labels.shape[0] - batch_size) | |
batch_images = test_images[offset:(offset + batch_size)] | |
batch_labels = test_labels[offset:(offset + batch_size)] | |
feed_dict = {input: batch_images, labels: batch_labels} | |
c, acc = session.run(['cost:0', 'accuracy:0'], feed_dict=feed_dict) #Note: We pass in strings 'cost:0' and 'accuracy:0' | |
total_cost = total_cost + c | |
total_accuracy = total_accuracy + acc | |
print("Test Cost: ", total_cost / num_test_batches) | |
print("Test accuracy: ", total_accuracy * 100.0 / num_test_batches, "%") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment