## 4 Methodology
### Model Operation
#### 4.2.2 Spatiotemporal Relation Attention Model  
Current attention-based techniques use global average pooling to help the model gather global information. However, the spatiotemporal connections among objects are more significant for video anomaly identification than the information in a layer's channels [28]. Accordingly, we used the STR attention block, as shown in Figure 4, to capture  
Figure 3: Example of features map obtained using ViT. the spatiotemporal interconnections among objects in the video frames. In contradistinction to the framework proposed by [PERSON] et al. [28], the ViT transformer was adopted as the encoder part of the proposed model to capture the global context between the image patches instead of using CNN modules, which enable the model to obtain both global image context features and spatiotemporal relationships between objects to enhance the process of video anomaly detection. The STR attention block uses both temporal and spatial attention to identify complex correlations in video data. The spatial attention is attained by using convolutional layers and pooling techniques (with kernel sizes of H \(\times\) 1 and 1 \(\times\) W) to aggregate information along horizontal and vertical axes. The spatial attention scores are then generated by concatenating the obtained features and passing them through a shared convolutional layer to emphasize important spatial components. The temporal attention is performed through temporal pooling and convolutional processes to find relationships between frames and produce the temporal attention scores. Furthermore, a spatiotemporal attention map is created by combining these spatial and temporal scores, weighting the initial feature maps to increase attention to areas with important spatiotemporal correlations. According to [PERSON] et al. [28], the introduced attention method combines temporal and spatial information to obtain the spatiotemporal relationship information, which allows it to extract and aggregate dimensional components independently. The STR attention architecture consists of input processing, dimensional feature encoding, feature aggregation, an attention mechanism, and attention weighted output. The operation details are as follows:  
A one-to-one dimensional feature encoding procedure uses two pooling kernels with spatial sizes of (H,1) and (W,1) to encode each channel  
Then, the features of the video frame sequence at the time t are derived from every channel feature in the following manner:  
\[Y_{t}(X)=F^{3\times 3}\sigma\big{(}F^{1\times 1}(X)\big{)},\ X\in\ \mathbb{R}^{C/r \times(H+W)} \tag{3}\]  
where the normalization process is represented by \(\sigma\) and the convolution operation is represented by \(F\). The convolution kernel sizes are represented by \(3\times 3\) and \(1\times 1\), while the reduction ratio that regulates the change in the number of channels is denoted by r. A collection of spatiotemporal-aware feature mappings is produced by aggregating the outputs of the three transformations mentioned above along each of the three dimensions. The aggregation process is performed firstly by concatenating feature maps obtained from Equations (1) and (2) as follows:  
\[Y^{hw}=\delta\big{(}F^{1\times 1}\big{[}Y^{h},Y^{w}\big{]}\big{)} \tag{4}\]  
where [..] represents the concatenation of two tensors, \(F^{1\times 1}\) indicates the convolutional transformation through a convolutional kernel of size \(1\times 1\), and d represents the nonlinear activation function. Then, the output Y is split into two tensors with the same dimension, i.e., \(Y^{h}\in\mathbb{R}^{C/r\times H}\) and \(Y^{w}\in\mathbb{R}^{C/r\times W}\). After that, the spatial and temporal attentions are obtained by applying the activation function to each of the split tensors as follows:  
\[g^{h}=\text{Sigmoid}\big{(}F_{h}\big{(}Y^{h}\big{)}\big{)} \tag{5}\]  
\[g^{w}=\text{Sigmoid}\big{(}F_{w}\big{(}Y^{w}\big{)}\big{)} \tag{6}\]  
where \(F_{h}\) and \(F_{w}\) indicate two different \(1\times 1\) convolutional kernels.