Created
January 6, 2017 16:07
-
-
Save tilfin/91f607c87b5e566cca1e78c39d56575d 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
from datetime import datetime | |
import math | |
import time | |
import numpy as np | |
import tensorflow as tf | |
from tensorflow.models.image.cifar10 import cifar10 | |
FLAGS = tf.app.flags.FLAGS | |
#cifar10.IMAGE_SIZE = 32 | |
tf.app.flags.DEFINE_string('checkpoint_dir', 'D:/tensorflow/data/cifar10_train', | |
"""Directory where to read model checkpoints.""") | |
tf.app.flags.DEFINE_integer('num_examples', 10000, | |
"""Number of examples to run.""") | |
def evaluate_images(images): | |
logits = cifar10.inference(images) | |
variable_averages = tf.train.ExponentialMovingAverage( | |
cifar10.MOVING_AVERAGE_DECAY) | |
variables_to_restore = variable_averages.variables_to_restore() | |
saver = tf.train.Saver(variables_to_restore) | |
load_trained_model(saver, logits) | |
def load_trained_model(saver, logits): | |
with tf.Session() as sess: | |
ckpt = tf.train.get_checkpoint_state(FLAGS.checkpoint_dir) | |
if ckpt and ckpt.model_checkpoint_path: | |
# Restores from checkpoint | |
saver.restore(sess, ckpt.model_checkpoint_path) | |
else: | |
print('No checkpoint file found') | |
return | |
predict = sess.run(logits) | |
print(predict, '\n') | |
def img_read(filename): | |
if not tf.gfile.Exists(filename): | |
tf.logging.fatal('File does not exists %s', filename) | |
image_data = tf.gfile.FastGFile(filename, 'rb').read() | |
image = tf.image.decode_jpeg(image_data) | |
image = tf.image.resize_images(image, [24, 24]) | |
return image | |
filename = '1.jpg' | |
image = img_read(filename) | |
evaluate_images([image]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment