gpt4 book ai didi

python - TensorFlow 无法为张量 'Placeholder_21:0' 提供形状 (538, 1) 的值,该张量的形状为 '(?, 8)' ?

转载 作者:行者123 更新时间:2023-12-01 08:04:31 24 4
gpt4 key购买 nike

我尝试实现一个神经网络来解决分类问题,但是我的程序:

 _, c = sess.run([train_op, loss_op], feed_dict={X: x_train,Y: y_train})

我尝试 reshape 数据并尝试了堆栈中给出的许多解决方案来解决我的问题,但对我不起作用,我想知道我应该做什么?

最重要的部分:

...
n_output = 8
n_input = 9 # Max number of input that may have features of one single program
################################ Dfine data ####################################
from google.colab import files
import io

uploaded = files.upload()
x_train_ = pd.read_csv(io.StringIO(uploaded['x_train.csv'].decode('utf-8')), skiprows=1, header=None)
uploaded1 = files.upload()
y_train_ = pd.read_csv(io.StringIO(uploaded1['y_train.csv'].decode('utf-8')), skiprows=1, header=None)
x_train.fillna(-1, inplace=True)

x_train = np.array(x_train)
y_train = np.array(y_train)

################################ Input, weights, biases ########################
# tf Graph input
X = tf.placeholder(shape=[None, n_input], dtype=tf.float32)
Y = tf.placeholder(shape=[None, n_output], dtype=tf.float32)
.....
################################ Construct model ###############################
logits = multilayer_perceptron(X)
# Define loss and optimizer
loss_op = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=Y))
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate)
train_op = optimizer.minimize(loss_op)
...

# Initializing the variables
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
# Training cycle
for epoch in range(training_epochs):
avg_cost = 0.
_, c = sess.run([train_op, loss_op], feed_dict={X: x_train,Y: y_train})
...
print("Optimization Finished!")

编辑:一旦我打印出来:print(y_train_.head())它给出:

    0
0 2
1 4
2 8
3 16
4 32

最佳答案

Y = tf.placeholder(shape=[None, n_output], dtype=tf.float32)这样你的 Y 占位符的形状就是 [m, 8]。显然 y_train 构造不正确,尝试使用 y_train.values() 而不是 np.array(y_train)。

关于python - TensorFlow 无法为张量 'Placeholder_21:0' 提供形状 (538, 1) 的值,该张量的形状为 '(?, 8)' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55598430/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com