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…

  1. 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 ...

Get TensorFlow Machine Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.