python
import tensorflow as tf
x = tf.placeholder(tf.float32, shape=[None, 784])
W_hidden = tf.Variable(tf.random_normal([784, 256]))
b_hidden = tf.Variable(tf.zeros([256]))
hidden_layer = tf.nn.relu(tf.matmul(x, W_hidden) + b_hidden)
W_output = tf.Variable(tf.random_normal([256, 10]))
b_output = tf.Variable(tf.zeros([10]))
output_layer = tf.matmul(hidden_layer, W_output) + b_output
y_true = tf.placeholder(tf.float32, shape=[None, 10])
loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=output_layer, labels=y_true))
optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01).minimize(loss)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for epoch in range(1000):
sess.run(optimizer, feed_dict={x: batch_x, y_true: batch_y})
accuracy = sess.run(accuracy_metrice, feed_dict={x: test_x, y_true: test_y})