{'fraction_non_alphanumeric': 0.035122633390705676, 'fraction_numerical': 0.014898881239242686, 'mean_word_length': 4.878280113815998, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Synthetic Temporal Anomaly Guided End-to-End Video Anomaly Detection

Due to the limited availability of anomaly examples, video anomaly detection is often seen as one-class classification (OCC) problem. A popular way to tackle this problem is by utilizing an autoencoder (AE) trained only on normal data. At test time, the AE is then expected to reconstruct the normal input well while reconstructing the anomalies poorly. However, several studies show that, even with normal data only training, AEs can often start reconstructing anomalies as well which depletes their anomaly detection performance. To mitigate this, we propose a temporal pseudo anomaly synthesizer that generates fake-anomalies using only normal data. An AE is then trained to maximize the reconstruction loss on pseudo anomalies while minimizing this loss on normal data. This way, the AE is encouraged to produce distinguishable reconstructions for normal and anomalous frames. Extensive experiments and analysis on three challenging video anomaly datasets demonstrate the effectiveness of our approach to improve the basic AEs in achieving superiority against several existing state-of-the-art models.


Introduction
Anomaly detection in video sequences has recently attracted significant attention because of its importance in surveillance systems [37,41,18,4,16,21,19,1,46]. As anomalous events occur rarely in real-life situations and collecting plenty of anomalous examples can be cumbersome, this task is extremely challenging. Therefore, anomaly detection is often seen as one-class classification (OCC) problem in which only normal data is used to train a novelty detection model [7,18,4,35,39,17,14]. At test time, the events that do not conform to the learned representations are considered anomalous.
One common way to tackle the OCC problem is by using a deep autoencoder (AE) [8,45,39,4,21,29,20,35,7]. By training to minimize reconstruction error on normal data, the model is encouraged to extract the features represent-ing normal data in its latent space. This way, at test time, the network is expected to poorly reconstruct the anomalous cases. However, as previously observed by several researchers [47,26,39], AEs can also often successfully reconstruct anomalous examples. In such cases, the reconstruction loss between normal and anomalous data may not be discriminative enough to successfully identify the anomalies.
Recently, a new addition to the field of OCC is the idea of utilizing pseudo anomalies generated from the normal training data. For example, Zaheer et al. [39] fuse two random images from normal data to generate appearance anomalies and use them to train an image classifier. However, this work needs old and new states of the reconstructor and trains in a two-phase scheme. Furthermore, the approach is limited to appearance and does not consider any temporal information for anomaly detection. On the contrary, our work proposes a simple yet highly effective temporal pseudo anomaly synthesizer to assist the training of an AE in an end-to-end fashion without any bells and whistles. For each pseudo anomaly example as input, our AE model is trained to produce high reconstruction loss. This helps in limiting the capability of AE to reconstruct anomalies at test time.
We owe the inspiration of our approach to the intuition that detecting fast or suddenly changing motion is significantly important and closely related to detecting anomalies. For example, it is a common observation that animals often associate strong motion with dangerous situations [6]. The case is similar for humans as well. For instance, people running unusually may indicate life-threatening situations nearby, such as fires [11,5] or natural disasters [9,15]. Moreover, fights or robberies may also be characterized by sudden strong motions. Some other examples may include riding bikes or vehicles on pedestrian sidewalks, overspeeding vehicles, etc. [2,36,27]. Therefore, we hypothesize that most of the anomalous events can be characterized by the motion depicted.
To this end, we propose a temporal pseudo anomaly synthesizer that injects synthesized anomaly examples into the  Figure 1. Visualization of normal, anomalous, and pseudo anomalous frames. Given red lines as reference, (a) shows a normal movement pattern in which humans are walking in a usual pace. (b) shows an anomalous movement, i.e. the anomalous object almost completely crosses the reference line within few frames. (c) shows the output of our pseudo anomaly synthesizer generated from normal frames which mimics anomalous movements.
training of an AE. To simulate anomalous movements from normal data, we arbitrarily skip few frames to generate pseudo anomaly sequences as shown in Fig. 1. The overall training is then carried out to minimize the reconstruction loss of normal data while maximizing the reconstruction loss of synthesized anomaly data. Note that, unlike existing motion tracking based anomaly detection methods [3,32,43,24], our approach does not extract any handpicked motion information. Rather, by complementing a temporal pseudo anomaly synthesizer with a deep AE, we harness the power of deep learning to detect a variety of anomalous activities inside videos. Our extensive experiments and analysis demonstrate the superior capability of our approach in three challenging anomaly detection datasets, i.e. Ped2 [16], Avenue [19], and ShanghaiTech [21].

Related Work
Since it is not easy to obtain anomaly examples [31], a popular approach for anomaly detection is one-class classification (OCC) in which the training is carried out using only normal data. Several works train a one-class classifier using the features extracted through object trackers [3,24,32,43]. However, such handpicked features can of-ten limit the generalization capability of the network on different kinds of activities.
Several attempts have been made to limit the reconstruction capability of an AE on anomalous data. Memory-based networks [7,29] employ a memory mechanism over the latent space between the encoder and the decoder of an AE. The network is restricted to use only the memorized normalcy definitions which limits its capability to reconstruct anomalous data. However, such networks are highly dependent on the memory size and a small-sized memory may also limit their normal data reconstruction capability. In our approach, we also attempt to limit the reconstruction capability of an AE on anomalous inputs. However, instead of using a memory network, we utilize a pseudo anomaly synthesizer to generate fake anomaly examples and encourage the AE to produce high reconstruction loss on these examples.
The most related to our work is OGNet [39], which fuses normal images to generate appearance anomalies and train the network using both normal and fake anomaly examples. Moreover, OGNet requires a two-phase adversarial training scheme in which a discriminator is trained based on two previously frozen generator models. On the other hand, our approach of synthesizing anomalies is substantially different. We propose to utilize temporal information rather than appearance to synthesize anomalies. Moreover, our method is end-to-end trainable and complements the conventional training of an AE.
In order to enhance the discrimination of normal and anomalous data, some researchers [26,38,41,40,46,42,37] propose to deviate from the fundamental definition of OCC by using real anomaly examples during training. Our method on the other hand utilizes only normal data to synthesize pseudo anomaly examples for training, thus following the conventional OCC protocol.

Methodology
In this section, we present our proposed STEAL (Synthetic TEmporal AnomaLy guided end-to-end video anomaly detection) network. Due to the unavailability of  anomalous examples during training, most of the AE based anomaly detection approaches often fail to discriminate anomalies from normal data at test time. Therefore, we propose the utilization of fake anomaly examples, that are generated by our pseudo anomaly synthesizer using only normal training videos, to enhance the performance of AEs.

Architecture
Our overall architecture is shown in Fig. 2. We train a conventional AE as our baseline, which takes a sequence of normal frames as input and produces its reconstruction as output. To complement the baseline training, we propose a pseudo anomaly synthesizer that generates fake anomaly examples. These examples are then used for training with a probability p. This way, we limit the reconstruction capability of the AE by forcing it to increase the reconstruction loss on these fake anomaly examples. Finally, the anomaly score is computed using the frame-level reconstruction loss. Each component of our architecture is discussed next:

Autoencoder
In order to capture robust representations, autoencoders (AE) are often designed to take multi-frame inputs [7,29,8,45]. Therefore, we set our AE model to take X as input of size T × C × H × W , where T , C, H, and W are the number of frames in the input sequence, number of channels, height of frames, and width of frames, respectively. The reconstructionX is then given as: where E and D are the encoder and the decoder of our model, respectively.
Conventionally, an AE is trained to reconstruct using only normal data in the training set. At test time, it is expected to well reconstruct the normal data while poorly reconstruct the anomalous examples. However, this is not always the case. AEs can often "generalize" too well and reconstruct anomalous examples as well [47,26,39]. As there are no anomaly examples utilized in the training time, it can be difficult to train a reconstruction based anomaly detection model [39]. To mitigate this problem, we propose a pseudo anomaly synthesizer that can provide fake anomaly examples. These examples are then used to restrain the generation capability of the AE and encourage it to produce high reconstruction loss on any kind of anomalous inputs.
During training, a sequence of video frames X is given to the network as: where X P is a sequence of frames generated using our proposed pseudo anomaly synthesizer, X N is a sequence of frames from normal training data, and p is the probability that defines the ratio of pseudo anomaly examples used. Note that the pseudo anomalies are only introduced during training. At test time, we simply input the original sequence of video frames to AE.

Temporal Pseudo Anomaly Synthesizer
In our proposed approach, we follow the OCC protocols by utilizing only normal data to carry out the training. Therefore, in order to generate temporal pseudo anomalies, we utilize the normal training videos only. Similar to the common practices in training a conventional AE [8,29], we extract sequences of frames X N from a training video V i = {I 1 , I 2 , ..., I Ki } of length K i frames by randomly selecting a frame index n from V i and then taking a fixed number of consecutive T frames thereafter, as described: On the other hand, pseudo anomalies X P are synthesized by introducing a skip frame parameter s to Eq. (3) as: X P = (I n , I n+s , ..., I n+(T −1)s ) = (I n+ts ) 0≤t<T,n+(T −1)s≤Ki,s>1 .
The skip frame parameter s controls the number of frames we skip to generate temporal pseudo anomaly examples. An example pseudo anomaly sequence with s = 2 is visualized in Fig. 1(c).

Training
In order to learn normal representations, a conventional AE is trained on X N by minimizing reconstruction loss between the input frame I n+t and its reconstructionÎ n+t as follows: where ∥.∥ F means Frobenius norm. For X P generated by our temporal pseudo anomaly synthesizer, the loss can be similarly defined as: Note the negative sign in Eq. (6), which is introduced to increase the reconstruction loss of pseudo anomaly examples. This helps in limiting the reconstruction capability of our AE on anomalous inputs.
Then, the overall loss L for training takes the form:

Anomaly Score
At test time, concurrent to the existing approaches [7,29,18,8,45,39,41], we predict anomaly scores at frame level. Moreover, we compute these scores by utilizing the reconstruction based Peak Signal to Noise Ratio (PSNR). According to Mathieu et al. [23], PSNR is often a better assessment of image quality than the reconstruction loss itself. Recently, it has also been utilized in anomaly detection [29,18] where PSNR between an input frame and its reconstruction is used to calculate the anomaly score. In our approach, we compute PSNR P t as: where R is the total number of pixels inÎ t , t is the frame index, and MÎ t is the maximum possible value ofÎ t . Then, following [29,18], we normalize the PSNR value to the range of [0, 1] by a min-max normalization over all the frames in a test video V i as follows: where t is the frame index of V i . In Eq. (9), a higher Q t represents lower reconstruction loss compared to the other frames in V i and vice versa. Therefore, we calculate the final anomaly score A t as: 4. Experiments

Datasets
We evaluate our approach on three widely popular video anomaly detection datasets, i.e. Ped2 [16], Avenue [19], and ShanghaiTech [21]. We utilize the standard division of the datasets in which training splits consist of only normal videos. Whereas, every video in each of the test sets contains one or more anomalous portions. Ped2. This dataset consists of 16 training and 12 test videos [16]. Pedestrians dominate most of the normal frames whereas anomalies include bikes, carts, or skateboards. Avenue. This dataset contains 16 training and 21 test videos [19]. Anomalies include abnormal objects such as bikes and abnormal actions of humans such as unusual walking directions, running, or throwing stuff. ShanghaiTech. This is by far the largest one-class anomaly detection dataset [21]. It consists of 330 training and 107 test videos. The dataset is recorded at 13 different locations having complex lighting conditions and camera angles. In total, the test videos contain 130 anomalous events including running, riding bicycle, and fighting.
Parameters and implementation details. We adopt a generative architecture recently proposed by Gong et al. [7] as our baseline that takes an input sequence X (Eq. (1)) of size 16 × 1 × 256 × 256 and produces its reconstruction of the same size. All 16 frames are used for computing the reconstruction loss during training (Eq. (5) - (6)). At test time, following [7], only 9th frame out of the 16 frames is considered for anomaly score calculation (Eq. (8) -(10)). However, differently from the original implementation, we remove the memory network and utilize only the autoencoder part. Furthermore, we add Tanh output layer to have the output range of [−1, 1].
The implementation of STEAL Net and the baseline is done in PyTorch [30]. The training is carried out using Adam [13] with a learning rate of 10 −4 and the batch size is set to 4. The skip frame parameter s in Eq. (4) is set to {2, 3, 4, 5}, which means s can be randomly selected as 2, 3, 4, 5 each time we generate a pseudo anomaly sequence. The probability p for pseudo anomaly in Eq. (2) is set to 0.01. The baseline in our results refer to the model trained without pseudo anomalies, i.e. the probability p in Eq. (2) is set to 0. Table 1 shows the AUC comparisons of our proposed STEAL Net on Ped2 [16], Avenue [19], and ShanghaiTech [21] datasets. Our approach yields better performance than the baseline on all three datasets. Specifically, our approach demonstrates an absolute gain of 5.9%, 5.6%, and 2.4% AUC on Ped2, Avenue, and ShanghaiTech datasets respectively. This shows that our approach successfully improves the capability of the baselines on several diverse datasets.

Quantitative Results
Comparing the performance with existing approaches, we achieve superior performances on all three datasets. Although MNAD-Prediction [29] achieves better performance on Avenue compared to our method, its superiority may be attributed to different base architecture as well as training settings, i.e., prediction task. Nevertheless, compared with MNAD-Reconstruction, which has a similar base architecture as ours and performs the same task of reconstruction, our model yields noticeably better performance, thus demonstrating the superiority of our approach.
Overall, the superior performance of STEAL Net validates our hypothesis that several different kinds of anomalies may be characterized by the motions present within. Therefore, by utilizing a temporal pseudo anomaly synthesizer, we unleash the potential of a deep autoencoder for more accurate anomaly detection.

Qualitative Results
Input images and the comparisons of their reconstructions produced by STEAL Net and the baseline are shown in the first three columns of Fig. 3. In addition, reconstruc- Table 1. AUC performance comparison of our approach with several SOTA methods on Ped2, Avenue (Ave), and ShanghaiTech (Sh). Best performances in each dataset are highlighted as bold whereas second best are highlighted as underlined.
Anomaly ground truths are marked as red boxes.
tion error heat maps are visualized in the last two columns. These heat maps are generated by computing the squared error of each pixel between the reconstruction and the input frame followed by min-max normalization. As our approach is specifically trained to produce high reconstruction loss on anomalous inputs, it consequently attempts to satisfy this condition by distorting the anomalous regions.
On the other hand, concurrent with the reports in several research works [47,26,39], the baseline reconstructs the anomalies well, thus often failing to produce noticeable discrimination.

Conclusion
We proposed the utilization of pseudo anomalies, that are generated using only normal data, to assist the training of an autoencoder (AE) for video anomaly detection. In addition to the conventional training of AEs where a network only attempts to minimize reconstruction error on inputs, we further encourage the network to maximize this loss on pseudo anomalies. The effectiveness of our approach in complementing the AEs to achieve superiority against several existing state-of-the-art models is extensively analyzed on three challenging video anomaly datasets.

Acknowledgements
This work was supported by the ICT R&D program of MSIT/IITP. [2019-0-01309, Development of AI Technology for Guidance of a Mobile Robot to its Goal with Uncertain Maps in Indoor/Outdoor Environments]. Also, we thank Ki-In Na and Jae-Yeong Lee for the discussions and support in improving our work.