请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

InvalidArgumentError错误

问题已解决。。。。。。

问题已解决。。。。。。

问题已解决。。。。。。








# -*- encoding:utf-8 -*-
import tensorflow as tf

y = tf.placeholder(tf.float32, name='y')
y_ = tf.placeholder(tf.float32, name='y_')

# 欧几里得距离
cost = tf.reduce_sum(tf.pow(y_-y, 2.0))

with tf.Session() as session:
   print(session.run(cost), feed_dict={y_:2.0, y:1.0})




-----

错误信息

Traceback (most recent call last):

  File "C:\Users\sotto\Envs\tensor3\lib\site-packages\tensorflow\python\client\session.py", line 1327, in _do_call

    return fn(*args)

  File "C:\Users\sotto\Envs\tensor3\lib\site-packages\tensorflow\python\client\session.py", line 1312, in _run_fn

    options, feed_dict, fetch_list, target_list, run_metadata)

  File "C:\Users\sotto\Envs\tensor3\lib\site-packages\tensorflow\python\client\session.py", line 1420, in _call_tf_sessionrun

    status, run_metadata)

  File "C:\Users\sotto\Envs\tensor3\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 516, in __exit__

    c_api.TF_GetCode(self.status.status))

tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'y' with dtype float

[[Node: y = Placeholder[dtype=DT_FLOAT, shape=<unknown>, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "C:/Users/sotto/PycharmProjects/untitled/cost01.py", line 11, in <module>

    print(session.run(cost), feed_dict={y_:2.0, y:1.0})

  File "C:\Users\sotto\Envs\tensor3\lib\site-packages\tensorflow\python\client\session.py", line 905, in run

    run_metadata_ptr)

  File "C:\Users\sotto\Envs\tensor3\lib\site-packages\tensorflow\python\client\session.py", line 1140, in _run

    feed_dict_tensor, options, run_metadata)

  File "C:\Users\sotto\Envs\tensor3\lib\site-packages\tensorflow\python\client\session.py", line 1321, in _do_run

    run_metadata)

  File "C:\Users\sotto\Envs\tensor3\lib\site-packages\tensorflow\python\client\session.py", line 1340, in _do_call

    raise type(e)(node_def, op, message)

tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'y' with dtype float

[[Node: y = Placeholder[dtype=DT_FLOAT, shape=<unknown>, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]


Caused by op 'y', defined at:

  File "C:/Users/sotto/PycharmProjects/untitled/cost01.py", line 4, in <module>

    y = tf.placeholder(tf.float32, name='y')

  File "C:\Users\sotto\Envs\tensor3\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1777, in placeholder

    return gen_array_ops.placeholder(dtype=dtype, shape=shape, name=name)

  File "C:\Users\sotto\Envs\tensor3\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 5496, in placeholder

    "Placeholder", dtype=dtype, shape=shape, name=name)

  File "C:\Users\sotto\Envs\tensor3\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper

    op_def=op_def)

  File "C:\Users\sotto\Envs\tensor3\lib\site-packages\tensorflow\python\framework\ops.py", line 3290, in create_op

    op_def=op_def)

  File "C:\Users\sotto\Envs\tensor3\lib\site-packages\tensorflow\python\framework\ops.py", line 1654, in __init__

    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access


InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'y' with dtype float

[[Node: y = Placeholder[dtype=DT_FLOAT, shape=<unknown>, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]



Process finished with exit code 1


正在回答

2回答

print(session.run(cost, feed_dict={y_:2.0, y:1.0}))

0 回复 有任何疑惑可以回复我~
  • 提问者 小土儿 #1
    是这样 - -写快了
    回复 有任何疑惑可以回复我~ 2018-04-29 13:47:35
Erik_Song 2018-04-29 13:32:43

可以使用pycharm避免这些问题

0 回复 有任何疑惑可以回复我~

相似问题

登录后可查看更多问答,登录/注册

问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信