1 Star 0 Fork 2

Mike_W / tensorflow_alexnet_classify

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
validate_image.py 995 Bytes
一键复制 编辑 原始数据 按行查看 历史
zengfanlin 提交于 2018-03-06 23:04 . 注释
import matplotlib.pyplot as plt
import tensorflow as tf
from alexnet import AlexNet
class_name = ['cat', 'dog']
def test_image(path_image, num_class, weights_path='Default'):
img_string = tf.read_file(path_image)
img_decoded = tf.image.decode_png(img_string, channels=3)
img_resized = tf.image.resize_images(img_decoded, [227, 227])
img_resized = tf.reshape(img_resized, shape=[1, 227, 227, 3])
model = AlexNet(img_resized, 0.5, 2, skip_layer='', weights_path=weights_path)
score = tf.nn.softmax(model.fc8)
max = tf.arg_max(score, 1)
saver = tf.train.Saver()
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
saver.restore(sess, "./tmp/checkpoints/model_epoch100.ckpt")
# score = model.fc8
print(sess.run(model.fc8))
prob = sess.run(max)[0]
plt.imshow(img_decoded.eval())
plt.title("Class:" + class_name[prob])
plt.show()
test_image('./validate/10.jpeg', num_class=2)
1
https://gitee.com/Mike_W/tensorflow_alexnet_classify.git
git@gitee.com:Mike_W/tensorflow_alexnet_classify.git
Mike_W
tensorflow_alexnet_classify
tensorflow_alexnet_classify
master

搜索帮助