A convolutional neural network, or CNN, is a type of machine learning model that is especially good at understanding images. It can learn to recognize patterns such as edges, shapes, textures, and objects without a programmer listing every rule by hand. CNNs matter because they power tools like face detection, medical image analysis, self-driving car vision, and photo search.
They connect computer science, statistics, and physics ideas by turning visual information into numbers that can be processed step by step.
A CNN works by passing an image through layers that each learn a different kind of feature. Early layers often detect simple patterns like lines or corners, while deeper layers combine those patterns into parts of objects and then full objects. Convolution filters slide across the image and produce feature maps, pooling layers shrink the information, and fully connected layers help make the final prediction.
During training, the network compares its prediction to the correct answer and adjusts its weights to reduce error.
Key Facts
- A CNN takes an image input as a grid of pixel values, often with 3 color channels for red, green, and blue.
- Convolution uses a small filter that slides over the image to detect local patterns such as edges or textures.
- Feature map value = sum of pixel values times filter weights plus bias.
- ReLU activation is often written as f(x) = max(0, x), which keeps positive values and changes negative values to 0.
- Pooling reduces image size while keeping important information, such as using max pooling to keep the largest value in each small region.
- Training updates weights to reduce loss, often using gradient descent: new weight = old weight - learning rate × gradient.
Vocabulary
- Convolutional Neural Network
- A neural network designed to process grid-like data such as images by learning patterns through convolution filters.
- Filter
- A small grid of weights that slides across an image to detect a specific feature such as an edge or texture.
- Feature Map
- The output created when a filter scans an image and marks where a learned pattern appears.
- Pooling
- A step that shrinks a feature map while keeping the most important information.
- Training
- The process of showing a model many labeled examples so it can adjust its weights and improve its predictions.
Common Mistakes to Avoid
- Thinking a CNN sees images like a human, which is wrong because it processes arrays of numbers and learns statistical patterns from pixels.
- Assuming the first layer recognizes whole objects, which is wrong because early layers usually detect simple features like edges, corners, and color changes.
- Forgetting that filters are learned during training, which is wrong because CNNs improve by changing filter weights based on prediction error.
- Treating high accuracy as proof the model understands the world, which is wrong because a CNN may still fail on unusual images, biased data, or examples outside its training set.
Practice Questions
- 1 A grayscale image is 28 pixels by 28 pixels. How many pixel values are in the input image?
- 2 A 32 by 32 image with 3 color channels is passed into a CNN. How many total input numbers represent the image?
- 3 Explain why a CNN often uses several convolution layers instead of trying to classify an image directly from raw pixels.