import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
# 载入数据
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
# 输入图片是28
n_input = 28
max_time = 28
lstm_size = 100 # 隐藏单元
n_class = 10 # 10个分类
batch_size = 50 # 每次50个样本
n_batch_size = mnist.train.num_examples // batch_size # 计算一共有多少批次
# 这里None表示第一个维度可以是任意长度
# 创建占位符
x = tf.placeholder(tf.float32,[None, 28*28])
# 正确的标签
y = tf.placeholder(tf.float32,[None, 10])
# 初始化权重 ,stddev为标准差
weight = tf.Variable(tf.truncated_normal([lstm_size, n_class], stddev=0.1))
# 初始化偏置层
biases = tf.Variable(tf.constant(0.1, shape=[n_class]))
# 定义RNN网络
def RNN(X, weights, biases):
# 原始数据为[batch_size,28*28]
# input = [batch_size, max_time, n_input]
input = tf.reshape(X,[-1, max_time, n_input ])
# 定义LSTM的基本单元
lstm_cell = tf.contrib.rnn.BasicLSTMCell(lstm_size)
# final_state[0]