【问题标题】:Tensorflow inception_v2_resnet inferenceTensorFlow inception_v2_resnet 推理
【发布时间】:2017-02-21 12:13:59
【问题描述】:

参考这篇文章:

Using pre-trained inception_resnet_v2 with Tensorflow

我也在尝试使用 inception_resnet_v2 模型来获得图像预测。因此我查看了 sn-p 并试图让它运行,但它说“input_tensor”没有定义。提到的代码中是否缺少任何内容,或者任何人都可以给我一些提示以使其运行/如何定义 input_tensor 变量?

这里又是 sn-p:

import tensorflow as tf
slim = tf.contrib.slim
from PIL import Image
from inception_resnet_v2 import *
import numpy as np

checkpoint_file = 'inception_resnet_v2_2016_08_30.ckpt'
sample_images = ['dog.jpg', 'panda.jpg']
#Load the model
sess = tf.Session()
arg_scope = inception_resnet_v2_arg_scope()
with slim.arg_scope(arg_scope):
  logits, end_points = inception_resnet_v2(input_tensor, is_training=False)
saver = tf.train.Saver()
saver.restore(sess, checkpoint_file)
for image in sample_images:
  im = Image.open(image).resize((299,299))
  im = np.array(im)
  im = im.reshape(-1,299,299,3)
  predict_values, logit_values = sess.run([end_points['Predictions'],logits], feed_dict={input_tensor: im})
  print (np.max(predict_values), np.max(logit_values))
  print (np.argmax(predict_values), np.argmax(logit_values))

谢谢

【问题讨论】:

    标签: tensorflow inference resnet


    【解决方案1】:

    代码 sn-p 似乎缺少对 input_tensor 的任何定义。查看inception_resnet_v2() 函数的definition,张量用于feed_dict 的事实,以及图像大小为299 x 299 的事实,您可以定义input_tensor 如下:

    input_tensor = tf.placeholder(tf.float32, [None, 299, 299, 3])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-18
      • 2018-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多