Lightweight Portrait Matting via Regional Attention and Refinement

Yatao Zhong, Ilya Zharkov

TL;DR

This paper introduces a lightweight, two-stage framework for high-resolution portrait matting that operates without any auxiliary inputs like trimaps or background captures. By combining a Vision Transformer (ViT) backbone for coarse estimation with a novel Cross Region Attention (CRA) module for local refinement, the model achieves state-of-the-art quality while using only 1/20th of the computational cost (FLOPs) of previous leading models, enabling real-time HD and near real-time 4K performance.

What Problem Does This Paper Address?

Image matting—the process of precisely separating a foreground object from its background—is a classic "ill-posed" problem because a single pixel color is a mix of foreground and background ($I = \alpha F + (1-\alpha)B$). Traditionally, models require a "trimap" (a hand-drawn map of foreground, background, and unknown regions) or a pre-captured background image to solve this.

While "trimap-free" models exist, they face a steep trade-off:

  1. Computation: Processing 4K or HD images at full resolution is incredibly heavy.
  2. Context vs. Detail: Downsampling an image to save power loses the fine details (like hair strands) essential for matting. Conversely, looking only at local patches (refinement) loses the global context needed to tell a person apart from a similarly colored background.

The authors aim to bridge this gap, providing a model that is both "automatic" (no trimaps) and "efficient" (runs on consumer GPUs at high resolutions).

Methods

The authors propose a two-stage "coarse-to-fine" architecture:

  1. Low-Resolution Stage (Coarse Alpha): The model uses a Swin Transformer (ViT) backbone. A key insight here is the use of pixel-unshuffle (tokenization). Unlike standard downsampling, which discards pixels, tokenization reshapes the image into patches, preserving all original pixel information in the channel dimension. This allows the model to estimate a "coarse" alpha matte and a "predicted trimap" efficiently.
  2. Refinement Stage (Fine Alpha): The model identifies "uncertain" regions from the coarse stage and crops them into $8 \times 8$ patches for high-resolution processing.
  3. Cross Region Attention (CRA): To solve the "lost context" problem inherent in cropping, the authors developed the CRA module. It uses a K-Nearest Neighbors (KNN) approach to allow each local patch to "talk" to its neighbors. By using a learnable lookup table for relative positional bias, the model understands where patches are located relative to each other, allowing it to propagate contextual information across the image without needing to process the entire high-res frame through a heavy global network.

Datasets

The model was trained and evaluated on:

  • P3M-10k: Currently the largest human portrait matting dataset, containing over 10,000 high-resolution images with blurred faces for privacy.
  • PPM-100: A smaller, high-quality benchmark dataset used to test the model's ability to generalize to different imaging conditions and resolutions.

Key Insights and Ideas

  • ViT vs. CNN for Downsampling: The authors found that standard CNNs struggle with "pixel-unshuffled" data because the effective kernel size becomes too large, breaking the CNN's ability to generalize. ViTs, which are designed to handle tokens, are naturally better suited for this high-channel, low-spatial-resolution input.
  • Inverting the Context Order: Instead of upsampling heavy feature maps (which is memory-intensive), the authors "invert" the process: they extract local regions first and then use the CRA module to "gather" context back from the neighbors.
  • Efficiency is King: By focusing on only the "uncertain" pixels (the boundaries of the portrait), the model avoids wasting computation on the solid foreground and background areas.

Key Results

  • Computational Efficiency: The model uses only 19 GFLOPs, compared to 364.9 GFLOPs for P3M-Net, representing a nearly 20x reduction in complexity.
  • Speed: On an Nvidia RTX 6000 GPU, the model achieves 54.9 FPS for HD and 19.5 FPS for 4K video.
  • Accuracy: Despite the lower footprint, it outperforms or matches much heavier models (like MODNet and BGMv2) on the P3M and PPM benchmarks, particularly in "Connectivity" and "Gradient" errors, which measure how natural the matte looks to the human eye.

Limitations and Future Work

  • Texture Confusion: The refinement network can still struggle with extremely high-contrast textures in the background that mimic foreground details.
  • Error Propagation: Because it is a two-stage model, if the first stage completely misses a part of the person (e.g., a hand or an accessory), the refinement stage cannot "undo" that mistake, as it only looks at regions the first stage marked as uncertain.
  • Future Directions: The authors suggest that training the coarse and refinement stages on even larger, more diverse datasets (including synthetic data) could further improve robustness in complex real-world environments.

Summary updated

BibTeX
@inproceedings{zhong2024lightweight,
  author = {Yatao Zhong and Ilya Zharkov},
  title = {{Lightweight Portrait Matting via Regional Attention and Refinement}},
  booktitle = {IEEE/CVF Winter Conference on Applications of Computer Vision},
  year = {2024},
  doi = {10.1109/wacv57701.2024.00411},
}
Figure