首先要了解一些基础知识:
- 首先定义图表:图像队列,图像预处理,卷积推理,top-k精度
- 然后创建一个,
tf.Session()
并在其中进行操作:启动队列运行器,并调用sess.run()
这是您的代码应为的样子
# 1. GRAPH CREATION filename_queue = tf.train.string_input_producer(['/home/tensor/.../inputImage.jpg'])... # NO CREATION of a tf.Session herefloat_image = ...images = tf.expand_dims(float_image, 0) # create a fake batch of images (batch_size=1)logits = faultnet.inference(images)_, top_k_pred = tf.nn.top_k(logits, k=5)# 2. TENSORFLOW SESSIonwith tf.Session() as sess: sess.run(init_op) coord = tf.train.Coordinator() threads = tf.train.start_queue_runners(coord=coord) top_indices = sess.run([top_k_pred]) print ("Predicted ", top_indices[0], " for your input image.")编辑:
正如@mrry所建议的,如果只需要处理 单个 图像,则可以删除队列运行器:
# 1. GRAPH CREATIONinput_img = tf.image.depre_jpeg(tf.read_file("/home/.../your_image.jpg"), channels=3)reshaped_image = tf.image.resize_image_with_crop_or_pad(tf.cast(input_img, width, height), tf.float32)float_image = tf.image.per_image_withening(reshaped_image)images = tf.expand_dims(float_image, 0) # create a fake batch of images (batch_size = 1)logits = faultnet.inference(images)_, top_k_pred = tf.nn.top_k(logits, k=5)# 2. TENSORFLOW SESSIonwith tf.Session() as sess: sess.run(init_op) top_indices = sess.run([top_k_pred]) print ("Predicted ", top_indices[0], " for your input image.")


