Skip to content
Artificial Intelligence

What Is a Convolutional Neural Network? CNNs Explained

Follow an image through learned filters, feature maps, and a prediction, then see why the training data matters.

What Is a Convolutional Neural Network? CNNs Explained

Key takeaways

  • A CNN learns filters that detect useful local patterns and reuses those filters across the input.
  • Convolutional layers produce feature maps; later layers combine them into more complex representations.
  • Training adjusts the weights, while inference applies the trained network to new inputs.
  • Good accuracy on familiar images does not guarantee reliable results under different lighting, backgrounds, or camera conditions.

A convolutional neural network (CNN) is a type of neural network that learns patterns in data by applying small filters across local regions. It is widely used for images because nearby pixels contain useful relationships, such as edges, textures, and shapes.

Imagine a camera inspecting ceramic tiles for cracks. The software receives a grid of numbers describing the image. A CNN can learn combinations of visual patterns that help distinguish a cracked tile from an intact one, without an engineer writing a rule for every possible crack.

Understanding that process requires separating three things: the image values, the operations performed by the network, and the training that determines its weights.

An Image Starts as a Grid of Values

A grayscale image has one intensity value per pixel. A typical RGB image has three channels representing red, green, and blue. A 128-by-128 RGB image therefore contains 49,152 channel values.

The arrangement matters. A thin dark line surrounded by lighter pixels could be evidence of a crack. The same dark values scattered around the image would describe a different structure.

A fully connected network can process flattened image values, but a CNN explicitly uses their local arrangement. Stanford’s convolutional network notes explain this combination of local connections and shared weights.

Filters Produce Feature Maps

A filter, also called a kernel, contains weights applied to a small input region. At each position, the layer multiplies input values by corresponding weights, sums the products, and usually adds a bias.

Here is a deliberately small grayscale example with no bias:

Image patch       Filter
1  2              1   0
3  4              0  -1

Result = (1 × 1) + (2 × 0) + (3 × 0) + (4 × -1)
       = -3

Moving the same filter across the image produces a grid of results called a feature map. The example weights are chosen for illustration; a trained CNN normally learns its weights.

A layer can contain many filters, producing multiple output channels. In a standard convolution, each filter also spans the input channels. A 3-by-3 filter applied to RGB input therefore has 27 weights, plus a bias if used.

The Keras Conv2D reference describes how filter count, kernel size, stride, and padding control this operation.

Stride and Padding Control Where Filters Apply

Stride determines the spacing between filter positions. A stride of one visits adjacent positions; a larger stride generally produces a smaller spatial output.

Padding adds values around the input boundary. Without padding, a filter must fit entirely inside the image, so the output becomes smaller. With appropriate padding and stride one, a layer can preserve width and height.

For the tile example, these settings affect how much detail remains available. Reducing resolution too aggressively could remove a narrow crack before later layers have a chance to use it.

Activations and Pooling Change the Representation

Convolutional networks combine their weighted operations with nonlinear activation functions. ReLU is a common example: it keeps positive values and replaces negative values with zero.

Before ReLU: -3  0  2  7
After ReLU:   0  0  2  7

Nonlinearity lets the network represent relationships beyond a sequence of linear transformations.

Pooling reduces spatial dimensions. For example, max pooling over the values 2, 7, 4, and 3 keeps 7. It retains a strong response while discarding its exact position within that small region. Some architectures reduce resolution with strided convolutions instead.

Pooling does not guarantee that a prediction stays unchanged when an object moves or rotates. That behavior needs evaluation.

Later Layers Combine Earlier Features

An early layer might respond to a local brightness change. Later layers combine earlier feature maps over larger effective regions of the original image, called receptive fields.

In the tile example, a useful representation could distinguish a long irregular mark from the regular boundaries between tiles. That is an illustrative interpretation, not a promise that individual filters will correspond neatly to human concepts.

For image classification, the final part of the network turns those representations into class scores. Other designs can locate objects or label individual pixels. A model answering “is there a crack?” has a different output from one drawing the crack’s precise outline.

Training Teaches the Network Which Patterns Matter

For a supervised tile classifier, training begins with images labeled as cracked or intact. A loss function measures disagreement between predictions and labels. Backpropagation calculates gradients, and an optimizer updates the weights.

TensorFlow’s CNN tutorial demonstrates this process with a small image classifier, including convolutional layers, pooling, training, and evaluation.

Using the resulting network on a new photograph is inference. An ordinary prediction does not automatically retrain the network. The broader machine learning process includes deciding when new data justifies another training cycle.

A CNN Can Learn the Wrong Shortcut

Suppose all cracked tiles were photographed on a dark workbench and intact tiles on a white conveyor. The network could use the background to predict the label.

Its score might look excellent until the camera moves. To investigate, evaluate images from different backgrounds, lighting conditions, cameras, and production batches. Keep near-duplicate photographs of the same tile out of both training and evaluation sets.

Also consider the errors separately. Missing a crack and rejecting an intact tile have different costs. A single accuracy percentage hides that distinction.

CNNs provide a useful architecture for learning local patterns, but the application succeeds only when those patterns hold up beyond the examples used to build it. For the wider context, see what artificial intelligence means.

A CNN learns patterns that help with its training task; evaluation must establish whether those patterns are useful in the real setting.
Top