Building an image classifier using a Convolutional Neural Network
The image classifier in the previous section didn't perform that well. Getting 92.1% on the MNIST dataset is relatively easy. Let's see how we can use CNNs to achieve a much higher accuracy. We will build an image classifier using the same dataset, but with a CNN instead of a single-layer neural network.
Create a new Python file and import the following packages:
import argparse
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
Define a function to create values for weights in each layer:
def get_weights(shape):
data = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(data)
Define a function to create values for biases in each layer:
def get_biases(shape):
data = tf.constant(0.1, shape=shape)
return tf.Variable(data)
Define a function to create a layer based on the input shape:
def create_layer...