import numpy as np
import tensorflow as tf

"""
Do an MNIST classification line by line by LSTM
"""

(x_train, y_train), \
    (x_test, y_test) = tf.keras.datasets.mnist.load_data()
x_train, x_test = x_train/255.0, x_test/255.0

model = tf.keras.Sequential()
model.add(tf.keras.layers.LSTM(128, input_shape=(None, 28)))
#model.add(tf.keras.layers.BatchNormalization())
model.add(tf.keras.layers.Dense(10))
model.add(tf.keras.layers.Activation("softmax"))
model.summary()

model.compile(loss=tf.keras.losses.SparseCategoricalCrossentropy(),
              optimizer="sgd",
              metrics=["accuracy"])

model.fit(x_train, y_train, validation_data=(x_test, y_test),
          batch_size=100, epochs=100)


[((9, 23, 9, 58), 'tensorflow.keras.datasets.mnist.load_data', 'tf.keras.datasets.mnist.load_data', ({}, {}), '()', True, 'import tensorflow as tf\n'), ((12, 8, 12, 29), 'tensorflow.keras.Sequential', 'tf.keras.Sequential', ({}, {}), '()', True, 'import tensorflow as tf\n'), ((13, 10, 13, 59), 'tensorflow.keras.layers.LSTM', 'tf.keras.layers.LSTM', (), '', True, 'import tensorflow as tf\n'), ((15, 10, 15, 35), 'tensorflow.keras.layers.Dense', 'tf.keras.layers.Dense', ({(15, 32, 15, 34): '(10)'}, {}), '(10)', True, 'import tensorflow as tf\n'), ((16, 10, 16, 47), 'tensorflow.keras.layers.Activation', 'tf.keras.layers.Activation', ({(16, 37, 16, 46): '"""softmax"""'}, {}), "('softmax')", True, 'import tensorflow as tf\n'), ((19, 19, 19, 66), 'tensorflow.keras.losses.SparseCategoricalCrossentropy', 'tf.keras.losses.SparseCategoricalCrossentropy', ({}, {}), '()', True, 'import tensorflow as tf\n')]