# Target Detection for Coloring and Ripening Potted Dwarf Apple Fruits Based on Improved YOLOv7-RSEs
## 2 Materials and Methods
### Improvements to YOLOv7
#### 2.4.1 SE Attention Mechanism  
Traditional CNNs emphasize feature representation within channels while overlooking the mapping relationships between channels. The SE module addresses inter-channel relationships through squeeze-and-excitation operations, thereby adaptively adjusting channel responses. In traditional convolutional networks, inter-channel relationships are often implicit and are confined to specific hierarchical levels. However, top-level channels are closely related to tasks; for instance, in segmentation networks, the number of top-level channels corresponds to the number of segmentation categories. In middle layers of the network, the number of channels is typically based on empirical data or test results, which may be derived from real-world applications or extensive experimental analysis. The SE network architecture, proposed in [23], integrates the idea of attention mechanisms into convolutional neural networks to achieve adaptive learning of the importance of each channel. The SE module introduces a parameter-efficient channel attention mechanism, as illustrated in Figure 5. It achieves this through two steps: squeezing and excitation. In the squeezing phase, the feature maps are aggregated into a scalar value, and in the excitation phase, a fully connected layer is utilized to transform this value into a weight vector, which is then used to weight the feature maps. The SE module enables CNNs to learn the importance of each channel, thereby improving model performance. Demonstrating strong performance across various image classification tasks, the SE network has been widely adopted in diverse visual tasks. The structure of the SE block is to map the input feature map \(X\in R^{H^{\prime}\times W^{\prime}\times C^{\prime}}\) to the output feature map \(U\in R^{H\times W\times C}\) through convolutional operation Ftr, where the collection of convolutional kernels is represented by \(V=[v_{1},v_{2},\dots,v_{c}]\)I, and the output is represented by \(U=[u_{1},u_{2},\dots,u_{c}]\); thus,  
\[u_{c}=u_{c}*X=\sum_{s=1}^{C^{\prime}}v_{c}^{s}*x^{s} \tag{2}\]  
This formula represents the convolution operation, where \(u_{c}\in R^{H\times W},v_{c}=\left[v_{c}^{1},v_{c}^{2},\dots,v_{c}^{C^{\prime}}\right]\), and \(X=\left[x^{1},x^{2},\dots,x^{C^{\prime}}\right]\); \(v_{c}^{s}\) is a 2D convolution kernel, indicating that \(v_{c}\) acts on the corresponding channel of the \(X\) squeeze stage, Global Information Integration, in order to comprehensively consider the information of each channel in the output feature map; this  
Figure 5: SE attention mechanism. paper adopts the global average pooling method to integrate global spatial information into a single-channel descriptor, \(Z_{c}\)  
\[z_{c}=F_{sq}(u_{c})=\frac{1}{H\times W}\sum_{i=1}^{H}\sum_{j=1}^{W}u_{c}(i,j) \tag{3}\]  
For activation and adaptive recalibration, in order to adequately capture the interdependencies between channels, this paper employs a simple gating mechanism, the sigmoid activation function, to achieve adaptive recalibration of channel responses. \[s=F_{ex}(z,W)=\sigma(g(z,W))=\sigma(W_{2}\delta(W_{1}z)) \tag{4}\]  
where \(\delta\) is the ReLU function, \(W_{1}\in R^{\frac{C}{\gamma}\times C}\), and \(W_{2}\in R^{C\times\frac{C}{\gamma}}\). The final output result of the SE code block is obtained by rescaling U by a scale factor, s:  
\[x=F_{scale}(u_{c},s_{c})=s_{c}u_{c} \tag{5}\]  
In this paper, the SE module serves as a plug-and-play component designed to address inter-channel dependencies, as illustrated in Figure 6. It utilizes global average pooling to compress global spatial information, i.e., performing the squeeze operation. To fully leverage the aggregated information from the squeeze operation, the proposed model employed the FC-ReLU-FC-sigmoid operation to capture channel dependencies. The SE module can be added to any location of the YOLOv7 network, such as within the C3 module.