记一次超级蠢超级折磨我的bug。

报错内容:

tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'x_1' with dtype float and shape [?,227,227,3]
[[Node: x_1 = Placeholder[dtype=DT_FLOAT, shape=[?,227,227,3], _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]
[[Node: fc3/_33 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_110_fc3", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

错误理解起来很简单,没有给placeholder ‘x_1’赋值。

这是我的预测代码:

image = Image.open(imagefile)
image = image.resize([227, 227])
image_array = np.array(image)
image_array = image_array.astype(float)
image = np.reshape(image_array, [1, 227, 227, 3])
saver = tf.train.import_meta_graph("/home/ubuntu/demo/package/5.8_2000op_256batch/AlexNetModel.ckpt.meta")
graph = tf.get_default_graph()
prediction = graph.get_tensor_by_name("fc3:0")
x = graph.get_tensor_by_name("x:0")
with tf.Session() as sess:
  saver.restore(sess, "/home/ubuntu/demo/package/5.8_2000op_256batch/AlexNetModel.ckpt")
  Predict = sess.run(prediction, feed_dict={x: image})
  max_index = np.argmax(Predict)
  if max_index==0:
    return "cat"
  else:
    return "dog"

之前是觉得image格式有问题,不能作为输入给x。

因为最初始,源码是这样写的:

image = Image.open(imagefile)
image = image.resize([227, 227])
image_array = np.array(image)

image = tf.cast(image_array,tf.float32)
image = tf.image.per_image_standardization(image)
image = tf.reshape(image, [1, 227, 227, 3])

而使用tf的方法,返回值是一个tensor,而tensor是无法赋值给placeholder定义的数据类型。

  • sess.run()第一个参数是要fetch的变量,这个变量的类型只能是tensor或者string, 后面如果要加feed_dict = {}, 注意feed的数据类型可以是Python scalars, strings, lists, numpy ndarrays, or TensorHandles,不能是tensor.fecth得到的变量是<type 'numpy.ndarray'>。一句话就是,在运行图的时,tensor用sess.run()取出来,然后再feed进去。

所以就把image的形状变化,tf.reshape()改为了np.reshape(),但是还有问题,报错为上面的You must feed a value for placeholder tensor 'x_1' with dtype float and shape [?,227,227,3].......

完了彻底把我整懵逼了,不知道应该给x什么样的输入了,但是又好奇怪,placeholder tensor 'x_1'那里来的,没有定义过 'x_1'这种东西呀。贴一下训练代码,placeholder的申请。

x = tf.placeholder(tf.float32, [None, 227, 227, 3],name='x')
y = tf.placeholder(tf.float32, [None, n_classes])

感觉没问题啊,挺好的啊。如果代码真的是这样确实没啥问题挺好的,关键是自己脑残,x = tf.placeholder(tf.float32, [None, 227, 227, 3],name='x')申请了两遍

删掉一个。OK了。很烦,困扰了自己好几天

tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'x_1' with dtype float and shape [?,227,227,3]的更多相关文章

  1. InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_1' with dtype float and shape [?,10]

    在莫烦Python教程的“Dropout 解决 overfitting”一节中,出现错误如下: InvalidArgumentError: You must feed a value for plac ...

  2. Tensorflow报错:InvalidArgumentError: You must feed a value for placeholder tensor 'input_y' with dtype

    此错误神奇之处是每次第一次运行不会报错,第二次.第三次第四次....就都报错了.关掉重启,又不报错了,运行完再运行一次立马报错!搞笑! 折磨了我半天,终于被我给解决了! 问题解决来源于这边博客:htt ...

  3. faster-rcnn错误信息 : tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [21] rhs shape= [2]

    faster-rcnn错误信息 : tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shap ...

  4. tensorflow.python.framework.errors_impl.OutOfRangeError: FIFOQueue

    tensorflow.python.framework.errors_impl.OutOfRangeError: FIFOQueue 原创文章,请勿转载哦~!! 觉得有用的话,欢迎一起讨论相互学习~F ...

  5. Tensorflow 报错:tensorflow.python.framework.errors_impl.InternalError: Failed to create session.

    问题描述 IDE:pycharm,环境中安装tensorflow-gpu 1.8.0 ,Cuda9 ,cudnn 7,等,运行代码 报错如下 tensorflow.python.framework.e ...

  6. 【err】tensorflow.python.framework.errors_impl.OutOfRangeError: RandomShuffleQueue

    problem Traceback (most recent call last): File , in _do_call return fn(*args) File , in _run_fn opt ...

  7. ''tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[?]'' 错误分析

    这是tensorflow 一个经常性错误,错误的原因在于:显卡内存不够. 解决方法就是降低显卡的使用内存,途径有以下几种措施: 1 减少Batch 的大小 2 分析错误的位置,在哪一层出现显卡不够,比 ...

  8. tensorflow.python.framework.errors_impl.PermissionDeniedError: /data; Permission denied

    在linux系统中,tensorflow跑mnist数据集出现错误,本应该自动下载的数据集 将mnist自动下载的路径,由/data/mnist之前的/删掉即可.改为data/mnist.

  9. 手写数字识别 ----在已经训练好的数据上根据28*28的图片获取识别概率(基于Tensorflow,Python)

    通过: 手写数字识别  ----卷积神经网络模型官方案例详解(基于Tensorflow,Python) 手写数字识别  ----Softmax回归模型官方案例详解(基于Tensorflow,Pytho ...

随机推荐

  1. 2019-01-31 Python学习之BFS与DFS实现爬取邮箱

    今天学习了python网络爬虫的简单知识 首先是一个爬取百度的按行读取和一次性爬取 逐行爬取 for line in urllib.request.urlopen("http://www.b ...

  2. [源码解析] GroupReduce,GroupCombine 和 Flink SQL group by

    [源码解析] GroupReduce,GroupCombine和Flink SQL group by 目录 [源码解析] GroupReduce,GroupCombine和Flink SQL grou ...

  3. 【JMeter_15】JMeter逻辑控制器__仅一次控制器<Once Only Controller>

    仅一次控制器<Once Only Controller> 业务逻辑: 在每个线程内,该控制器下的内容只会被执行一遍,无论循环多少次,都只执行一遍.<嵌套在循环控制器之内时是个例外,每 ...

  4. TiDB初探

    TiDB是一个开源的分布式NewSQL数据库,设计的目标是满足100%的OLTP和80%的OLAP,支持SQL.水平弹性扩展.分布式事务.跨数据中心数据强一致性保证.故障自恢复的高可用.海量数据高并发 ...

  5. TLS1.2协议设计原理

    目录 前言 为什么需要TLS协议 发展历史 协议设计目标 记录协议 握手步骤 握手协议 Hello Request Client Hello Server Hello Certificate Serv ...

  6. 工业4.0:换热站最酷设计—— Web SCADA 工业组态软件界面

    前言 随着工业4.0的不断普及与发展,以及国民经济的飞速前进,我国的城市集中供热规模也不断扩大,科学的管理热力管网具有非常重大的经济和社会效益.目前热力系统,如换热站大都采用人工监控,人工监控不仅浪费 ...

  7. 使用spring-test时报错

    java.lang.NoClassDefFoundError: org/springframework/core/annotation/MergedAnnotations$SearchStrategy ...

  8. IIS 发布页面后或者vs平台运行后显示“未能加载文件或程序集“WebApi”或它的某一个依赖项。试图加载格式不正确的程序。”

    一般情况下出现这样的问题是因为.dll文件不存在或者路径不正确. 但今天我遇到的情况都不在这两个内. 我确定.dll文件是存在的,路径也是正确的. 但是程序死活都是“未能加载文件或程序集“xxx”或它 ...

  9. python读取文件路径

    不同系统对文件路径的分割符不同: 在Windows系统下的分隔符是:\ (反斜杠). 在Linux系统下的分隔符是:/(斜杠). 绝对路径和相对路径 绝对路径就是文件的真正存在的路径,是指从硬盘的根目 ...

  10. linux之文件基本操作

    文件/目录管理命令: cd命令主要是改变目录的功能 cd ~ 返回登录目录 cd / 返回系统根目录 cd ../ 或者cd ..  返回上一级目录 cd -  返回上一次访问的目录 pwd命令用于显 ...