Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Image data and convolutional neural networks

OriginalTranslatedCoarsenedSuper-resolved
originaltranslatedcoarsefine

Compared to structured tabular datasets like Iris, images pose some particular challenges. For example, the four images above all contain the same object. But they would be viewed very differently by an MLP.

VersionVector
Original
Shifted
Coarsened
Super-resolved

If we trained a MLP only on centered MNIST images, the shifted image might cause a completely different set of activations in the hidden layer, leading to misclassification. And the coarsened/super-resolved images would have sizes that are incompatible with the hidden layer weight matrix.

Animal vision tends to overcome these problems, and CNNs are loosely inspired by experimental results on the visual cortex. These experiments revealed a hierarchical structure with simple and complex cells. The simple cells identify features such as edges within narrow visual regions, or receptive fields. The complex cells probe a larger region and their activation is less sensitive on the exact position of an object within their view.

Visual perception, therefore, roughly follows this process

Retinal stimulation→⏟Simple cellsLow-level features→⏟Complex cellsHigh-level features→⏟…Recognition\begin{align} \text{Retinal stimulation} \underbrace{\rightarrow}_{\text{Simple cells}} \text{Low-level features} \underbrace{\rightarrow}_{\text{Complex cells}} \text{High-level features} \underbrace{\rightarrow}_{\dots} \text{Recognition} \end{align}

Convolutional neural networks (CNN) aim to learn feature maps that incorporate several key aspects:

  • Sparse connectivity - like simple cells, each output of a CNN layer accesses only a small region of the input

  • Weight sharing - like complex cells, CNNs produce outputs that are insensitive to position by applying the same weights at different places, and pooling the outputs

Combined, these properties give CNNs an important property called translation equivariance

f(g(x))=g(f(x))f is equivariant to g\begin{align} f\big(g(x)\big) = g\big(f(x)\big) & & \mbox{f is equivariant to g} \\ \end{align}

Suppose we have a translation operator TT that acts on an image by shifting every pixel to the right by one: T(Ix,y)=Ix−1,yT(I_{x,y}) = I_{x-1, y}. A CNN layer produces a feature map fx,y(I)f_{x,y}(I) that is equivariant to TT

fx,y(T(Ix,y))=fx,y(Ix−1,y)=fx−1,y(Ix,y)=T(fx,y(Ix,y))\begin{align} f_{x,y}\big( T (I_{x,y})\big) = f_{x,y}( I_{x-1,y} ) = f_{x-1,y} (I_{x,y}) = T\big( f_{x,y} ( I_{x,y}) \big) \end{align}

The feature map of a shifted image is identical to the shifted feature map of the original image.

How do we possibly make this work in practice? That’s the focus of the lecture today.

What is a convolution?

The convolution of two functions f(x),w(x)f(x), w(x) is

(f∗w)(x)=∫−∞∞f(t) w(x−t) dt\begin{align} (f * w)(x) = \int_{-\infty}^{\infty} f(t) \, w(x-t) \, dt \end{align}

or equivalently

(f∗w)(x)=∫−∞∞f(x−t) w(x) dt\begin{align} (f * w)(x) = \int_{-\infty}^{\infty} f(x - t) \, w(x) \, dt \end{align}

Loosely, it’s a way of “mixing up” two functions. We sometimes refer to ww as a weighting function, or alternatively a kernel function.

Convolution has several very nice algebraic properties which we don’t need to get into. Read more here.

Computers are finite objects. So in general, we cannot evaluate integrals with infinitesimally small differentials dtdt. Instead, we compute the discrete convolution using a sum

z[i]=∑j=−∞∞x[i−j] w[j]\begin{align} z[i] = \sum_{j=-\infty}^{\infty} x[i-j] \, w[j] \end{align}

Note that we also cannot evaluate sums over infinite domains. So we often work with finite kernels such that

z[i]=∑j=−KKx[i−j] w[j]\begin{align} z[i] = \sum_{j=-K}^{K} x[i-j] \, w[j] \end{align}

Implementing discrete convolutions

Speeding up discrete convolutions

Example: Gradient filter

Example: edge detection (Sobel)

Convolutions and Cross-Correlations as a sliding dot product

Sketch this on the whiteboard

Image data often has multiple channels