# Innovative Approaches to Traffic Anomaly Detection and Classification Using AI
## 2 Algorithms and Methods
### Generative Adversarial Networks (GANs)
Experiments on the UCSD Ped1 and Ped2 [37] and Avenue [38] datasets demonstrate STANs' competitive performance, particularly in complex scenes with large objects and frequent occlusions. Visualization techniques further enhance interpretability by highlighting regions containing anomalies, as depicted in Figure 13.  
The work presented in [43] proposes another GAN-based video anomaly detection method but with a dual discriminator. The main contribution lies in introducing a second discriminator specifically designed to analyze motion information, enhancing temporal continuity in predictions. During training, the GAN generator learns to predict the next frame in video sequences using a dataset of normal events. The generator's loss function combines intensity, gradient, motion, and adversarial losses to produce realistic frames. The motion discriminator examines optical flow between frames, ensuring smooth and consistent temporal transitions. While in testing, the generator predicts frames, and the peak signal-to-noise ratio (PSNR) is used to measure the prediction quality. Frames with low PSNR values are flagged as anomalous, with regularity scores calculated for classification. The method was evaluated on the UCSD Ped2, CUHK Avenue, and ShanghaiTech datasets. The results show that the dual-discriminator GAN performs comparably or better than state-of-the-art methods, particularly excelling on the ShanghaiTech dataset due to its ability to handle complex motion scenarios. Figure 12: Training pipeline of spatio-temporal adversarial networks (STANs). The input frame sequence is first encoded by a spatial encoder to extract semantic features. These features are processed by a forward ConvLSTM and a combined ConvLSTM to model short- and long-term temporal dependencies. The output is decoded by a spatial decoder to generate the predicted frame. A spatio-temporal discriminator distinguishes between real and generated sequences to enforce realistic spatial structure and temporal consistency. From [42]. TransAnomaly [44] introduces a novel method for video anomaly detection by integrating the U-Net architecture with the Video Vision Transformer (ViViT), as shown in Figure 14. This approach effectively leverages Transformers' ability to model temporal sequences and global video context, addressing the challenge of detecting rare and unpredictable events. Using a frame prediction-based strategy, TransAnomaly predicts the next frame in a video sequence. While normal frames are accurately predicted, anomalous frames result in higher prediction errors. ViViT enhances temporal and global context modeling, outperforming traditional CNN-based approaches. Integrated with U-Net, the model improves predictions of appearance and motion details. The optimization process involves intensity, gradient, and difference loss functions to ensure accurate visual and motion predictions. A patch discriminator enhances the realism of frames during adversarial training. Anomalies are detected by calculating the PSNR between predicted and actual frames, with lower PSNR values indicating anomalies. To reduce noise, a sliding window approach calculates the PSNR in relevant frame regions. Figure 14: The framework of the model. From [44]. Figure 13: Localization and visualization results of the abnormal events on UCSD Ped1 (first row), UCSD Ped2 (second row), and Avenue (third row). (**a**) Real frame, (**b**) generated frame, (**c**) abnormality visualization by the generator, and (**d**) abnormality visualization by the discriminator. From [42]. Evaluated on the CUHK Avenue and UCSD Pedestrian datasets, TransAnomaly demonstrated better performance. The work emphasized the importance of optimizing Transformer encoder depth and loss functions to maximize accuracy. Additionally, visualizations highlighted the model's capability to localize anomalies effectively within frames.