Detect Any Shadow: Segment Anything for Video Shadow Detection

Yonghui Wang, Wengang Zhou, Yunyao Mao, Houqiang Li

TL;DR

ShadowSAM adapts Meta’s Segment Anything Model (SAM) for the specialized task of video shadow detection by fine-tuning its mask decoder to recognize shadows rather than ignore them. By using SAM to generate a robust "shadow prior" from the first frame and propagating it through a long short-term attention network, the authors achieve state-of-the-art accuracy and significantly faster inference speeds than previous methods.

What Problem Does This Paper Address?

Shadows provide critical cues for scene understanding, such as light direction and object geometry, but detecting them in video is notoriously difficult. Shadows are not "objects" in the traditional sense; they undergo significant deformation and lack the regular shapes that typical trackers rely on.

While foundation models like the Segment Anything Model (SAM) have revolutionized general segmentation, they have a blind spot: they are trained to segment objects and typically treat shadows as part of the background. Furthermore, existing video shadow detection (VSD) methods often struggle with temporal consistency or require looking at multiple future frames to make a prediction, which hampers real-time performance. The authors aim to bridge the gap between SAM’s powerful feature representation and the specific requirements of dynamic shadow detection.

Methods

The proposed framework, ShadowSAM, consists of two main stages:

  1. ShadowSAM (Fine-tuned SAM): The authors found that SAM’s heavy image encoder already extracts excellent representations. To make SAM "shadow-aware," they froze the encoder and prompt encoder, fine-tuning only the lightweight mask decoder (~4M parameters). During inference, a user (or a simulation) provides bounding boxes for shadows in the first frame, and ShadowSAM generates a high-quality "shadow prior" mask.
  2. Long Short-Term Network (LSTN): This network propagates the shadow information across the video. It uses a synergistic attention mechanism:
  3. Self-Attention: Captures internal correlations within the current frame.
  4. Long-Term Attention: Links the current frame back to the first frame (the prior) to prevent "error drift" over time.
  5. Short-Term Attention: Aggregates features from the immediate previous frame to ensure smooth, continuous transitions.
An overview of the proposed ShadowSAM architecture.

Datasets

  • ViSha: The primary benchmark for VSD, containing 120 videos with pixel-level shadow masks. The model was trained on 50 videos and tested on 70.
  • VISAD: A separate dataset used to evaluate the model's generalization ability in new environments without further training.
  • SA-1B & ImageNet: Used for the initial pre-training of the SAM components and the LSTN backbone (MobileNetV2), respectively.

Key Insights and Ideas

  • Foundation Models Need Nudging: SAM’s failure to detect shadows isn't a lack of "intelligence" but a result of its training objective. Fine-tuning just the decoder is a computationally efficient way to repurpose a massive foundation model for a niche task.
  • The Power of the Prior: By treating the first frame's shadow mask as a "prior" (similar to Video Object Segmentation), the network has a clear target to track, which simplifies the learning process compared to methods that try to detect shadows from scratch in every frame.
  • Efficiency through Architecture: Unlike previous SOTA methods (like TVSD) that require five subsequent frames to predict the current one, ShadowSAM only needs the first and the previous frame. This reduces the computational overhead significantly.
Visual comparison showing that original SAM ignores shadows while ShadowSAM captures them accurately.

Key Results

  • State-of-the-Art Performance: On the ViSha dataset, ShadowSAM achieved a Mean Absolute Error (MAE) of 0.020 and an Intersection over Union (IoU) of 0.693, outperforming the previous best methods (MAE 0.029, IoU 0.640).
  • Superior Speed: The total inference time for the test set was only 8.8 minutes on a single NVIDIA 3090Ti. For context, the previous fastest method took 9.2 minutes on a more powerful A100 GPU.
  • Robust Generalization: When tested on the VISAD dataset, ShadowSAM maintained its lead, proving it isn't just "memorizing" the ViSha training set but has learned a generalizable concept of what a shadow looks like in motion.

Limitations and Future Work

The authors identify a specific failure mode: abundant and densely distributed small objects. When a scene contains more than eight small shadows, the system defaults to a single large bounding box encompassing all of them. This coarse prompt can lead to imprecise initial masks and subsequent errors in the propagation network.

Future work will focus on:

  1. Improving the fine-tuning strategy to allow SAM to detect shadows without requiring user-provided bounding boxes.
  2. Enhancing the propagation strategy to better handle complex, multi-shadow scenes.

Summary updated

BibTeX
@article{wang2024detect,
  author = {Yonghui Wang and Wengang Zhou and Yunyao Mao and Houqiang Li},
  title = {{Detect Any Shadow: Segment Anything for Video Shadow Detection}},
  journal = {IEEE Trans. Circuits Syst. Video Technol.},
  year = {2024},
  url = {https://openreview.net/forum?id=1DzdhtSaV2},
}
Figure