The library Tensorflow includes a built-in CNN and Pooling function. By adjusting the number of layers, we can increase or decrease our model’s complexity. To create our model, we first define our number of layers (for example, 3). For each of our 3 layers, we sandwich 2 Max Pooling/Average Pooling (MaxPool2D) layers between 3 Convolutional 2D layers (Conv2D). Finally, for our output layer, we use a Dense model.
import tensorflow as tf def build_model(): model = tf.keras.Sequential() #Convolutional Layer model.add(tf.keras.layers.Conv2D(number_of_kernels, (filter_size, filter_size), activation_function)) #Max Pool Layer model.add(tf.keras.layers.MaxPool2D((filter_size, filter_size)) #Output Layer model.add(tf.keras.layers.Dense(number_of_kernels, activation_function))