# Log Volume Measurement and Counting Based on Improved Cascade Mask R-CNN and Deep SORT
## 3 Methods
### Improved Backbone  
In the Cascade Mask R-CNN model, a combination of ResNet and Feature Pyramid Network (FPN) is typically employed as the backbone for feature extraction. The ResNet network generates features at various scales, while the FPN effectively integrates these multi-scale feature maps by constructing a pyramid structure across different network layers. This dual information flow--both bottom-up and top-down--ensures that high-level semantic information is transmitted to lower-level feature maps, allowing the network to  
Figure 3: The overall network structure. acquire richer semantic details for better object understanding and localization. However, the differences in spatial resolution and semantic content among the multi-scale feature maps produced by ResNet can result in adjacent feature maps containing similar information, leading to redundancy. This redundant information may introduce unnecessary computational overhead during feature fusion and negatively impact detection accuracy. Therefore, optimizing the feature fusion strategy is crucial for effectively leveraging multi-scale features and minimizing redundancy. Attention-based methods effectively emphasize critical prediction regions, enabling the model to focus more precisely on the object and concentrate more on the most relevant positive samples. This enhances the performance of two-stage object detectors [35]. Therefore, we constructed a hierarchical attention mechanism applied to the multi-scale features output by ResNet. Each feature scale is refined using a Convolutional Block Attention Module (CBAM) [36], before being integrated into the Feature Pyramid Network (FPN) for feature fusion. The improved network architecture is illustrated in Figure 4, utilizing ResNet50 as the backbone network. ResNet50 is a deep convolutional neural network with 50 layers that employs a residual learning framework. It consists mainly of multiple Bottleneck modules organized into five stages, with the depth of feature maps progressively increasing at each stage. We integrated the CBAM module after the four stages from stage 1 to stage 5 of ResNet50. The four-scale features output by ResNet are \(F_{1},F_{2},F_{3},F_{4}\), and we apply the CBAM mechanism to each feature map to obtain the enhanced feature maps \(F_{i}^{\prime}\), as shown in Formula (1):  
\[F_{i}^{\prime}=CBAM(F_{i}),i=1,2,3,4 \tag{1}\]  
The network structure of the CBAM module is illustrated in Figure 5. CBAM contains channel attention and spatial attention. The objective of channel attention is to learn the weights assigned to each channel, with the aim of amplifying the channels carrying valuable information while mitigating noise. Channel attention is achieved by conducting global mean pooling and global maximum pooling on the input feature maps, which are subsequently processed by a fully connected layer. Finally, the final channel attention score is obtained by sigmoid activation function. Define the input feature map as F and the  
Figure 4: Improved Backbone, ResNet50-CBAM. output of the channel attention as \(M_{c}\), and the channel attention weights are computed as follows:  
\[ \begin{split} M_{c}(F)=\sigma(MLP(AvgPool(F))\\ +MLP(MaFPool(F)))\\ =\sigma(W_{1}(W_{0}(F_{avg}^{c}))+W_{1}(W_{0}(F_{max}^{c})))\end{split}  \tag{2}\]  
where \(\sigma\) represents the activation function, \(MLP\) stands for a multi-layer perceptron, and \(W_{0}\) and \(W_{1}\) denote the shared MLP weights. \(AvgPool\) and \(MaxPool\) correspond to global average pooling and global maximum pooling, respectively. Spatial attention takes the feature map after the channel attention calculation as its input. The input feature map is subjected to maximum pooling and average pooling along the channel dimension, resulting in two single-channel feature maps. These two feature maps are then processed using a \(7\times 7\) convolutional kernel. After passing through an activation function, the final spatial attention is obtained. Formula (3) shows the calculation process  
\[