TensorFlow-based MLP for MNIST classification

First, load the MNIST dataset, and define the training and test features and the targets using the following code:

from tensorflow.examples.tutorials.mnist import input_datamnist_home = os.path.join(datasetslib.datasets_root, 'mnist')mnist = input_data.read_data_sets(mnist_home, one_hot=True)X_train = mnist.train.imagesX_test = mnist.test.imagesY_train = mnist.train.labelsY_test = mnist.test.labelsnum_outputs = 10 # 0-9 digitsnum_inputs = 784 # total pixels

We create three helper functions that will help us create a simple MLP with only one hidden layer, followed by a larger MLP with multiple layers and multiple neurons in each layer.

The mlp() function builds the network layers with the following ...

Get Python: Advanced Guide to Artificial Intelligence 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.