2016-11-16 42 views
1

您好,我是tensorflow上的新手我嘗試運行我寫的一個小函數。我已經重新啓動我的內核,這是我的腳本:爲什麼我得到這個錯誤:您必須爲dtype float提供佔位符張量'Placeholder_3'的值

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) 

的錯誤是:

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' 

回答

2

嗯,你的函數接受參數:

x1 = tf.placeholder(tf.float32, [None, None]) 
W1 = tf.placeholder(tf.float32, [None, None]) 
B1 = tf.placeholder(tf.float32,[None]) 

x2 = tf.placeholder(tf.float32, [3, 1]) 
W2 = tf.placeholder(tf.float32, [1, 3]) 
b2 = tf.placeholder(tf.float32,[3]) 

在您的sess.run中,您只指定了其中的三個,因此無法執行計算。

其實B1只是宣佈但從未使用,因此唯一缺少的是x1W1

+0

謝謝你的回答 –

相關問題