# Innovative Approaches to Traffic Anomaly Detection and Classification Using AI
## 2 Algorithms and Methods
### Transformers  
Transformers, renowned for their ability to capture long-range dependencies in sequential data, have emerged as a powerful methodology for detecting traffic anomalies in surveillance videos. These models can learn complex traffic patterns and vehicle behaviors and identify anomalies such as accidents or traffic violations. To further enhance performance, some approaches integrate Transformers with architectures like U-Net. By leveraging the strengths of Transformers, traffic anomaly detection systems can achieve greater accuracy and effectiveness, contributing to improved road safety. The authors in [45] presented a method for anomaly detection in surveillance videos, using Transformers and an attention model to identify unusual events that deviate from normal patterns. To reduce reliance on frame-level labeling, the method employs a weakly supervised learning strategy, using video-level labels to generate frame-level anomaly scores. This is particularly advantageous in weakly supervised video anomaly detection (WSVAD), where distinguishing between normal and abnormal instances during training is challenging. Transformer-based video swin features are used for feature extraction, outperforming traditional CNN models such as I3D and C3D. An attention layer with dilated convolution and self-attenuation captures both long- and short-range temporal dependencies, enhancing the model's ability to identify anomalies accurately. For detecting anomalous segments, the robust temporal feature magnitude learning (RTFM) model is applied, using the L2 norm of temporal features to differentiate normal segments (low magnitudes) from anomalous ones (high magnitudes). The presented work was evaluated on the ShanghaiTech Campus dataset, and the obtained results showed that the method achieved competitive performance, as indicated by a high area under the curve (AUC) score compared to existing approaches. In [46], a three-stage framework was introduced to detect anomalies in traffic video sequences by combining spatio-temporal feature extraction, segment-level anomaly detection, and video-level anomaly detection, enhancing accuracy and reliability. In the first stage, spatio-temporal features are extracted using the ViViT neural network, a Transformer-based model effective in video analysis. ViViT leverages its attention mechanism to model long-term contextual information, addressing the limitations of traditional 3D convolution-based extractors. The pre-trained ViViT network produces \"class tokens\" for global segment features and \"patch tokens\" for local segment details. In the second stage, the extracted tokens are processed by two anomaly detectors. The segment-level detector analyzes \"class tokens\" using multi-instance learning with video-level labels, while the video-level detector assesses \"patch token\" similarities to identify abrupt changes or inconsistencies. The latter employs binary cross-entropy loss for training as a binary classification task. In the final stage, outputs from both detectors are fused to generate a composite anomaly score. This integration leverages the video-level detector's stability to correct potential errors from the segment-level detector, ensuring more reliable anomaly detection. The presented framework was validated using the TAD dataset, which includes diverse traffic anomalies, and the framework demonstrated significant improvements in detection and localization. Ablation studies confirmed the effectiveness of each stage and the robustness of the fusion strategy, validating this approach as a powerful tool for traffic video anomaly detection. In another work, presented in [47], the authors introduced CViT, an architecture that combines U-Net with vision Transformers (ViTs) to detect and localize anomalous behavior in videos, as illustrated in Figure 15. By integrating convolutional layers for local feature extraction with Transformer layers for capturing global relationships, CViT enhances the accuracy of anomaly detection in video sequences.