# Research on the Classification of Sun-Dried Wild Ginseng Based on an Improved ResNeXt50 Model
## 3 To Construct the Network Model
### SE Attention Mechanism  
The core idea of the SE attention mechanism is to adaptively adjust channel weights, enabling the model to focus more on essential feature channels. This mechanism mainly consists of two core steps: squeeze and excitation. In the squeeze phase, the SE attention mechanism uses global average pooling to convert each channel's feature map into a single scalar, reflecting the channel's importance across the entire feature map. In the excitation phase, a fully connected layer maps the scalar generated in the squeeze phase to a new weight vector, representing the importance of each channel. Finally, this weight vector is multiplied element-wise with the original feature map to produce a weighted feature map. This approach allows the model to focus more on essential feature channels, enhancing classification performance. The SE attention mechanism is advantageous due to its simple and efficient structure, making it easy to integrate into existing convolutional neural network (CNN) architectures. It has significantly improved performance in various image classification tasks, becoming a widely adopted attention mechanism. Figure 5 illustrates its working principle. (1) Input Features: For any given transformation, such as a convolution, which maps the input X to U\(\left(\text{U}^{\text{H}\times\text{W}\times\text{C}}\right)\), a corresponding SE block can be constructed to perform feature recalibration. (2) Calculation Method: In the squeeze phase, the feature map U undergoes a squeezing operation, aggregating feature mappings over its spatial dimensions (H \(\times\) W) to generate  
Figure 4: Comparison of the ReLU and Leaky ELU functions. Figure 5: Squeeze and excitation networks. channel descriptors. The primary function of this descriptor is to create a global distribution embedding of channel feature responses, allowing global receptive field information from the network to be utilized by all layers. Specifically, this process involves applying global average pooling to the input feature map to achieve compression along the channel dimension. Assuming the shape of the input feature map is (C, H, W), where C represents the number of channels, and H and W are the height and width of the feature map, respectively, a tensor of shape (C, 1, 1) is obtained through global average pooling. The calculation formula for the squeeze phase is as follows:  
\[\mathrm{z_{c}}=\mathrm{F_{sq}(u_{c})}=\frac{1}{\mathrm{H}\times W}\mathrm{ \sum_{i=1}^{H}}\ \ \ \mathrm{\sum_{j=1}^{W}}\ \ \ \mathrm{u_{c}(i,j)} \tag{6}\]  
In the excitation phase, a simple adaptive channel selection mechanism is employed. This mechanism uses the embedding as input to generate a set of modulation weights for each channel. These weights are then applied to the feature map U to produce the output of the SE block, which can be directly passed to subsequent layers of the network. Specifically, the tensor of shape (C, 1, 1) obtained from the previous step is fed into a fully connected layer, reducing the number of channels to a smaller value, referred to as middle channels. After compression, the features are input into a ReLU activation function, resulting in a vector of shape (middle_channels). The calculation formula for the excitation phase is as follows:  
\[\mathrm{s}=\mathrm{F_{ex}(z,W)}=\sigma(\mathrm{g}(z,W))=\sigma(\mathrm{W_{2} \delta(W_{1}z)}) \tag{7}\]  
(3) During the output feature process, the previously obtained excitation vector is expanded into a tensor of shape (C, 1, 1) and multiplied element-wise with the original feature map X. This operation results in a weighted feature map for each channel, effectively enhancing feature representation capabilities. The calculation formula for the output features is as follows:  
\[\mathrm{\overset{\sim}{X_{c}}}=\mathrm{F_{scale}(u_{c},s_{c})}=\mathrm{s_{c}} \cdot u_{c} \tag{8}\]  
Wild sun-dried ginseng roots have dense and varied shapes and sizes, which can affect a network model's ability to extract detailed features.