PixelNN: Example-based Image Synthesis

Aayush Bansal, Yaser Sheikh, Deva Ramanan

Introduction

Conditional image synthesis is the task of generating a high-resolution, photorealistic image from an "incomplete" input signal, such as a rough sketch, an edge map, a surface normal map, or a low-resolution thumbnail.

Currently, Generative Adversarial Networks (GANs) are the state-of-the-art for this task. However, they suffer from two major limitations:

  1. Mode Collapse: GANs often struggle to produce a diverse set of outputs for a single input. For example, given a single edge map of a cat, a GAN might repeatedly generate the exact same fur pattern, ignoring the vast number of plausible real-world variations.
  2. Lack of Interpretability: GANs operate as "black boxes." It is notoriously difficult for users to control the output or understand exactly why the model chose a specific texture, color, or feature.

Conversely, traditional regression models (like standard Convolutional Neural Networks) can capture the overall structure but fail on fine details. Because they attempt to minimize mean squared error across all possible valid outputs, they typically produce blurry, averaged images.

To address these issues, researchers introduce PixelNN, a hybrid image synthesis framework. PixelNN combines the structural power of CNNs with the diversity and interpretability of classical nearest-neighbor (NN) search, effectively "copy-pasting" high-frequency details from training examples to generate diverse, photorealistic images.

Methods: A Two-Stage Pipeline

PixelNN utilizes a clever two-stage pipeline to capture both global structure and local detail, getting the "best of both worlds."

Stage 1: Regression (The "Skeleton")

In the first stage, a CNN (specifically PixelNet) is trained to map the incomplete input to a smoothed, low-frequency RGB image.

Stage 1 Blurry Output

This stage successfully handles the global structure, layout, and color palette of the image, but it inherently lacks sharp, high-frequency details.

Stage 2: Compositional Matching (The "Skin")

To inject realistic textures and sharp edges, the system performs a pixel-wise nearest neighbor search. For every pixel in the smoothed Stage 1 image, the algorithm searches the training set to find a similar pixel in a similar context. It then "copy-pastes" the high-frequency detail from that training exemplar directly onto the final output.

The Key Innovation: Hypercolumns To ensure semantic accuracy—for instance, ensuring an "eye pixel" matches with another "eye pixel" rather than a "mouth pixel"—the authors utilize hypercolumn features. These are vectors of activations extracted from multiple layers of a pre-trained CNN. Hypercolumns provide a multi-scale descriptor that captures both local texture and global semantic context, ensuring highly accurate and context-aware pixel matches.

Key Insights and Capabilities

  • Compositionality is Power: By matching at the pixel level rather than the image level, the model can compose entirely new images. If a dataset has $N$ training images consisting of $K$ pixels, the number of potential unique compositions is $(NK)^K$. This is an astronomical increase in diversity compared to the linear $N$ matches available to traditional global nearest-neighbor methods.
  • Interpretability by Design: Because the model literally copies pixels from the training set, the generation process is entirely transparent. Users can trace any pixel in the generated image back to its exact source in the training data.
  • User Control: Users can "steer" the synthesis by pruning the training set. If a user wants to generate a cat that looks specifically like a "Maine Coon," they can restrict the nearest-neighbor search to that specific sub-category, providing a level of granular control that GANs lack.

Key Results

The authors evaluated PixelNN across several diverse domains, including human faces (CelebA), pets (Oxford-IIIT), shoes, and handbags. They compared PixelNN against Pix2Pix, a popular conditional GAN framework.

Diverse Handbag Generations
  • Overcoming Mode Collapse: While Pix2Pix often generated nearly identical images despite random noise inputs, PixelNN successfully generated dozens of distinct, plausible variations for a single input (as seen in the handbag edge-to-image generations above).
  • Quantitative Performance: Using an "Oracle" selection method (picking the best of the generated outputs), PixelNN outperformed Pix2Pix across multiple metrics, including Mean/Median angular error for surface normals and Average Precision (AP) for edge-to-RGB tasks.
  • Frequency Analysis: Fourier analysis demonstrated that PixelNN’s final outputs closely match the high-frequency spectrum of real, high-resolution images, successfully recovering the frequencies lost in the Stage 1 CNN output.

Limitations and Future Work

While highly effective, PixelNN has two primary limitations:

  1. Computational Speed: The pixel-wise search is significantly slower than a standard GAN forward pass. Currently, PixelNN runs at about 0.2 frames per second (fps) on a CPU. While GPU-based libraries like FAISS could accelerate this, it does not yet achieve the real-time performance of pure neural approaches.
  2. Database Dependency: The output quality is strictly bottlenecked by the training data. If the training set lacks a specific feature or "part" (e.g., a unique eye shape), the model may produce artifacts or fail to find a suitable nearest neighbor.

Future work will likely focus on system-level optimizations to make pixel-wise nearest-neighbor search competitive for real-time graphics applications.

Summary updated

BibTeX
@inproceedings{bansal2018pixelnn,
  author = {Aayush Bansal and Yaser Sheikh and Deva Ramanan},
  title = {{PixelNN: Example-based Image Synthesis}},
  booktitle = {International Conference on Learning Representations},
  year = {2018},
  url = {https://openreview.net/forum?id=Syhr6pxCW},
}
Figure