###### qq_34644971

2018-11-10 04:51 阅读 1.4k

# 使用RNN进行手写数字识别，为什么正确率总是无法提高

``````import tensorflow as tf

from tensorflow.contrib.layers import fully_connected
from tensorflow.examples.tutorials.mnist import input_data
n_steps = 28
n_inputs = 28
n_neurons = 100
x = tf.placeholder(tf.float32,[None,n_steps,n_inputs])
action_one_hot = tf.placeholder(tf.float32,[None,10])

basic_cell = tf.contrib.rnn.BasicRNNCell(num_units=n_neurons)
output_seqs, states = tf.nn.dynamic_rnn(basic_cell,x,dtype=tf.float32)
y0 = fully_connected(states,100,activation_fn=tf.nn.relu)
y = fully_connected(y0,10)
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(labels=action_one_hot, logits=y)
mean_loss = tf.reduce_mean(cross_entropy)

with tf.Session() as sess:
for i in range(10000):
sess.run(tf.global_variables_initializer())
x1,y1 = mnist.train.next_batch(1000)
x1 = x1.reshape((-1,n_steps,n_inputs))
sess.run(trian_op,feed_dict={x:x1,action_one_hot:y1})
if i%200==0:
print(sess.run(mean_loss,feed_dict={x:x1,action_one_hot:y1}))
``````

• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享