Building and Evaluating the Convolutional Neural Network (CNN)
While the ANN can classify images, it does not preserve the spatial features present in image data. Convolutional Neural Networks (CNNs) overcome this limitation by automatically learning important features such as edges, textures, and shapes.
In this module, you will build a CNN, train it using the CIFAR-10 dataset, evaluate its performance, and compare its results with the ANN model.
Building the CNN Model
Create the Convolutional Neural Network.
Code
cnn = keras.Sequential([
keras.layers.Conv2D(32, (3,3), activation='relu', input_shape=(32,32,3)),
keras.layers.MaxPooling2D((2,2)),
keras.layers.Conv2D(64, (3,3), activation='relu'),
keras.layers.MaxPooling2D((2,2)),
keras.layers.Flatten(),
keras.layers.Dense(64, activation='relu'),
keras.layers.Dense(10, activation='softmax')
])
Explanation
The CNN includes:
- Convolution Layers
- Max Pooling Layers
- Flatten Layer
- Dense Layer
- Output Layer
These layers help the model automatically learn image features.










