我刚刚开始学习tensorflow,并试图实现一个双层网络,但我似乎无法让它工作。你们可以在下面的代码中指出我目前的错误吗?谢谢。
# Hidden layer and output layer
hidden_node = 20
output_node = 10
# Weights and biases for layer one
layer1_weight = tf.Variable(tf.zeros([784, hidden_node]))
layer1_bias = tf.Variable(tf.zeros([hidden_node]))
# Weights and biases for layer two
layer2_weight = tf.Variable(tf.zeros(hidden_node, output_node))
layer2_bias = tf.Variable(tf.zeros([output_node]))
# Hidden and output layer
input = tf.matmul(mnist_dataset, layer1_weight) + layer1_bias
hidden = tf.nn.relu(input)
ouput = tf.matmul(hidden, layer2_weight) + layer2_bias
output_layer = tf.nn.softmax(output)
scores = tf.placeholder(tf.float32, [None, output_node])
loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits
(output_layer, mnist_labels))
# Optimizer.
optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss)
答案 0 :(得分:0)
你在这里缺少一组括号:
layer2_weight = tf.Variable(tf.zeros(hidden_node, output_node))
应该是:
layer2_weight = tf.Variable(tf.zeros([hidden_node, output_node]))