Hello I am new on tensorflow I try to run little function I wrote. I already reboot my kernel and this is my script :
你好,我是新手,我尝试运行我写的小函数。我已经重新启动了内核,这是我的脚本:
import tensorflow as tf
def phi1 (x,B,w) :
x1 = tf.placeholder(tf.float32, [None, None])
W1 = tf.placeholder(tf.float32, [None, None])
B1 = tf.placeholder(tf.float32,[None])
phi = []
x2 = tf.add(x1,x)
W2 = tf.add(W1,w)
y = tf.matmul(x2,W2)
print(y.get_shape())
for i in range(3):
z1=tf.sin(y[i,:])*tf.transpose(B)
Z2=tf.cos(y[i,:])*tf.transpose(B)
z1= tf.cast(z1, tf.float32)
z2= tf.cast(Z2, tf.float32)
#print(type(z2))
phi.append(z1)
phi.append(z2)
y = phi
return y
x2 = tf.placeholder(tf.float32, [3, 1])
W2 = tf.placeholder(tf.float32, [1, 3])
b2 = tf.placeholder(tf.float32,[3])
y = phi1 (x2,b2,W2)
init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
z4_op = sess.run(y , feed_dict = {x2: [[1.0],[2.0],[3.0]], b2: [0.5, 2.0, 1.0], W2: [[1.0, 2.0, 3.0]]})
print(z4_op)
the error is :
错误的是:
InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_3' with dtype float
[[Node: Placeholder_3 = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Caused by op 'Placeholder_3'
1 个解决方案
#1
2
Well your function accepts 6 arguments:
你的函数接受6个参数:
x1 = tf.placeholder(tf.float32, [None, None])
W1 = tf.placeholder(tf.float32, [None, None])
B1 = tf.placeholder(tf.float32,[None])
and
和
x2 = tf.placeholder(tf.float32, [3, 1])
W2 = tf.placeholder(tf.float32, [1, 3])
b2 = tf.placeholder(tf.float32,[3])
in your sess.run
you only specified three of them, thus computations cannot be performed.
在您的sess.run中,您只指定了其中的三个,因此无法执行计算。
Actually B1
is only declared but never used, thus the only missing ones are x1
and W1
.
实际上B1只被声明但从未被使用,因此唯一缺失的是x1和W1。
#1
2
Well your function accepts 6 arguments:
你的函数接受6个参数:
x1 = tf.placeholder(tf.float32, [None, None])
W1 = tf.placeholder(tf.float32, [None, None])
B1 = tf.placeholder(tf.float32,[None])
and
和
x2 = tf.placeholder(tf.float32, [3, 1])
W2 = tf.placeholder(tf.float32, [1, 3])
b2 = tf.placeholder(tf.float32,[3])
in your sess.run
you only specified three of them, thus computations cannot be performed.
在您的sess.run中,您只指定了其中的三个,因此无法执行计算。
Actually B1
is only declared but never used, thus the only missing ones are x1
and W1
.
实际上B1只被声明但从未被使用,因此唯一缺失的是x1和W1。