Implementing a Simpler CNN
In this recipe, we will develop a four-layer convolutional neural network to improve upon our accuracy in predicting the MNIST digits. The first two convolution layers will each be compromised of Convolution-ReLU-maxpool operations and the final two layers will be fully connected layers.
Getting ready
To access the MNIST data, TensorFlow has a contrib
package that has great dataset loading functionalities. After we load the data, we will setup our model variables, create the model, train the model in batches, and then visualize loss, accuracy, and some sample digits.
How to do it…
First, we'll load the necessary libraries and start a graph session:
import matplotlib.pyplot as plt import numpy as np import tensorflow as tf from tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets sess = tf.Session()
Next, we will load the data and transform the images into 28x28 arrays:
data_dir = 'temp' mnist = read_data_sets(data_dir) train_xdata = np.array([np...