我试图将x_data传递为feed_dict,但由于错误程度较低,我不确定代码中有什么问题。
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'x_12' with dtype int32 and shape [1000]
[[Node: x_12 = Placeholder[dtype=DT_INT32, shape=[1000], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]我的守则:
import tensorflow as tf
import numpy as np
model = tf.global_variables_initializer()
#define x and y
x = tf.placeholder(shape=[1000],dtype=tf.int32,name="x")
y = tf.Variable(5*x**2-3*x+15,name = "y")
x_data = tf.pack(np.random.randint(0,100,size=1000))
print(x_data)
print(x)
with tf.Session() as sess:
sess.run(model)
print(sess.run(y,feed_dict={x:x_data}))我检查了x和x_data的形状,结果是一样的。
Tensor("pack_8:0", shape=(1000,), dtype=int32)
Tensor("x_14:0", shape=(1000,), dtype=int32)我正在处理一维数据。任何帮助都是感激的,谢谢!
发布于 2017-02-10 10:55:21
为了工作,我改变了两件事,第一,我把y变成了Tensor。第二,我没有将x_data更改为Tensor,就像注释这里一样
可选的feed_dict参数允许调用方覆盖图中张量的值。feed_dict中的每个键都可以是以下类型之一: 如果键是张量,则该值可能是Python标量、字符串、列表或numpy ndarray,可以转换为与该张量相同的dtype。此外,如果键是占位符,则将检查值的形状是否与占位符兼容。
为我工作的更改代码:
import tensorflow as tf
import numpy as np
model = tf.global_variables_initializer()
#define x and y
x = tf.placeholder(shape=[1000],dtype=tf.int32,name="x")
y = 5*x**2-3*x+15 # without tf.Variable, making it a tf.Tensor
x_data = np.random.randint(0,100,size=1000) # without tf.pack
print(x_data)
print(x)
with tf.Session() as sess:
sess.run(model)
print(sess.run(y,feed_dict={x:x_data}))https://stackoverflow.com/questions/42154108
复制相似问题