Masking Strategies for Background Bias Removal in Computer Vision Models

Ananthu Aniraj, Cassio F. Dantas, Dino Ienco, Diego Marcos

TL;DR

This paper investigates how to stop computer vision models from "cheating" by using background cues (like a forest or ocean) to identify objects (like specific bird species). By comparing early masking (at the image level) and late masking (at the feature level) across CNNs and Vision Transformers (ViTs), the authors find that early masking consistently provides the best robustness against out-of-distribution backgrounds, with ViTs emerging as the superior architecture for this task.

What Problem Does This Paper Address?

In fine-grained image classification—tasks where you need to distinguish between very similar categories, such as different species of sparrows—models often fall into a trap called background bias. Because certain objects are frequently found in specific environments (e.g., waterbirds on water), deep learning models often learn to associate the background with the label rather than focusing on the object itself.

Figure 1: Background bias in fine-grained classification

This leads to a "shortcut learning" problem: the model performs great on your training data but fails miserably when deployed in the real world on new, Out-of-Distribution (OOD) backgrounds. The authors set out to determine the most effective way to force models to ignore these environmental cues and focus strictly on the foreground object.

Methods

The researchers explored two primary strategies for removing background information, illustrated in Figure 2:

  1. Early Masking: The background is removed at the input stage. A segmentation network generates a foreground-background (FG-BG) mask, and the background pixels are set to zero (blacked out) before the image ever reaches the classification model.
  2. Late Masking: The model processes the full image, but the high-level spatial feature maps are masked at an intermediate stage. This allows the model to potentially use some context for feature extraction but prevents that context from reaching the final classification head.
Figure 2: Early and late masking strategies

They tested these strategies using two modern backbones: ConvNeXt (a state-of-the-art CNN) and Vision Transformers (ViT). They also experimented with different ViT classification inputs, comparing the standard [CLS] token against Global Average Pooled (GAP) patch tokens.

Datasets

  • CUB-200-2011: The primary dataset for training and in-distribution testing, containing 200 bird species.
  • Waterbirds: An OOD test set specifically designed to measure background bias. It takes birds from the CUB dataset and synthetically places them on backgrounds from the Places dataset (e.g., a land bird placed on a water background).
  • ADE20k: Used to pre-train the Mask2Former segmentation model, which was then fine-tuned on CUB to generate the FG-BG masks.

Key Insights and Ideas

  • Early Masking is King: Across almost all tests, masking at the image level (Early Masking) outperformed masking at the feature level. By never showing the model the background, the authors effectively prevented the backbone from ever learning spurious correlations.
  • ViTs are More Robust to "The Void": CNNs showed a significant performance drop on the original CUB dataset when early masking was applied, likely because the sharp edges of the black mask conflict with the CNN's inductive bias for local spatial patterns. ViTs, which lack these rigid biases, handled the masked images much better.
  • The Power of Patch Tokens: For ViTs, using the Global Average Pooled (GAP) patch tokens for classification—rather than the traditional [CLS] token—yielded the highest OOD robustness. This suggests that patch-based representations are better at isolating foreground features when combined with masking.
  • Fine-tuning Risks: Interestingly, fine-tuning a ViT on unmasked data can actually decrease its OOD robustness, as the model uses the extra training time to "overfit" to the background correlations present in the training set.

Key Results

The quantitative results highlight a clear win for masking when dealing with OOD data. As shown in the extracted results (Figure 5), for a ConvNeXt-B model, OOD performance on the Waterbirds dataset jumped from 65.96% (Baseline) to 80.10% with early masking.

For ViT-B, the improvement was even more pronounced. When using GAP-Pooled patch tokens and early masking, the model achieved the highest OOD robustness of all tested configurations. Specifically, Table 4 (Figure 6) shows that fine-tuning an early-masked ViT-B reached 88.81% accuracy on OOD Waterbirds, compared to just 68.36% for the unmasked baseline.

Figure 5: Results showing that Early Masking consistently improves OOD performance on the Waterbird dataset compared to the Baseline.

Limitations and Future Work

While effective, the authors acknowledge several hurdles:

  • Segmentation Dependency: The method relies on having high-quality foreground-background masks. In many real-world scenarios, ground-truth masks aren't available, and training a segmentation model adds significant computational overhead.
  • Dataset Scope: The study was primarily limited to the CUB bird dataset. Testing on larger, more diverse datasets is necessary to confirm these findings generalize across all types of object-centric tasks.
  • Integration: Future work could look into "seamless" background suppression—integrating the masking logic directly into the training objective rather than requiring a separate pre-processing segmentation step.

Summary updated

BibTeX
@inproceedings{aniraj2023masking,
  author = {Ananthu Aniraj and Cassio F. Dantas and Dino Ienco and Diego Marcos},
  title = {{Masking Strategies for Background Bias Removal in Computer Vision Models}},
  booktitle = {Workshops @ ICCV},
  year = {2023},
}
Figure