How CNNs Work
- Input Image: The network processes an image (e.g., Tweety).
- Convolution Layer: Extracts features using kernels (filters).
- Pooling Layer: Reduces the spatial size for computational efficiency.
- Feature Maps: Hierarchical features are extracted (from edges to complex patterns).
- Flatten Layer: Converts feature maps into a vector for classification.
- Fully Connected Layer: Processes features and makes predictions.
- Output: Probabilistic predictions using the Softmax function.
CNN Code Example
Here's how we can define the layers of a CNN:
import tensorflow as tf
from tensorflow.keras import layers
model = tf.keras.Sequential([
layers.Input(shape=(224, 224, 3)), # Input Layer
layers.Conv2D(filters=10, kernel_size=3), # Convolution Layer
layers.MaxPool2D(pool_size=(2, 2)), # Max Pooling Layer
layers.Flatten(), # Flatten Layer
layers.Dense(10, activation="softmax") # Fully Connected (Dense) Layer
])