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 Mastering TensorFlow 1.x 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.