0
我目前正在学习TensorFlow。我正在尝试创建一个能准确评估预测模型并为其指定分数的NN。我现在的计划是将已有程序的分数与mlp进行比较,并将它们与真实值进行比较。我玩过MNIST的数据,我正在尝试将我所学到的知识应用于我的项目。不幸的是我有一个问题tensorflow ValueError:两个形状中的维度0必须相等
def multilayer_perceptron(x, w1):
# Hidden layer with RELU activation
layer_1 = tf.matmul(x, w1)
layer_1 = tf.nn.relu(layer_1)
# Output layer with linear activation
#out_layer = tf.matmul(layer_1, w2)
return layer_1
def my_mlp (trainer, trainer_awn, learning_rate, training_epochs, n_hidden, n_input, n_output):
trX, trY= trainer, trainer_awn
#create placeholders
x = tf.placeholder(tf.float32, shape=[9517, 5])
y_ = tf.placeholder(tf.float32, shape=[9517, ])
#create initial weights
w1 = tf.Variable(tf.zeros([5, 1]))
#predicted class and loss function
y = multilayer_perceptron(x, w1)
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y, y_))
#training
train_step = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cross_entropy)
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
with tf.Session() as sess:
# you need to initialize all variables
sess.run(tf.initialize_all_variables())
print("1")
for i in range(training_epochs + 1):
sess.run([train_step], feed_dict={x: [trX['V7'], trX['V8'], trX['V9'], trX['V10'], trX['V12']], y_: trY})
return
的代码给了我这个错误
ValueError: Dimension 0 in both shapes must be equal, but are 9517 and 1
运行cross_entropy线的时候,会出现此错误。我不明白为什么这会发生,如果你需要更多的信息,我会很乐意给你。
谢谢你的完美工作! –