LeNet CNN for MNIST with TensorFlow

In TensorFlow, apply the following steps to build the LeNet based CNN models for MNIST data:

  1. Define the hyper-parameters, and the placeholders for x and y (input images and output labels):
n_classes = 10 # 0-9 digitsn_width = 28n_height = 28n_depth = 1n_inputs = n_height * n_width * n_depth # total pixelslearning_rate = 0.001n_epochs = 10batch_size = 100n_batches = int(mnist.train.num_examples/batch_size)# input images shape: (n_samples,n_pixels)x = tf.placeholder(dtype=tf.float32, name="x", shape=[None, n_inputs]) # output labelsy = tf.placeholder(dtype=tf.float32, name="y", shape=[None, n_classes])

Reshape the input x to shape (n_samples, n_width, n_height, n_depth):

x_ = tf.reshape(x, shape=[-1, n_width, ...

Get Python: Advanced Guide to Artificial Intelligence now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.