# Real-Time Monitoring Method for Traffic Surveillance Scenarios Based on Enhanced YOLOv7
## 3 ETS-YOLOv7 Algorithm
### Multidimensional Attention Mechanism  
To enhance vehicle feature representation in complex traffic environments and improve the saliency of these features, attention mechanisms have been integrated into the backbone network. For example, the channel attention mechanism of the SE module only considers the saliency of each channel while ignoring the features of the spatial region [42]. On the other hand, the spatial attention mechanism optimizes the interest representation in neural networks by exploiting the different spatial relationships between feature maps and allocating computational resources to more important spatial feature locations [43]. Current research indicates that both channel and spatial attention mechanisms can enhance the feature extraction capability of the method. To comprehensively consider the semantic information from both aspects, the CBAM attention module is introduced. This module serially generates feature map information in both channel and spatial dimensions, thus enhancing the feature extraction capability of the network.  
As shown in Figure 2, the first step is to generate the channel attention feature \(\rm{M_{C}}\), where the learned weights are multiplied by the original feature map, enhancing effective channel features and weakening ineffective ones by weighting. The second step is the generation of the spatial attention feature \(\rm{M_{S}}\), which is multiplied elementwise by the input feature map \(\rm{M_{C}}\)(F)\(\times\)F, which enhances the saliency of the vehicle features at the spatial level and outputs the final attention-enhanced feature map. The channel attention module first aggregates spatial information at the spatial level through global average pooling and global max pooling operations, yielding global average pooling and global max pooling features. These two channel-level features are then fed into a shared network consisting of a single hidden layer multi-layer perceptron (MLP). The results are summed to obtain the channel attention features. The formula is as follows:  
\[\rm{M_{C}}(F)=\sigma(MLP(AvgPool(F))+MLP(MaxPool(F))) \tag{1}\]  
where F is the input feature map, MLP is the multi-layer perceptron, and \(\sigma\) is the sigmoid function.  
The spatial attention module performs global average pooling and global max pooling operations along the channel dimension to derive corresponding features. These two features are then fused by a convolution operation to obtain the final features. The formula is as follows:  
\[\rm{M_{S}}(F)=\sigma(\tilde{f}^{\times\gamma}([AvgPool(M_{C}(F)\times F);MaxPool (M_{C}(F)\times F)])) \tag{2}\]  
where \(\sigma\) is the sigmoid function and \(\tilde{f}^{\times\gamma}\) is a convolution kernel size of \(7\times 7\).  
Figure 1: ETS-YOLOv7 network framework diagram.  
We inserted the CBAM modules after the second, third, and fourth CLAN modules in the backbone network. Thus, before feeding the feature maps into the backbone network, we assign weights to both high-dimensional and low-dimensional features from both channel and spatial perspectives, allowing the model to focus more on vehicle characteristics and reduce the influence of complex backgrounds.