liveBook · Manning

Aliasing

As explained in Inside Deep Learning: Math, Algorithms, Models

A sampling artifact in which fine-grained detail is collapsed into a smaller representation, causing distinct inputs to become indistinguishable.

Aliasing happens when downsampling collapses fine detail so that different inputs become indistinguishable. Max-pool a zebra image by a factor of four and dense stripes turn into blocky jaggies; detail is especially hard to recover around the face. Repeating pooling layers compounds the problem. section 14.1

Different patterns, identical pooled values

Consider three distinct one-dimensional black-and-white patterns. Ordinary max pooling produces the same output for all three. The lost distinctions cannot be inferred from that output. section 14.1

This matters beyond image appearance. Pooling is meant to help a CNN give similar predictions when an image shifts, but aliasing limits that benefit. To test it, train on random 24 × 24 crops of CIFAR-10 images, then evaluate different 24 × 24 crops of the same 32 × 32 test image. Compare the predicted probability of its correct class across crop positions. section 14.1.1

An anti-aliased replacement separates finding local maxima from shrinking the representation. First, max-pool with stride 1 so nearby maxima remain available. Then blur those values with a center-weighted binomial filter, using the blur operation’s stride to downsample. Mixing neighboring values before reduction helps distinguish patterns that ordinary max pooling merges. In PyTorch, this is packaged as `MaxPool2dAA`, using a `BlurLayer` after `F.max_pool2d`. section 14.1.2 section 14.1.3

class MaxPool2dAA(nn.Module): 
    def __init__(self, kernel_size=2, ratio=1.7): 
        """ 
        kernel_size: how much to pool by 
        ratio: how much larger the blurring filter should be than the 
         pooling size 
        """
        super(MaxPool2dAA, self).__init__() 

        blur_ks = int(ratio*kernel_size)                   #1 
        self.blur = BlurLayer(kernel_size=blur_ks,         #2 
         stride=kernel_size, D=2) 
        self.kernel_size = kernel_size                     #3

    def forward(self, x): 
        ks = self.kernel_size 
        tmp = F.max_pool2d(x, ks, stride=1, padding=ks//2) #4 
        return self.blur(tmp)                              #5
#1 Makes a slightly larger filter for blurring
#2 Creates the blur kernel
#3 Stores the pooling size
#4 Applies pooling with stride=1
#5 Blurs the result

The replacement layer pools at stride 1, then applies a blurring layer whose stride performs the intended reduction. section 14.1.3

Replacing ordinary pooling makes shifted-crop predictions more consistent in the comparison, but does not eliminate aliasing or guarantee a better prediction for every image. Average pooling and strided convolutions can have related problems; for a strided convolution, use stride 1 through the convolution, normalization, and activation, then downsample with a `BlurLayer`. section 14.1.3

How Inside Deep Learning: Math, Algorithms, Models covers it

How deep it goes
Works through pooling collisions, stride-one maxima, blurring, a PyTorch replacement, and shifted-image tests without promising perfect invariance.
Examples
Uses zebra stripes, three one-dimensional patterns with identical pooled outputs, and CIFAR-10 shifted-crop predictions.
What it assumes
Assumes basic CNN and max-pooling familiarity while building the blurring replacement from pooling and convolution operations.
What you can do after
Apply it via PyTorch’s `MaxPool2dAA` replacement and compare classification accuracy and shifted-crop confidence.
How it connects
Connects max pooling, convolution, blurring, downsampling, and translation invariance.

Also explained in

Compare how 2 books explain aliasing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Inside Deep Learning: Math, Algorithms, Models. The section links point to the parts of the book it draws on.