VMFormer: End-to-End Video Matting with Transformer

Jiachen Li, Vidit Goel, Marianna Ohanyan, Shant Navasardyan, Yunchao Wei, Humphrey Shi

TL;DR

VMFormer is the first end-to-end video matting framework built entirely on a vision transformer architecture. By leveraging learnable queries and a dual-track temporal modeling strategy, it achieves state-of-the-art accuracy and temporal consistency while maintaining real-time inference speeds of over 100 FPS.

What Problem Does This Paper Address?

Video matting—the process of precisely extracting a foreground element from a video sequence by calculating an "alpha matte"—is a fundamental task for video editing and conferencing. For years, Deep Convolutional Neural Networks (CNNs) have been the de-facto standard.

However, CNNs have two major drawbacks in this context:

  1. Locality Bias: CNNs are inherently local operators. They struggle to capture the global characteristics of an image, which is crucial for distinguishing foreground from background in complex or ambiguous scenes.
  2. Temporal Modeling Costs: Achieving temporal consistency (preventing flickering) usually requires modeling relationships across multiple frames. Doing this on high-resolution feature maps is computationally expensive, often forcing models to settle for very short-range temporal context.

VMFormer aims to solve these by replacing the CNN-heavy pipeline with a transformer-based approach that naturally handles global context and offers a more efficient way to model time.

Methods

The VMFormer architecture consists of two parallel branches that eventually converge to produce the final alpha matte.

Figure 1. An overview of the VMFormer. VMFormer has two branches for feature modeling and query modeling. The feature modeling branch takes video clips as input and extracts feature sequences through the backbone and the transformer encoder. The query modeling branch learns the global representation of feature sequences through the transformer decoder. Temporal modeling is applied to each branch individually to improve the temporal consistency of predictions. Finally, VMFormer makes predictions of alpha mattes with queries and feature maps. The detailed architecture of each branch is illustrated in Figure 2.

1. Feature Modeling Branch

This branch uses a lightweight CNN backbone (MobileNetV3) to extract initial feature pyramids, which are then fed into a Transformer Encoder. The encoder uses self-attention to build a global spatial representation of each frame. To handle short-range temporal dynamics, the authors introduce Short-range Feature-based Temporal Modeling (SFTM), which uses recurrent aggregation to share information between successive feature maps.

2. Query Modeling Branch

This is the heart of the "end-to-end" transformer approach. A set of learnable queries (one per frame) passes through a Transformer Decoder. These queries interact with the feature sequences via cross-attention, learning a global representation of the foreground.

To ensure the video doesn't flicker, the authors implement Long-range Query-based Temporal Modeling (LQTM). Because queries are much smaller than feature maps, the model can efficiently attend to all queries across a long sequence ($O(TC)$ complexity vs. the $O(THWC)$ complexity required for feature maps).

3. Prediction Stage

The final alpha matte is generated through a simple batch matrix multiplication between the refined queries and the high-resolution feature maps. This elegant "matching" process replaces complex CNN decoder heads.

Figure 2. The Architecture of the VMFormer. It contains two separate branches for modeling features and queries: a) The feature modeling path contains a CNN-based backbone network to extract feature pyramids and a transformer encoder that integrates feature se- quences globally with short-range feature-based temporal modeling (SFTM) on feature maps of successive frames. b) The query modeling path has a transformer decoder for queries to learn global representations of feature sequences. Long-range query-based temporal model- ing (LQTM) is built upon all queries with learnable temporal weights. The final alpha matte predictions are based on matrix multiplication between queries and feature maps. LayerNorm, residual connection, and repeated blocks are omitted for simplicity.

Datasets

The model was trained and evaluated using a mix of standard matting benchmarks:

  • Training: VideoMatte240K (foregrounds), ImageMatte (foregrounds), BG20K (backgrounds), and DVM (backgrounds).
  • Testing: The authors used a composited test set of 50 challenging clips and also evaluated on the benchmark used by Robust Video Matting (RVM).

Key Insights and Ideas

  • Queries as Global Proxies: By performing long-range temporal modeling on queries rather than feature maps, VMFormer achieves temporal consistency at a fraction of the computational cost.
  • Cross-Attention for Matching: The use of cross-attention to "match" learnable queries to image features provides a more flexible way to identify foreground pixels than static convolutional kernels.
  • Redundancy is a Feature: Visualization of the feature maps (Figure 4) shows that while many channels are "empty" (a common trait in Vision Transformers), the active channels provide highly specific, high-quality cues for alpha prediction.
  • Simplicity Wins: Unlike previous methods that required complex multi-stage training or auxiliary segmentation tasks, VMFormer is trained end-to-end with a standard combination of Focal, Dice, and Temporal losses.

Key Results

VMFormer consistently outperformed previous state-of-the-art CNN models like RVM and MODNet across multiple metrics (MAD, MSE, Gradient, and Connectivity).

  • Accuracy: On the 512x288 benchmark, VMFormer achieved a Mean Absolute Difference (MAD) of 4.91, significantly better than RVM (5.99) and BGMv2 (6.63).
  • Temporal Consistency: The model showed superior performance in the "Connectivity" metric, indicating much smoother transitions and less flickering.
  • Speed: Despite the transformer architecture, VMFormer reached 109.5 FPS on an NVIDIA RTX A6000, making it fully capable of real-time inference.
  • Qualitative: As seen in Figure 3, VMFormer is notably better at distinguishing foreground from background in cases of "color obfuscation" (where the person's clothes match the background).
Figure 3. Visualization of alpha matte predictions from MODNet, RVM, and VMFormer under challenging frames from the composited test set. VMFormer shows a better ability to distinguish ambiguous foreground from background regions as shown in the magnified image patches. Please zoom in for details.

Limitations and Future Work

  • Memory Constraints: Due to the memory-intensive nature of transformers, the model currently processes video in clips (e.g., $T=5$ for training, $T=20$ for inference). While LQTM helps, truly "infinite" long-range modeling remains a challenge.
  • Auxiliary Supervision: Interestingly, the authors found that standard transformer tricks like auxiliary supervision on intermediate layers didn't help much here. They hypothesize that predicting a single-channel alpha matte is "easier" for a transformer than multi-object detection, suggesting the architecture could be further streamlined.
  • Future Directions: The authors suggest exploring more efficient attention mechanisms to handle even higher resolutions and longer sequences natively.

Summary updated

Abstract

Video matting aims to predict the alpha mattes for each frame from a given input video sequence. Recent solutions to video matting have been dominated by deep convolutional neural networks (CNN) for the past few years, which have become the de-facto standard for both academia and industry. However, they have inbuilt inductive bias of locality and do not capture global characteristics of an image due to the CNN-based architectures. They also lack long-range temporal modeling considering computational costs when dealing with feature maps of multiple frames. In this paper, we propose VMFormer: a transformer-based end-to-end method for video matting. It makes predictions on alpha mattes of each frame from learnable queries given a video input sequence. Specifically, it leverages self-attention layers to build global integration of feature sequences with short-range temporal modeling on successive frames. We further apply queries to learn global representations through cross-attention in the transformer decoder with long-range temporal modeling upon all queries. In the prediction stage, both queries and corresponding feature maps are used to make the final prediction of alpha matte. Experiments show that VMFormer outperforms previous CNN-based video matting methods on the composited benchmarks. To our best knowledge, it is the first end-to-end video matting solution built upon a full vision transformer with predictions on the learnable queries. The project is open-sourced at https://chrisjuniorli.github.io/project/VMFormer/
BibTeX
@inproceedings{li2024vmformer,
  author = {Jiachen Li and Vidit Goel and Marianna Ohanyan and Shant Navasardyan and Yunchao Wei and Humphrey Shi},
  title = {{VMFormer: End-to-End Video Matting with Transformer}},
  booktitle = {IEEE/CVF Winter Conference on Applications of Computer Vision},
  year = {2024},
  url = {https://openreview.net/forum?id=tmgt5Ndksg},
}
Figure