# FIQ: A Fastener Inspection and Quantization Method Based on Mask FRCN
## 3 Semantic Segmentation Algorithm Based on Track Fasteners--Mask FRCN
### FCRM: Fastener CBAM Residual Module  
By incorporating the CBAM (Convolutional Neural Network Attention Module) into the bottleneck residual module, we constructed a bottleneck residual module with an attention mechanism called FCRM (Fastener CBAM Residual Module). In this new module, CBAM can extract spatial and channel-related information, thereby enhancing the performance of the model in the segmentation task of rail fastener-connected regions. The following is a detailed composition of the CBAM-enhanced bottleneck residual module, based on the description above:  
(1) First layer: A \(1\times 1\) convolutional layer that reduces the number of channels. This layer typically includes batch normalization and an activation function (e.g., ReLU). The layer can be represented as follows:  
\[F_{1}(x)=\sigma(BN(W_{1}*x)). \tag{1}\]  
Figure 3: This system for designing railway fasteners enables one-stop testing of fasteners, shims, and fastener hats. For fasteners, the system can evaluate damage and shift, whereas for fastener hats, it can evaluate damage, loss, and looseness. As for shims, the system can evaluate them for looseness and damage.  
(2) Second layer: A 3 \(\times\) 3 convolutional layer that extracts spatial features. Similarly, this layer also includes batch normalization and an activation function. The layer can be represented as follows:  
\[F_{3}(x)=BN(W_{3}*x). \tag{2}\]  
(3) Third layer: A 1 \(\times\) 1 convolutional layer that restores the number of channels. This layer includes only batch normalization and typically does not include an activation function. The layer can be represented as follows:  
\[F_{2}(x)=\sigma(BN(W_{2}*x)). \tag{3}\]  
(4) CBAM is introduced after the third convolutional layer and comprises channel attention and spatial attention [26]. Channel attention processes the input feature map with global average pooling and global max pooling, generating attention vectors that are normalized to obtain channel attention weights. These weights are applied to the third convolutional layer's output. Spatial attention uses a convolution operation on the feature map, normalizing the output with a Sigmoid activation function to obtain spatial attention weights, which are then applied to the feature map.  
(5) Skip Connection adds the input feature to CBAM's output, forming a residual connection with the attention mechanism. This structure helps avoid gradient vanishing and representational bottleneck issues, allowing for deeper network structures.  
(6) The activation function (e.g., ReLU) processes the output of the skip connection to obtain the final output of the CBAM-enhanced bottleneck residual module.  
Integrating this module into ResNet-101 creates a more powerful feature extractor, where spatial and channel attention mechanisms enhance the model's performance. Channel attention identifies channels with more task-related information, whereas spatial attention focuses on important image regions.  
With the improved ResNet-101 as the backbone network for Mask R-CNN, the model performs better in rail fastener-connected region segmentation tasks. The CBAM-enhanced bottleneck residual module enables focusing on key areas and identifying task-related channels, improving Mask R-CNN's accuracy and supporting railway safety and maintenance.