Locally Masked Convolution for Autoregressive Models

Ajay Jain, Pieter Abbeel, Deepak Pathak

Abstract

Autoregressive (AR) models, such as PixelCNN, are powerful tools for estimating high-dimensional data distributions but are traditionally limited by a fixed raster-scan generation order. This constraint leads to "blind spots" in local receptive fields and prevents models from conditioning on future context in tasks like image completion. This paper introduces Locally Masked Convolution (LMCONV), a novel approach that applies location-specific masks to input patches rather than global masks to weights. This modification allows AR models to generate data in arbitrary orders, enabling state-of-the-art density estimation on CIFAR10 and MNIST and providing superior flexibility for conditional generation tasks.

Introduction

Autoregressive models decompose the joint distribution of high-dimensional data into a sequence of conditional probabilities. While effective, standard implementations rely on a fixed top-left to bottom-right raster-scan order. This creates two primary challenges: first, the use of a single global weight mask can prevent the model from observing nearby pixels (blind spots); second, the fixed order makes it impossible to condition on pixels that appear later in the sequence, such as completing the top of an image given the bottom.

Methods: Locally Masked Convolution

The core innovation of this work is the transition from global to local masking. In a standard PixelCNN, a single mask is applied to the convolutional weights. In contrast, LMCONV applies a binary mask to the input patch at each spatial location $(i, j)$. This allows the "causal neighborhood" to vary dynamically across the image.

Mechanism of Locally Masked Convolution (LMCONV) applying masks to input patches.

Implementation and Training

To maintain computational efficiency, the authors modify the standard im2col operation, applying location-specific masks directly to the rearranged image patches before matrix multiplication. This architecture enables order-agnostic training, where a single model with shared weights can be trained on multiple traversal paths, such as raster-scans, S-curves, or Hilbert curves. To manage memory overhead during backpropagation, a custom backward pass recomputes the im2col operation, achieving significant memory savings with minimal speed penalties.

Key Insights

  • Arbitrary Traversal: By supporting flexible generation orders, the model can optimize its traversal for specific tasks. For example, center-hole filling can be achieved by generating pixels from the outside in.
  • Space-Filling Curves: Utilizing Hilbert curves helps the model capture dependencies between nearby, highly correlated pixels more effectively than traditional row-by-row scanning.
  • Ensembling: Averaging predictions from multiple generation orders significantly improves density estimation, effectively creating an ensemble of different graphical models.

Results and Evaluation

The model was evaluated on standard benchmarks including MNIST, CIFAR10, and CelebA-HQ. LMCONV achieved state-of-the-art results on CIFAR10 with 2.89 bits per dimension (bpd), outperforming PixelCNN++ (2.92 bpd). It also set new benchmarks for both binarized and grayscale MNIST.

Image completion results using LMCONV compared to original images for different observation masks.

In image completion tasks, LMCONV showed a dramatic advantage over fixed-order models. When generating the top half of a CIFAR10 image given the bottom half, LMCONV achieved 2.76 bpd, whereas PixelCNN++ was limited to 3.07 bpd. Qualitatively, the model produces highly coherent completions, maintaining symmetry and structural integrity that raster-scan models often fail to capture.

Conclusion and Future Work

LMCONV provides a simple yet powerful framework for making autoregressive models more flexible and context-aware. While the current implementation is more computationally demanding than standard convolutions, its ability to handle arbitrary generation orders opens new possibilities for conditional image synthesis. Future research may explore integrating LMCONV with self-attention mechanisms to capture even longer-range dependencies while maintaining the benefits of local causal masking.

Summary updated

BibTeX
@inproceedings{jain2020locally,
  author = {Ajay Jain and Pieter Abbeel and Deepak Pathak},
  title = {{Locally Masked Convolution for Autoregressive Models}},
  booktitle = {Conference on Uncertainty in Artificial Intelligence},
  year = {2020},
}
Figure