Building the model

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.

Coding the 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))

Previous Section

Next Section

2.2. The Data

2.4 Reducing Overfitting

<aside> ⚖️ Copyright © 2022 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License.

If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact [email protected] for inquiries.

</aside>