Step 4 – Constructing the CNN layers

Once we have defined the CNN hyperparameters, the next task is to implement the CNN network. As you can guess, for our task, we will construct a CNN network having three convolutional layers, a flattened layer and two fully connected layers (refer to LayersConstructor.py). Moreover, we need to define the weight and the bias as well. Furthermore, we will have implicit max-pooling layers too. At first, let's define the weight. In the following, we have the new_weights() method that asks for the image shape and returns the truncated normal shapes:

def new_weights(shape): 
    return tf.Variable(tf.truncated_normal(shape, stddev=0.05)) 

Then we define the biases using the new_biases() method:

def new_biases(length): ...

Get Practical Convolutional Neural Networks 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.