0
這是我的代碼:InvalidArgumentError(參見上述用於回溯):必須喂爲佔位符張量「佔位符」的值與D型浮子
import numpy as np
import tensorflow as tf
input_dim=8
layer1_dim=6
learning_rate=0.01
train_data=np.loadtxt("data.txt",dtype=float)
train_target=train_data[:,-1]
train_feature=train_data[:,0:-1]
test_data=np.loadtxt("data.txt",dtype=float)
test_target=test_data[:,-1]
test_feature=test_data[:,0:-1]
x=tf.placeholder(tf.float32)
y=tf.placeholder(tf.float32)
w1=tf.Variable(tf.random_normal([input_dim,layer1_dim]))
b1=tf.Variable(tf.random_normal([1,layer1_dim]))
layer_1 = tf.nn.tanh(tf.add(tf.matmul(x, w1), b1))
loss=tf.reduce_mean(tf.square(layer_1-y))
train_op = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss)
init = tf.global_variables_initializer()
with tf.Session() as session:
session.run(init)
for i in range(10):
print(session.run(train_op, feed_dict={x: train_feature, y: train_target}))
print(layer_1)
print(loss.eval())
這是我的錯誤:
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder' with dtype float
[[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=<unknown>, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
過程以退出代碼結束1
數據只是一個常規矩陣,即6x8特徵和6x1目標。 sess.run的打印爲無。 如果我不打印損失,則沒有錯誤,但是沒有sess.run。
如果在佔位符聲明中指定了尺寸,會發生什麼情況? – IanTimmis
形狀爲'(?,1)'的Tensor'Placeholder_1:0'無法提供形狀(6,)的值。 – user6876743
嘗試並重新設置(6,)到(6,1) – IanTimmis