Inter-patch spatio-temporal relation prediction for video anomaly detection

Hao Shen, Lu Shi, Linna Zhang, Wanru Xu, Yigang Cen, Gaoyun An

Abstract

Video Anomaly Detection (VAD) is a critical task in computer vision, traditionally approached through frame reconstruction or prediction. However, these methods often suffer from over-generalization, where anomalous events are reconstructed too well to be detected. This paper presents Patch Spatio-Temporal Relation Prediction (PSTRP), a novel self-supervised framework that shifts the focus from pixel-level reconstruction to high-level structural coherence. By training a two-stream Vision Transformer (ViT) to solve a "spatio-temporal jigsaw puzzle"—predicting the original order and similarity of shuffled video patches—the model learns the complex logic of normal motion and appearance. Experimental results on UCSD Ped2, CUHK Avenue, and ShanghaiTech datasets demonstrate that PSTRP achieves state-of-the-art performance, effectively identifying anomalies when the learned structural logic is violated.

Introduction

The primary challenge in VAD is the lack of anomalous data during training, necessitating unsupervised or self-supervised approaches. Conventional generative models assume that anomalies will result in high reconstruction errors. Yet, deep neural networks' strong generalization capabilities often lead to low errors even for unseen anomalous patterns, resulting in false negatives. Furthermore, pixel-based methods frequently overlook the broader spatio-temporal context essential for distinguishing between normal and abnormal behaviors. To address these issues, we propose focusing on the structural relationships between video patches rather than their raw pixel values.

Methodology

The PSTRP framework operates in three distinct stages. First, it employs an object-level extraction phase using YOLOv3 to isolate Spatio-Temporal Cubes (STCs), which are 3D segments of video capturing object movement over time. Second, these STCs are processed by a two-stream Vision Transformer (ViT). One stream analyzes spatial patches to capture appearance within a frame, while the other examines temporal patches to understand motion across frames.

The PSTRP architecture featuring two-stream Vision Transformers for spatial and temporal patch relation prediction.

The core of the methodology lies in the self-supervised pretext tasks. The model is trained to solve two sub-problems:

  1. Order Prediction: Patches are shuffled, and the model must classify their original positions.
  2. Distance Constraint: To enhance the model's understanding of patch relationships, it must predict the similarity (distance) between patches using Canberra distance for spatial relations and Cosine distance for temporal relations.

This dual-task approach prevents the model from merely memorizing positions and encourages a deeper understanding of spatio-temporal coherence. During inference, if the model cannot accurately predict the order or similarity of patches in a new video, it assigns a high "anomaly score" to that frame.

Results and Evaluation

The proposed method was evaluated on three benchmark datasets: UCSD Ped2, CUHK Avenue, and ShanghaiTech Campus. PSTRP consistently outperformed or matched state-of-the-art methods across these benchmarks.

Comparison of PSTRP with existing VAD methods across three benchmark datasets.

On the CUHK Avenue dataset, PSTRP achieved a 92.5% AUROC, significantly surpassing previous self-supervised and generation-based approaches. For UCSD Ped2, it reached 98.7% AUROC, nearly perfecting the dataset. On the more challenging ShanghaiTech dataset, it achieved 80.4% AUROC, demonstrating robust performance even in complex, multi-scene environments.

Ablation studies confirmed the importance of the Distance Constraint module. Removing this component dropped performance by 1.3% to 2.1%, proving that understanding how patches relate is just as critical as knowing their positions.

Discussion and Conclusion

By decoupling patch relations into order and similarity, PSTRP effectively captures the high-level behavior of objects in video sequences. This approach makes the model resilient to low-level noise and lighting changes that often plague pixel-based methods. While the model shows exceptional results, performance on highly complex scenes like those in ShanghaiTech suggests that further scaling of the ViT backbone and exploring more diverse pretext tasks could yield even greater accuracy. PSTRP represents a significant step toward more robust and context-aware video anomaly detection.

Summary updated

BibTeX
@inproceedings{shen2024inter,
  author = {Hao Shen and Lu Shi and Linna Zhang and Wanru Xu and Yigang Cen and Gaoyun An},
  title = {{Inter-patch spatio-temporal relation prediction for video anomaly detection}},
  booktitle = {Research Square},
  year = {2024},
  doi = {10.21203/rs.3.rs-5329540/v1},
}

Loading related content...

Figure