## 3 Methodology
### ECA-CBAM Attention Mechanism  
When detecting the surveillance images of tower crane cabs, the image quality is poor because the camera is usually installed at a high position, the pixel proportion of phones and cigarettes in the image is small, and issues such as occlusion, deformation, and blurred details are present. The YOLOv7 algorithm needs help properly extracting features from these objects, resulting in the inadequate identification of an operator using a phone or smoking. The conventional YOLOv7 network detects objects of different sizes by fusing feature maps at three resolutions (80 \(\times\) 80, 40 \(\times\) 40, and 20 \(\times\) 20), with three anchor boxes assigned to each scale to capture small, medium, and large objects. The minimum detection capability for an input image of 640 \(\times\) 640 pixels is 8 \(\times\) 8 pixels. However, cigarettes and phones are much smaller in the tower crane scene than in this resolution. To enhance model performance, we add a 160 \(\times\) 160 detection branch to YOLOv7, increasing the minimum detection resolution to 4 \(\times\) 4 pixels. Otherwise, an attention mechanism is implemented to augment the network's sensitivity to small objects, enhancing detection accuracy, and the network learns richer feature representations. However, introducing the attention mechanism augments the quantity of parameters, augmenting the model's computational complexity. The computation of the fully connected layer correlates with the number of channels, and given that the detection branch has a substantial number of channels, the computational overhead of channel attention is  
Figure 3: YOLO-TC network structure. relatively higher. We improve the CBAM by reducing the computation of channel attention. In this paper, we draw on the ECANet network structure to design the improved channel attention module and name it the E-CAM. The E-CAM is shown in Figure 4.  
The figure shows that the E-CAM uses one-dimensional convolution with convolution kernel length k to realize local cross-channel interaction and extract inter-channel dependencies based on the original channel attention. After one-dimensional convolution, The element-wise sum of the output results is passed through an activation function to produce channel attention weights. The attention weights are subsequently applied to the original input feature maps channel by channel, enabling feature recalibration. Among them, the size of the one-dimensional convolution kernel is k, and the function of the number of channels C determines the value of k. The mapping relationship between the two is as follows:  
\[C=\phi(k)=2^{\gamma\times k-b} \tag{1}\]  
Moreover, the number of channels C is known at this point, and we can derive an expression for k:  
\[k=\psi(C)=\left|\frac{log_{2}(C)}{\gamma}+\frac{b}{\gamma}\right|_{old} \tag{2}\]  
The \(\left|x\right|_{\text{odd}}\) is the nearest odd number, \(\gamma\) is 2, and \(b\) is 1. The kernel size \(k\) is adjusted adaptively based on the number of channels C. The theoretical rationale behind this design lies in the observation that with an increasing number of channels, the cross-channel dependencies become more complex, necessitating a larger receptive field (i.e., a larger \(k\)) to effectively model long-range dependencies across channels. Conversely, when the number of channels is smaller, a relatively smaller \(k\) is sufficient to capture the essential inter-channel relationships. Compared to a fixed kernel size, the adaptive adjustment mechanism of \(k\) offers several advantages. First, it achieves a balance between model complexity and representational capacity. Second, the dynamic kernel size enables the E-CAM to flexibly adapt to features with varying numbers of channels, thereby enhancing the effectiveness and generalization capability of the channel attention mechanism.