# Research on Urban Traffic Incident Detection Based on Vehicle Cameras
## 3 Data and Methods
### Neural Networks
#### 3.2.2 Mechanism for Fusing Attention  
The Mechanism of Attention [45; 46; 47] is a deep learning data processing approach that is widely employed in a variety of deep learning tasks, including natural language processing, picture recognition, and audio recognition. The principle of the attention mechanism comes from the mechanism of the human brain processing information through the visual function. When the human brain receives information, it does not process all of it, but only processes the information that the brain considers important, and filters the information that the brain considers unnecessary. This can improve the efficiency of information processing. Similarly, when processing information, the attention mechanism will selectively focus on a part of the information and ignore other unimportant information. The attention mechanism can not only judge and decide which part of the information needs to be paid attention to, but also can allocate limited information processing resources to the part to be paid attention to. Convolutional Block Attention Module (CBAM) is a pluggable module that enhances the performance of the network model and generates relevant features in the two dimensions of space and channel by weighing the features in the spatial and channel directions, Its structure is shown in Figure 7. It applies channel and spatial attention modules consecutively to learn characteristics in the channel and spatial dimensions, respectively. In addition, information through emphasis or suppression also contributes to the flow of information within the network. Figure 5: Atrous convolution structure. The CBAM attention mechanism is introduced into the neck of the YOLOv5s model in this work. For feedforward convolutional neural networks, this is a simple but effective attention module. Given an intermediate feature map, our module successively infers the attention map along two independent dimensions (channel and space), and then multiplies the attention map by the input feature map for adaptive feature decoration. Figure 6: Atrous spatial pyramid structure. Figure 7: Fusion attention mechanism structure. The CBAM attention mechanism module is illustrated in the diagram above. The two aspects of CBAM's attention mechanism are spatial attention and channel attention. As can be seen from the above figure, the channel attention is in the front, and the spatial attention is in the back. After the feature map is input, it first enters the channel attention. In the spatial dimension, the channel attention module compresses the feature map. Then it acts on a one-dimensional vector. Not only mean pooling but also max-pooling are taken into account when compressing in the spatial dimension. To collect the spatial information of feature maps, feed them to a shared network, compress the spatial dimension of the input feature maps, and sum and merge element-wise to produce channel attention maps, average pooling and max pooling can be utilized. As far as a picture is concerned, channel attention focuses on what content within the picture is important. When performing gradient back propagation computations, average pooling has feedback for every pixel on the feature map, whereas max-pooling only receives gradient feedback at the most responsive area of the feature map. The following is a description of the channel attention mechanism:  
\[M_{c}(F) =\sigma(MLP(AvgPool(F))+MLP(MaxPool(F))) \tag{3}\] \[=\sigma(W_{1}(W_{0}(F^{c}_{avg}))+W_{1}(w_{0}(F^{c}_{max}))) \tag{4}\]  
where \(\sigma\) is denotes the sigmoid function, \(W_{0}\in R^{c\times C\div r}\), \(W_{1}\in R^{c\times C\div r}\)\(W_{0}\) and \(W_{1}\) both inputs share the weights of the _MLP_ network. Unlike channel attention, the spatial attention network module generates the spatial attention map primarily based on the spatial relationship between picture feature elements. The spatial attention focuses on \"where\" is the feature information part, and the features of which positions are more meaningful or important.