## 2 GCB YOLOv7 Detection Method
### Attention Mechanisms  
The CBAM mechanism [22] is lightweight and plug-and-play, which can allocate the resources of the convolutional network according to the importance of feature extraction, thus changing the tendency of feature extraction. It reduces the interference of invalid features and improves the detection effect of the target.  
The CBAM mechanism is shown in Figure 2. Firstly, the input image in the initial stage undergoes parallel maximum pooling and average pooling operations on the feature map by the channel attention module and shares a multilayer perceptron to realize the output of the channel features \(M_{\text{C}}\). Secondly, \(M_{\text{C}}\) interacts with the input image and transfers the transition features to the spatial attention module. Finally, in the spatial attention module, the transition features are normalized by convolution and sigmoid functions, and the weights are multiplied with the features to achieve the output of spatial features \(M_{\text{S}}\).  
Suppose given an input intermediate feature map \(F\in R^{\text{C}\times H\times\text{W}}\), CBAM will complete channel feature extraction and spatial feature extraction and, in turn, generate a 1D channel attention map \(M_{\text{c}}\in R^{\text{C}\times 1\times 1}\) and a 2D spatial attention map \(M_{\text{s}}\in R^{1\times H\times\text{W}}\), respectively. Thus, the overall attention process of channel feature extraction and spatial feature extraction can be summarized as follows:  
\[F^{\prime}=M_{\text{c}}(F)\otimes F \tag{4}\]  
\[F^{\prime\prime}=M_{\text{s}}(F^{\prime})\otimes F^{\prime} \tag{5}\]  
where \(F^{\prime}\) is an intermediate feature; \(\otimes\) denotes element-wise multiplication; and \(F^{\prime\prime}\) is the final refined output.  
In Hemercollis citrina Baroni maturity detection, the CBAM mechanism is able to allocate attention to both spatial and channel dimensions simultaneously, which enhances the detection effect of the model.  
The CBAM mechanism utilizes the feature relationships between channels to generate feature mappings. Considering the feature information of each channel at the same time requires a lot of computation. Therefore, the channel computation can be represented as follows:  
\[\begin{array}{ll}M_{\text{c}}(F)&=\sigma[MLP(A\text{r}_{\text{S}}Pool(F))+MLP( MaxPool(F))]\\ &=\sigma[W_{1}(W_{0}(F^{\text{c}}_{\text{r}\text{a}\text{r}\text{s}}))+W_{1}(W_ {0}(F^{\text{c}}_{\text{m}\text{a}\text{r}\text{s}}))]\end{array} \tag{6}\]  
Figure 2: CBAM mechanism.  
where \(\sigma\) denotes the sigmoid function, \(W_{0}\in R^{C/r\times C}\), \(W_{1}\in R^{C\times C/r}\), \(W_{0}\) and \(W_{1}\) denote the weights after pooling and sharing the network, respectively, and \(r\) is the channel reduction ratio.  
In the spatial attention model, to aggregate spatial information, two 2D maps \(F_{\text{avg}}^{\text{s}}\in R^{1\times H\times W}\) and \(F_{\text{max}}^{\text{s}}\in R^{1\times H\times W}\) are generated by applying max-pooling and average pooling operations and concatenating the two 2D maps along the channel axis to generate an efficient feature descriptor. Then, a convolution layer is applied to generate a spatial attention map \(M_{s}(F)\in R^{H\times W}\). In short, spatial attention is computed as follows:  
\[\begin{array}{ll}M_{s}(F)&=\sigma[f^{k\times k}(AvgPool(F);MaxPool(F))]\\ &=\sigma[f^{k\times k}(F_{\text{arg}}^{\text{s}};F_{\text{max}}^{\text{s}})] \end{array} \tag{7}\]  
where \(f^{k\times k}\) represents a convolution operation with the filter size of \(k\times k\).  
In the Hemerocallis citrina Baroni maturity detection model, inserting the CBAM mechanism between the feature extraction and the feature fusion network enables the model to focus on the information that is more critical to the current task among the numerous information inputs, reduces attention to other information, and even filters out irrelevant information. It can also solve the problem of information overload and improve the efficiency and precision of image processing.