LSTM for image processing
Let's imagine we want to perform handwriting recognition. From time to time, we get a new column of data. Is it the end of a letter? If yes, which one? Is it the end of a word? Is it punctuation? All these questions can be answered with a recurrent network.
For our test example, we will go back to our 10-digit dataset and use LSTMs instead of convolution layers.
We use similar hyperparameters:
import tensorflow as tf from tensorflow.contrib import rnn # rows of 28 pixels n_input=28 # unrolled through 28 time steps (our images are (28,28)) time_steps=28 # hidden LSTM units num_units=128 # learning rate for adam learning_rate=0.001 n_classes=10 batch_size=128 n_epochs = 10 step = 100
Setting up training and testing data is almost similar to our CNN example, except for the way we reshape the images:
import os import numpy as np from sklearn.datasets import fetch_mldata from sklearn.model_selection import train_test_split mnist = fetch_mldata('MNIST original') mnist...