A lightweight citrus disease identification method based on a double attention mechanism
By introducing ECA and MSAA modules with dual attention mechanisms into a lightweight model, the accuracy of citrus disease identification was improved, solving the balance between efficient operation and identification accuracy on mobile devices, and achieving efficient and accurate citrus disease identification on mobile devices.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NANTONG UNIV
- Filing Date
- 2026-02-12
- Publication Date
- 2026-06-09
AI Technical Summary
Existing lightweight models struggle to balance model size, inference speed, and recognition accuracy while maintaining high precision in citrus disease identification, especially when dealing with subtle lesion features, which presents a recognition challenge.
A lightweight model based on a dual attention mechanism is adopted. By introducing the efficient channel attention module ECA and the multi-scale adaptive attention module MSAA, and combining the MobileNetV4-Conv-Small architecture, the DACNet model is constructed to enhance the feature extraction capability and achieve efficient operation of the model on mobile devices.
It significantly improved the accuracy of citrus disease identification to 92.76%, meeting the real-time application needs of mobile and edge devices, while maintaining the model's lightweight nature and efficient inference.
Smart Images

Figure CN122176262A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer vision and deep learning technology, specifically to a lightweight citrus disease identification method based on a dual attention mechanism. Background Technology
[0002] With breakthroughs in deep learning technology, CNN models have demonstrated significant advantages in citrus disease identification. Some classic convolutional neural networks, such as AlexNet, VGG, ResNet, and DenseNet, have been applied to citrus disease identification with some success. However, citrus disease datasets suffer from drawbacks such as small data volume and limited data context. Furthermore, due to the complexity of agricultural scenarios, a more realistic citrus disease dataset is currently needed.
[0003] In recent years, the attention mechanism of convolutional neural networks (CNNs) has further advanced research on feature extraction. The attention mechanism of CNNs changes the way networks summarize different feature information; it can distinguish between different feature information, allowing the network to focus on important information and reduce attention to unimportant information. Therefore, many attention mechanism methods have been applied to the field of complex disease identification.
[0004] In recent years, the rapid development of mobile and edge computing devices has further propelled research into lightweight neural networks. Lightweight models have revolutionized the deployment of traditional deep networks on mobile devices, enabling efficient inference under limited computing resources and storage constraints. This allows disease identification systems to run in real-time on edge terminals such as smartphones and portable detection devices, thus meeting the urgent need for real-time field diagnosis. Consequently, many lightweight model methods have been applied to the field of real-time agricultural disease detection. However, while maintaining high accuracy, existing lightweight models often struggle to achieve an ideal balance between model size, inference speed, and recognition accuracy. This is particularly true when dealing with tasks requiring fine feature recognition, such as citrus diseases. Effectively extracting subtle lesion features under lightweight constraints remains a significant challenge.
[0005] Despite significant progress in existing research, citrus disease identification still faces challenges such as complex background interference, high similarity of disease symptoms, and difficulty in real-time detection and identification.
[0006] How to solve the above problems is the problem that this invention aims to solve. Summary of the Invention
[0007] For citrus disease data identification, where subtle lesions are the key identifying feature, a model capable of extracting more important detailed features of the lesions is needed. This invention explores ways to enhance feature extraction capabilities by adding a novel attention module to a convolutional neural network. For citrus disease detection systems with real-time field diagnosis as a key application scenario, a lightweight model that can run efficiently on resource-constrained equipment is required. This invention explores effective ways to significantly reduce model complexity while maintaining recognition accuracy by introducing a lightweight design strategy into the convolutional neural network. This invention proposes a citrus disease identification method based on a hybrid attention network. By fusing channel attention and spatial attention mechanisms, it effectively improves the model's ability to extract disease features and enhances its robustness in complex environments, providing a new approach for the timely and accurate identification of citrus diseases.
[0008] The purpose of this invention is to provide a lightweight citrus disease identification method based on a dual attention mechanism. This method introduces an efficient channel attention module (ECA) and a multi-scale adaptive attention module (MSAA) to form a dual attention collaborative mechanism, which significantly improves the accuracy of citrus disease identification while maintaining the lightweight nature of the model.
[0009] To achieve the above objectives, the present invention adopts the following technical solution:
[0010] A lightweight citrus disease identification method based on a dual attention mechanism includes the following steps:
[0011] Step S1: Data Acquisition and Preprocessing: Collect and organize digital images of citrus leaves in the citrus orchard. Perform preprocessing on the images, including data augmentation, size normalization, and standardization. Use image annotation tools to label the preprocessed images to generate a training dataset containing category labels. The advantages are: effectively expanding the number of training samples, improving the model's robustness to changes in lighting, shooting angle, leaf posture, and other real-world scene variations; facilitating model processing; accelerating model convergence and improving training stability. The citrus disease leaf images include images of leaves with seven types of diseases: anthracnose, mottled yellowing, boron deficiency, canker, citrus oil spot, magnesium deficiency, and zinc deficiency, as well as images of healthy leaves, totaling eight target categories.
[0012] The data augmentation includes at least one of the following operations: horizontal flip, vertical flip, random rotation, color dithering, random cropping, affine transformation, and random erasure.
[0013] The size normalization scales the image to 224×224 pixels;
[0014] The standardization process uses the standard mean and standard deviation of the ImageNet dataset for normalization.
[0015] Step S2: Constructing a DACNet dual-attention lightweight classification model: Utilizing the efficient channel attention module ECA and the multi-scale adaptive attention module MSAA of the DACNet dual-attention lightweight classification model, a dual-attention collaborative mechanism is formed to enhance its ability to extract and identify citrus disease features. Its advantages include: maintaining mobile-friendly operation based on the MobileNetV4-Conv-Small architecture; the ECA module adopts an extremely lightweight design, achieving efficient channel attention through one-dimensional convolution and the HardSwish activation function, enhancing sensitivity to the color features of citrus diseases; and the MSAA module employs multi-scale depth-separable convolution. The model extracts spatial features at different scales and combines channel attention and residual gating hybrid connections to achieve spatial-channel joint attention enhancement, improving the detection capability of subtle lesions. The dual attention collaboration mechanism adopts a strategic deployment strategy, mainly using ECA to preserve detailed features in shallow and intermediate layers, and using ECA and MSAA dual attention collaboration enhancement in key downsampling layers and deep feature layers to achieve a balance between computational efficiency and recognition accuracy. The lightweight design (approximately 782K parameters and approximately 3MB model size) makes the model easy to deploy on mobile and edge devices, while achieving a recognition accuracy of 92.76%, which is better than other lightweight models and meets the needs of practical applications.
[0016] Step S2 includes the following steps:
[0017] Step S2.1: Construct a feature extraction backbone network (the core part for feature extraction) based on the MobileNetV4-Conv-Small architecture, and extract hierarchical features;
[0018] The MobileNetV4-Conv-Small architecture is used as the base network for the DACNet model (as a starting point or reference architecture).
[0019] The MobileNetV4-Conv-Small network (the entire model architecture, i.e., the MobileNetV4-Conv-Small architecture) uses a progressive downsampling strategy in its efficient Stem module, downsampling the input image from 224×224 to 56×56 to retain more detailed features.
[0020] The Stem module consists of three operations: the first downsampling (224→112) uses standard convolution;
[0021] The second downsampling (112→56) uses standard convolution combined with ECA channel attention enhancement;
[0022] The third feature enhancement (56→56) uses convolution combined with ECA attention to preserve spatial information;
[0023] Then, the EUIB block sequence was used to further downsample the feature map from 56×56 to 28×28 (Block 4) and 14×14 (Block 6) to form a multi-scale feature representation. The high-resolution feature map (56×56) retains detailed information for the detection of subtle disease features, while the medium and low resolution feature maps (28×28, 14×14) extract high-level semantic information for global classification.
[0024] Step S2.2: Construct an efficient channel attention module (ECA):
[0025] An efficient channel attention module (ECA) is constructed and applied after projection convolution to be responsible for learning the importance of global channel dimension features. The efficient channel attention module (ECA) uses one-dimensional convolution to achieve channel attention, with only 3-5 parameters, achieving extremely lightweight channel feature enhancement.
[0026] The calculation process of the ECA module is as follows: For the input feature map Perform global average pooling to obtain channel descriptors. The calculation formula is as follows:
[0027] (1);
[0028] Where: B, C, H and W are the batch, channel, height and width of the feature map, respectively; Indicates the spatial location of all batches and channels. The value;
[0029] Channel attention weights are calculated using one-dimensional convolution and the HardSwish activation function, and the formula is as follows:
[0030] (2);
[0031] in: This is a one-dimensional convolution operation;
[0032] The HardSwish activation function in formula (2) is defined as follows:
[0033] (3);
[0034] Where: x is the input of HardSwish (from the output of Conv1d), and ReLU6 is the modified linear unit 6 activation function as shown in formula (4).
[0035] (4);
[0036] The attention weights are multiplied by the input features, and the calculation formula is as follows:
[0037] (5);
[0038] in, This indicates element-wise multiplication. The sigmoid function normalizes the weights to the range [0.5, 1.5]. The enhanced output feature map;
[0039] Step S2.3: Construct the Multi-Scale Adaptive Attention Module (MSAA):
[0040] The attention module MSAA is applied after intermediate depth convolution and is responsible for multi-scale spatial-channel joint feature enhancement.
[0041] That is, the attention module MSAA is immediately followed by the intermediate depth convolution ( After that, projective convolution ( Previously, this method was used to perform multi-scale spatial-channel joint feature enhancement on the extended channel feature map output by intermediate depth convolution.
[0042] The Multi-Scale Adaptive Attention Module (MSAA) uses multi-scale depthwise separable convolution to extract spatial features at different scales. Combined with a channel attention mechanism, it achieves spatial-channel joint attention enhancement through residual gated hybrid connections and HardSwish activation function.
[0043] The calculation process of the MSAA module is as follows: Calculate the channel attention weights (same as the ECA module), and the calculation formula is:
[0044] (6);
[0045] in: Channel attention weights; AvgPool is the average pooling operation;
[0046] Channel compression and spatial feature extraction are performed. Spatial features are extracted through multi-scale depthwise convolution. The formula for multi-scale depthwise convolution is as follows:
[0047] (7);
[0048] (8);
[0049] in: The feature map is compressed from the channel; DWConv3×3 and DWConv5×5 are 3×3 and 5×5 depthwise separable convolutions, respectively; The output feature map is a 3×3 depth separable convolution. The output feature map is a 5×5 depth separable convolution.
[0050] Multi-scale feature fusion, its calculation formula is as follows:
[0051] (9);
[0052] in: The fusion weights are the outputs of the 3×3 convolution; The fusion weights are the output of the 5×5 convolution;
[0053] The spatial attention weights are calculated using the following formula:
[0054] (10);
[0055] Where: Conv5×5 is a 5×5 convolution;
[0056] The calculation formula for the output via residual gated hybrid connection is:
[0057] ;
[0058] LayerScale is the layer scaling operation used for stable training. For the input feature map, This is the enhanced output feature map.
[0059] Step S2.4: Construct the Enhanced General Inverted Bottleneck Block EUIB:
[0060] It supports three flexible convolution combination strategies: IB, ConvNext, and ExtraDW.
[0061] The Enhanced Universal Inverted Bottleneck Block (EUIB) dynamically selects different convolution kernel sizes and depth convolution configurations based on network depth and feature complexity, achieving a balance between computational efficiency and feature representation capability.
[0062] The IB block structure includes: first, performing a 1×1 expanding convolution to increase the number of channels; then performing a 3×3 or 5×5 depthwise separable convolution (DWConv) to extract spatial features; and finally performing a 1×1 projective convolution to compress the number of channels.
[0063] ConvNext Block Structure: The ConvNext block structure includes: first, a 3×3 StartDW convolution is performed to extract preliminary spatial features, then a 1×1 Expand convolution is performed to expand the number of channels, and finally a 1×1 Project convolution is performed to compress the number of channels.
[0064] ExtraDW Block Structure: The ExtraDW block structure includes: first, a 3×3 or 5×5 StartDW convolution is performed for preliminary spatial feature extraction, then a 1×1 Expand convolution is performed to expand the number of channels, followed by a 3×3 or 5×5 MiddleDW convolution for depth feature extraction, and finally a 1×1 Project convolution is performed to compress the number of channels.
[0065] Step S2.5: Dual Attention Coordination Mechanism and its Strategic Deployment
[0066] The dual-attention collaborative mechanism adopts a strategic attention deployment strategy: no attention mechanism is used in the earliest layer to maintain computational efficiency, ECA channel attention is mainly used in the shallow and intermediate layers to preserve detailed features, and ECA and MSAA dual attention are used in the key downsampling layer and deep feature layer to achieve a balance between computational efficiency and feature representation capability.
[0067] In the 10 enhanced general inverted bottleneck blocks EUIB, block 0 does not use an attention mechanism, blocks 1-4 and 6-8 mainly use ECA channel attention, and blocks 5 and 9 use ECA and MSAA dual attention synergistic enhancement.
[0068] Step S2.6: Lightweight Design Strategy
[0069] The DACNet model uses a width multiplier of 0.8 to reduce the number of channels, employs depthwise separable convolutions to reduce the number of parameters, and optimizes the divisibility of the number of channels to achieve a hardware-friendly design. The final model has fewer parameters than the MobileNetV4-Conv-Small baseline while maintaining or improving recognition accuracy.
[0070] Step S3: Model Training: Based on the training dataset described in Step S1, the AdamW optimizer is used, along with a labeled smooth cross-entropy loss function and a cosine annealing restart learning rate scheduling strategy. The DACNet dual-attention lightweight classification model constructed in Step S2 is iteratively trained until the model performance metrics meet the preset requirements, and the trained classification model is obtained.
[0071] Its advantages are: the labeled smooth cross-entropy loss function (smoothing coefficient 0.1) transforms hard labels into soft labels, reducing overfitting of the model to training samples and improving generalization ability, making it particularly suitable for citrus disease datasets with imbalanced classes; the AdamW optimizer combines Adam's adaptive learning rate and weight decay regularization, which can automatically adjust the learning rate of different parameters, accelerate convergence and improve training stability, and the weight decay coefficient... Effectively prevents overfitting; the cosine annealing learning rate restart scheduling strategy enables the model to escape local optima and explore a better parameter space by periodically restarting the learning rate. Initial period and period multiple The design ensures that the training process has both a stable convergence phase and an exploration phase, improving the final performance of the model. The iterative training process is combined with an early stopping mechanism (stopping when the performance on the validation set does not improve for 20 consecutive epochs), avoiding overfitting and saving training time. This combination of training strategies enables the DACNet model to achieve a recognition accuracy of 92.76% while maintaining its lightweight nature, meeting the needs of practical applications.
[0072] Specifically, in step S3, the network training uses the AdamW optimizer with an initial learning rate of 0.0008 and a weight decay coefficient of 10. -4 The batch size is 16; a cosine annealing learning rate scheduling strategy is used, and the learning rate is updated after each training epoch. The initial period is... Cycle multiplication factor The minimum learning rate is ;
[0073] Label smoothing technology is used, with a smoothing coefficient. During training, an early stopping mechanism is used. Training is stopped early when the accuracy on the validation set does not improve for 20 consecutive rounds, and the model weight with the highest disease recognition rate on the validation set is selected.
[0074] The cross-entropy loss function is defined as:
[0075]
[0076] in, These are real labels that have undergone label smoothing processing. The model predicts probabilities; i: sample index, i=1,2,...,N, where N is the batch size; c: class index, c=1,2,...,C, where C is the number of classes (8 classes);
[0077] The formula for label smoothing is:
[0078]
[0079] Where: smoothing coefficient ; For the original The encoded true labels; C is the number of categories; label smoothing is performed on the true labels before calculating the cross-entropy loss function. Replace the 1 in the tag with Replace 0 with This enhances the model's generalization ability;
[0080] The labeled smoothed cross-entropy loss function is "composite" in the following way:
[0081] First, perform label smoothing on the real labels, and... Label Convert to smooth label The smoothing formula is shown in formula (13);
[0082] Then use the smoothed label. The cross-entropy loss is calculated using the following formula:
[0083]
[0084] in The smoothing coefficient is 0.1; The label is smoothed out; Predict probabilities for the model;
[0085] Label smoothing is integrated into the internal calculation of the cross-entropy loss function, rather than being treated as a separate loss term. PyTorch's CrossEntropyLoss achieves this through... The parameters enable this integration.
[0086] Step S4: Model reasoning and recognition: Perform the same preprocessing on the citrus leaf image to be detected as in step S1, and input the preprocessed image into the classification model trained in step S3 for forward reasoning to obtain the citrus disease classification results.
[0087] Step S4: Model Inference and Recognition: Employing the same preprocessing workflow and lightweight forward inference as the training phase, the preprocessed images to be detected are input into the trained DACNet model to achieve efficient and accurate citrus disease classification. This method offers advantages such as consistent preprocessing, fast inference speed, lightweight model, and ease of deployment. Combined with a dual attention mechanism, it achieves high recognition accuracy while maintaining a lightweight design, meeting the real-time application requirements of mobile devices.
[0088] Specifically, in step S4, forward inference is performed, progressive downsampling is performed through the efficient Stem module, feature extraction and dual attention enhancement are performed through several (10) enhanced general inverted bottleneck blocks EUIB, and the probability distributions of several classes (8 classes) are output through global average pooling and classification head to obtain the final recognition result.
[0089] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0090] (1) Dual attention collaborative mechanism improves recognition accuracy: By working together with the ECA and MSAA dual attention modules, the ability to extract citrus disease features is enhanced from the channel dimension and spatial dimension, respectively, significantly improving the recognition accuracy. The ECA module adopts an extremely lightweight design with only 3-5 parameters, realizing efficient learning of channel feature importance; the MSAA module adopts multi-scale deep separable convolution and residual gating hybrid connection to realize spatial-channel joint feature enhancement, effectively improving the ability to recognize subtle disease features.
[0091] (2) Lightweight design for mobile deployment: Lightweight strategies such as width multiplier optimization, depthwise separable convolution, and strategic attention deployment are adopted to improve recognition performance while maintaining the model's lightweight nature. The number of model parameters is reduced compared to the MobileNetV4-Conv-Small baseline, while maintaining or improving recognition accuracy. It is suitable for real-time deployment on mobile and edge devices and has good practicality and promotion value.
[0092] (3) Flexible convolution combination to adapt to different feature complexities: The EUIB block supports three flexible convolution combinations: IB, ConvNext, and ExtraDW. It dynamically selects different convolution kernel sizes and depth convolution configurations according to the network depth and feature complexity, so as to achieve a balance between computational efficiency and feature expression ability, and effectively adapt to the feature extraction needs of citrus diseases at different levels.
[0093] (4) Strategic attention deployment optimizes computational efficiency: The strategic attention deployment strategy is adopted. In the earliest layer, no attention mechanism is used to maintain computational efficiency. In the shallow and intermediate layers, ECA channel attention is mainly used to preserve detailed features. In the key downsampling layer and deep feature layer, ECA and MSAA dual attention are used to enhance the performance, so as to achieve a balance between computational efficiency and feature expression ability, and maintain a low inference latency while improving recognition accuracy.
[0094] (5) HardSwish activation function optimizes gradient flow: Both ECA and MSAA modules use the HardSwish activation function to replace the traditional Sigmoid function, providing better gradient flow and nonlinear modeling capabilities, which is particularly suitable for mobile deployment, improving model expressiveness while maintaining computational efficiency.
[0095] (6) Improved training strategies enhance model generalization ability: The AdamW optimizer, cosine annealing learning rate scheduling, label smoothing, early stopping mechanism and other improved training strategies effectively enhance the model's generalization ability and training stability, and achieve excellent performance in the citrus disease identification task. Attached Figure Description
[0096] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used together with the embodiments of the invention to explain the invention and do not constitute a limitation thereof.
[0097] Figure 1 The flowchart for DACNet: a lightweight citrus disease identification method based on a dual attention mechanism.
[0098] Figure 2 The overall network structure of DACNet: a lightweight citrus disease identification method based on a dual attention mechanism.
[0099] Figure 3 For DACNet: an efficient channel attention module in a lightweight citrus disease identification method based on a dual attention mechanism.
[0100] Figure 4 For DACNet: A lightweight citrus disease identification method based on dual attention mechanism, the multi-scale adaptive attention module.
[0101] Figure 5 This is the confusion matrix of the test set results for DACNet: a lightweight citrus disease identification method based on a dual attention mechanism. Detailed Implementation
[0102] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. Of course, the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0103] Example 1
[0104] See Figures 1 to 5 This embodiment provides a lightweight citrus disease identification method based on a dual attention mechanism, including the following steps:
[0105] Step S1: Data Acquisition and Preprocessing: Collect and organize digital images of citrus leaves in the citrus orchard, perform preprocessing on the images including data augmentation, size normalization and standardization, and use image annotation tools to annotate the preprocessed images to generate a training dataset containing category labels;
[0106] Its advantages are: effectively expanding the number of training samples, improving the robustness of the model to changes in actual scenes such as lighting changes, shooting angles, and leaf postures; facilitating model processing; accelerating model convergence and improving training stability.
[0107] The images of citrus diseased leaves include images of leaves with seven types of diseases: anthracnose, mottled yellowing, boron deficiency, canker, citrus oil spot, magnesium deficiency, and zinc deficiency, as well as images of healthy leaves, for a total of eight categories of targets.
[0108] The data augmentation includes at least one of the following operations: horizontal flip, vertical flip, random rotation, color dithering, random cropping, affine transformation, and random erasure.
[0109] The size normalization scales the image to 224×224 pixels;
[0110] The standardization process uses the standard mean and standard deviation of the ImageNet dataset for normalization. The mean is [0.485, 0.456, 0.406] and the standard deviation is [0.229, 0.224, 0.225]. Finally, the dataset is divided into training, validation and test sets in an 8:1:1 ratio.
[0111] Step S2 constructs the DACNet dual-attention lightweight classification model, such as... Figure 2 As shown, a lightweight classification model with dual attention in DACNet is constructed. The efficient channel attention module ECA and the multi-scale adaptive attention module MSAA of the lightweight classification model with dual attention are used to form a dual attention collaborative mechanism to enhance its ability to extract citrus disease features and the recognition accuracy.
[0112] Its advantages are as follows: It maintains mobile-friendliness based on the MobileNetV4-Conv-Small architecture; the ECA module adopts an extremely lightweight design, achieving efficient channel attention through one-dimensional convolution and the HardSwish activation function, enhancing sensitivity to the color features of citrus diseases; the MSAA module uses multi-scale depthwise separable convolution to extract spatial features at different scales, combining channel attention and residual gating hybrid connections to achieve spatial-channel joint attention enhancement, improving the detection capability of subtle lesions; the dual attention collaboration mechanism adopts a strategic deployment strategy, mainly using ECA to preserve detailed features in shallow and intermediate layers, and using ECA and MSAA dual attention collaboration enhancement in key downsampling layers and deep feature layers, achieving a balance between computational efficiency and recognition accuracy; the lightweight design (approximately 782K parameters, model size approximately 3MB) makes the model deployment friendly on mobile and edge devices, while achieving a recognition accuracy of 92.76%, superior to other lightweight models, meeting practical application needs.
[0113] Step S2.1: Construct a feature extraction backbone network (the core part for feature extraction) based on the MobileNetV4-Conv-Small architecture, and extract hierarchical features;
[0114] The MobileNetV4-Conv-Small architecture is used as the base network for the DACNet model (as a starting point or reference architecture).
[0115] The MobileNetV4-Conv-Small network (the entire model architecture, i.e., the MobileNetV4-Conv-Small architecture) is composed of efficient Stem modules and 10 enhanced general inverted bottleneck blocks (EUIBs) stacked together. Through its hierarchical structure, it outputs feature maps of different resolutions at different stages; just as... Figure 2 The MobileNetV4-Conv-Small network consists of a high-efficiency Stem module and 10 enhanced universal inverted bottleneck blocks (EUIBs). Through its hierarchical structure, it outputs feature maps of different resolutions at different stages. The high-efficiency Stem module adopts a progressive downsampling strategy to downsample the input image from 224×224 to 56×56, preserving more detailed features. The Stem module includes three operations: the first downsampling (224→112) uses standard convolution, the second downsampling (112→56) uses standard convolution combined with ECA channel attention enhancement, and the third feature enhancement (56→56) uses convolution combined with ECA attention to preserve spatial information. Then, the EUIB block sequence was used to further downsample the feature map from 56×56 to 28×28 (Block 4) and 14×14 (Block 6) to form a multi-scale feature representation. The high-resolution feature map (56×56) retains detailed information for the detection of subtle disease features, while the medium and low resolution feature maps (28×28, 14×14) extract high-level semantic information for global classification.
[0116] Step S2.2: Construct an efficient channel attention module (ECA)
[0117] Constructing an efficient channel attention module (ECA), such as Figure 3 As shown, it is applied after projection convolution and is responsible for learning the importance of global channel dimension features; the efficient channel attention module ECA uses one-dimensional convolution to achieve channel attention, with only 3-5 parameters, achieving extremely lightweight channel feature enhancement.
[0118] The calculation process of the ECA module is as follows: First, the input feature map is processed... Perform global average pooling to obtain channel descriptors. The calculation formula is as follows:
[0119] (1);
[0120] Where: B, C, H and W are the batch, channel, height and width of the feature map, respectively; Indicates the spatial location of all batches and channels. The value;
[0121] Then, the channel attention weights are calculated using one-dimensional convolution and the HardSwish activation function, with the following formula:
[0122] (2);
[0123] in: This is a one-dimensional convolution operation; the HardSwish activation function in formula (2) is defined as:
[0124] (3);
[0125] Where: x is the input of HardSwish (from the output of Conv1d), and ReLU6 is the modified linear unit 6 activation function as shown in formula (4).
[0126] (4);
[0127] Finally, the attention weights are multiplied by the input features, and the calculation formula is as follows:
[0128] (5);
[0129] in, This indicates element-wise multiplication. The sigmoid function normalizes the weights to the range [0.5, 1.5]. This is the enhanced output feature map.
[0130] Step S2.3: Construct the Multi-Scale Adaptive Attention Module (MSAA)
[0131] Construct a multi-scale adaptive attention module (MSAA), such as Figure 4 As shown, it is applied after the intermediate depth convolution, responsible for multi-scale spatial-channel joint feature enhancement; that is, the attention module MSAA is immediately following the intermediate depth convolution ( After that, projective convolution ( Previous applications have performed multi-scale spatial-channel joint feature enhancement on the extended channel feature maps output by intermediate-depth convolutions. The Multi-Scale Adaptive Attention Module (MSAA) uses multi-scale depthwise separable convolutions to extract spatial features at different scales, and combines this with a channel attention mechanism to achieve spatial-channel joint attention enhancement through residual-gated hybrid connections and a HardSwish activation function.
[0132] The calculation process of the MSAA module is as follows: First, calculate the channel attention weights (the same as the ECA module), and the calculation formula is:
[0133] (6);
[0134] in: Channel attention weights; AvgPool is the average pooling operation;
[0135] Then, channel compression and spatial feature extraction are performed. Spatial features are extracted through multi-scale depthwise convolution, and the calculation formula is as follows:
[0136] (7);
[0137] (8);
[0138] in: The feature map is compressed from the channel; DWConv3×3 and DWConv5×5 are 3×3 and 5×5 depthwise separable convolutions, respectively; The output feature map is a 3×3 depth separable convolution. The output feature map is a 5×5 depth separable convolution.
[0139] Multi-scale feature fusion, its calculation formula is as follows:
[0140] (9);
[0141] in, The fusion weights are the outputs of the 3×3 convolution; The fusion weights are the output of the 5×5 convolution;
[0142] Then, the spatial attention weights are calculated using the following formula:
[0143] (10);
[0144] Where: Conv5×5 is a 5×5 convolution;
[0145] Finally, the output is obtained through residual-gated hybrid connection, and its calculation follows the formula:
[0146] (11);
[0147] LayerScale is the layer scaling operation used for stable training. For the input feature map, This is the enhanced output feature map.
[0148] Step S2.4: Construct the Enhanced General Inverted Bottleneck Block EUIB
[0149] An enhanced general inverted bottleneck block (EUIB) is constructed, supporting three flexible convolution combination strategies: IB, ConvNext, and ExtraDW. The enhanced general inverted bottleneck block (EUIB) dynamically selects different convolution kernel sizes and depth convolution configurations based on network depth and feature complexity, achieving a balance between computational efficiency and feature representation capability.
[0150] The IB block structure includes: first, performing a 1×1 expanding convolution to increase the number of channels; then performing a 3×3 or 5×5 depthwise separable convolution (DWConv) to extract spatial features; and finally performing a 1×1 projective convolution to compress the number of channels.
[0151] ConvNext Block Structure: The ConvNext block structure includes: first, a 3×3 StartDW convolution is performed to extract preliminary spatial features, then a 1×1 Expand convolution is performed to expand the number of channels, and finally a 1×1 Project convolution is performed to compress the number of channels.
[0152] ExtraDW Block Structure: The ExtraDW block structure includes: first, a 3×3 or 5×5 StartDW convolution is performed for preliminary spatial feature extraction, then a 1×1 Expand convolution is performed to expand the number of channels, followed by a 3×3 or 5×5 MiddleDW convolution for depth feature extraction, and finally a 1×1 Project convolution is performed to compress the number of channels.
[0153] Step S2.5: Dual Attention Coordination Mechanism and its Strategic Deployment
[0154] The dual-attention collaborative mechanism adopts a strategic attention deployment strategy: no attention mechanism is used in the earliest layer to maintain computational efficiency, ECA channel attention is mainly used in the shallow and intermediate layers to preserve detailed features, and ECA and MSAA dual attention are used in the key downsampling layer and deep feature layer to achieve a balance between computational efficiency and feature representation capability.
[0155] Taking 10 enhanced general inverted bottleneck blocks as an example, in the 10 enhanced general inverted bottleneck blocks EUIB, block 0 does not use the attention mechanism, blocks 1-4 and 6-8 mainly use ECA channel attention, and blocks 5 and 9 use ECA and MSAA dual attention synergistic enhancement.
[0156] Step S2.6: Lightweight Design Strategy
[0157] The DACNet model uses a width multiplier. By reducing the number of channels and employing depthwise separable convolutions to reduce the number of parameters, and by optimizing the divisibility of the number of channels to achieve a hardware-friendly design, the final model has fewer parameters compared to previous models. The baseline is reduced while maintaining or improving recognition accuracy.
[0158] Step S3: Model Training: Based on the training dataset described in Step S1, the AdamW optimizer is used, employing a labeled smooth cross-entropy loss function combined with a cosine annealing learning rate restart scheduling strategy to iteratively train the DACNet dual-attention lightweight classification model constructed in Step S2 until the model performance metrics meet the preset requirements, thus obtaining the trained classification model. Its advantages are: the labeled smooth cross-entropy loss function (smoothing coefficient 0.1) converts hard labels into soft labels, reducing overfitting of the model to training samples and improving generalization ability, making it particularly suitable for citrus disease datasets with relatively imbalanced classes; the AdamW optimizer combines Adam's adaptive learning rate and weight decay regularization, automatically adjusting the learning rate of different parameters, accelerating convergence and improving training stability, with a weight decay coefficient of 1×10⁻. 4 Effectively prevents overfitting; the cosine annealing learning rate restart scheduling strategy enables the model to escape local optima and explore a better parameter space by periodically restarting the learning rate. The initial period T0 = 10 and the period multiple T... mult The design of =2 ensures that the training process has both a stable convergence phase and an exploration phase, improving the final performance of the model. The iterative training process is combined with an early stopping mechanism (stopping when the performance on the validation set does not improve for 20 consecutive epochs), avoiding overfitting and saving training time. This combination of training strategies enables the DACNet model to achieve a recognition accuracy of 92.76% while maintaining its lightweight nature, meeting the needs of practical applications.
[0159] Specifically, the network training uses the AdamW optimizer with an initial learning rate of 0.0008 and a weight decay coefficient of [value missing]. The batch size is 16; a cosine annealing learning rate scheduling strategy is used, and the learning rate is updated after each training epoch. The initial period is... Cycle multiplication factor The minimum learning rate is Label smoothing technology is used, with a smoothing coefficient of [missing information]. An early stopping mechanism is used during training. Training is stopped early when the accuracy of the validation set does not improve for 20 consecutive rounds, and the model weight with the highest disease recognition rate on the validation set is selected.
[0160] The cross-entropy loss function is defined as:
[0161] (12);
[0162] in: These are real labels that have undergone label smoothing processing. The model predicts probabilities; i: sample index, i=1,2,...,N, where N is the batch size; c: class index, c=1,2,...,C, where C is the number of classes (8 classes);
[0163] The formula for label smoothing is:
[0164] (13);
[0165] in, For smoothing coefficients; For the original The encoded true labels; C is the number of categories; label smoothing is performed on the true labels before calculating the cross-entropy loss function. Replace the 1 in the tag with Replace 0 with .
[0166] The labeled smoothed cross-entropy loss function is "composite" in the following way:
[0167] First, perform label smoothing on the real labels, and... Label Convert to smooth label The smoothing formula is shown in formula (13);
[0168] Then use the smoothed label. The cross-entropy loss is calculated using the following formula:
[0169] (14);
[0170] in The smoothing coefficient is 0.1; The label is smoothed out; Predict probabilities for the model;
[0171] Label smoothing is integrated into the internal calculation of the cross-entropy loss function, rather than being treated as a separate loss term. PyTorch's CrossEntropyLoss achieves this through... The parameters enable this integration.
[0172] Step S4: Model Inference and Recognition: Employing the same preprocessing workflow and lightweight forward inference as the training phase, the preprocessed images to be detected are input into the trained DACNet model to achieve efficient and accurate citrus disease classification. This method offers advantages such as consistent preprocessing, fast inference speed, lightweight model, and ease of deployment. Combined with a dual attention mechanism, it achieves high recognition accuracy while maintaining a lightweight design, meeting the real-time application requirements of mobile devices.
[0173] Specifically, in step S4, forward inference is performed, progressive downsampling is performed through the efficient Stem module, feature extraction and dual attention enhancement are performed through several (10) enhanced general inverted bottleneck blocks EUIB, and the probability distributions of several classes (8 classes) are output through global average pooling and classification head to obtain the final recognition result.
[0174] In this embodiment, to comprehensively evaluate the performance of different network architectures, a lightweight citrus disease identification method based on a dual attention mechanism was tested, and a corresponding confusion matrix was generated, as shown below. Figure 5 As shown. Based on the confusion matrix, the true positive (TP), true negative (TN), false positive (FP), and false negative (FN) values for each category are further extracted. Subsequently, these values are used to calculate the accuracy, precision, recall, and F1 score for each category. The specific calculation formula is shown in Equation 15-18.
[0175] (15);
[0176] (16);
[0177] (17);
[0178] (18);
[0179] Table 1. Experimental results of the method in this embodiment on the citrus disease test set:
[0180]
[0181] Example 2
[0182] Building upon Example 1, to further evaluate the performance advantages of DACNet over other networks, comparative experiments were conducted on the same self-built citrus disease dataset. All networks were implemented using the PyTorch framework and trained on an NVIDIA GeForce RTX 4060 Laptop. The AdamW optimizer was used to optimize the entire network parameters, with the following hyperparameter settings: initial learning rate of 0.0008, and exponential decay rate for first-moment estimation. The exponential decay rate estimated by the second moment The weight decay coefficient is set to eps set to The learning rate scheduling strategy is restarted using cosine annealing; a labeled smoothed cross-entropy loss function is used with a label smoothing coefficient of 0.1 to improve generalization ability; the training batch size is set to 16, all models are trained for 100 epochs, and an early stopping mechanism is adopted, which stops training when the performance on the validation set does not improve for 20 consecutive epochs to avoid overfitting.
[0183] Table 2. Performance evaluation of citrus leaf disease identification compared to 10 other models:
[0184]
[0185] Classic lightweight classification models such as EfficientNet, GhostNet, MobileNet, MobileVit, and ShuffleNet are widely used in citrus disease identification tasks and serve as comparative baselines. Therefore, we conducted experiments on these classification models on the dataset of this invention and compared them with our model under the same training parameter settings. As shown in Table 2, MobileNetV3 has the fewest parameters, followed by our DACNet; in terms of accuracy, recall, and... In terms of accuracy, ResNet18 performed the worst in the citrus disease identification task, achieving only 85.71% accuracy on the test set. However, it still achieved higher accuracy than other classic lightweight classification models such as EfficientNet, GhostNet, MobileNet, MobileVit, and ShuffleNet. Meanwhile, as shown in the table, compared to other classic classification models, DACNet achieved the best values in accuracy, recall, and F1 score, with an accuracy of 92.76%. This demonstrates DACNet's advantage in citrus disease identification. This invention can accurately identify eight types of citrus disease states, significantly improving identification accuracy while maintaining a lightweight model, thus enhancing the automation level and accuracy of intelligent citrus disease diagnosis.
[0186] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A lightweight citrus disease identification method based on a dual attention mechanism, characterized in that, Includes the following steps: Step S1: Data Acquisition and Preprocessing: Collect and organize digital images of citrus leaves in the citrus orchard, perform preprocessing on the images including data augmentation, size normalization and standardization, and use image annotation tools to annotate the preprocessed images to generate a training dataset containing category labels; Step S2: Construct the DACNet dual-attention lightweight classification model: Utilize the efficient channel attention module ECA and the multi-scale adaptive attention module MSAA of the DACNet dual-attention lightweight classification model to form a dual-attention collaborative mechanism, thereby enhancing its ability to extract and identify citrus disease features. Step S3: Model Training: Based on the training dataset described in Step S1, the AdamW optimizer is used, along with a labeled smooth cross-entropy loss function and a cosine annealing learning rate restart scheduling strategy. The DACNet dual-attention lightweight classification model constructed in Step S2 is iteratively trained until the model performance metrics meet the preset requirements, and the trained classification model is obtained. Step S4 Model Inference and Recognition: Using the same preprocessing process and lightweight forward inference as the training phase, the images to be detected are preprocessed and then input into the trained DACNet model to achieve citrus disease classification.
2. The lightweight citrus disease identification method based on a dual attention mechanism according to claim 1, characterized in that: In step S1: The images of citrus diseased leaves include images of leaves with seven types of diseases: anthracnose, mottled yellowing, boron deficiency, canker, citrus oil spot, magnesium deficiency, and zinc deficiency, as well as images of healthy leaves, for a total of eight categories of targets. The data augmentation includes at least one of the following operations: horizontal flip, vertical flip, random rotation, color dithering, random cropping, affine transformation, and random erasure. The size normalization scales the image to 224×224 pixels; The standardization process uses the standard mean and standard deviation of the ImageNet dataset for normalization.
3. The lightweight citrus disease identification method based on a dual attention mechanism according to claim 1, characterized in that: Step S2 includes the following steps: Step S2.1: Construct a feature extraction backbone network based on the MobileNetV4-Conv-Small architecture and extract hierarchical features; The MobileNetV4-Conv-Small architecture is used as the base network for the DACNet model; The MobileNetV4-Conv-Small network is composed of a high-efficiency Stem module and 10 enhanced general inverted bottleneck blocks (EUIBs) stacked together. Through its hierarchical structure, it outputs feature maps of different resolutions at different stages. The high-efficiency Stem module employs a progressive downsampling strategy; Step S2.2: Construct an efficient channel attention module (ECA); Step S2.3: Construct the multi-scale adaptive attention module MSAA; Step S2.4: Construct the enhanced general inverted bottleneck block EUIB; Step S2.5: Dual Attention Coordination Mechanism and its Strategic Deployment; Step S2.6: Adopt a lightweight design strategy.
4. The lightweight citrus disease identification method based on a dual attention mechanism according to claim 3, characterized in that: Step S2.2 specifically includes: The efficient channel attention module (ECA) uses one-dimensional convolution to achieve channel attention. The calculation process of the ECA module is as follows: For input features Perform global average pooling to obtain channel descriptors. The calculation formula is as follows: (1); Where: B, C, H and W are the batch, channel, height and width of the feature map, respectively; Indicates the spatial location of all batches and channels. The value; Channel attention weights are calculated using one-dimensional convolution and the HardSwish activation function, and the formula is as follows: (2); in: This is a one-dimensional convolution operation; The HardSwish activation function in formula (2) is defined as follows: (3); Where: x is the input of HardSwish, and ReLU6 is the modified linear unit 6 activation function as shown in formula (4); (4); The attention weights are multiplied by the input features, and the calculation formula is as follows: (5); in, This indicates element-wise multiplication. The sigmoid function normalizes the weights to the range [0.5, 1.5]. This is the enhanced output feature map.
5. A lightweight citrus disease identification method based on a dual attention mechanism according to claim 3, characterized in that: Step S2.3 specifically includes: The attention module MSAA is applied after intermediate depth convolution and is responsible for multi-scale spatial-channel joint feature enhancement. The Multi-Scale Adaptive Attention Module (MSAA) uses multi-scale depthwise separable convolution to extract spatial features at different scales. Combined with a channel attention mechanism, it achieves spatial-channel joint attention enhancement through residual gated hybrid connections and HardSwish activation function. The calculation process of the MSAA module is as follows: The channel attention weights are calculated using the following formula: (6); Where: w c Channel attention weights; AvgPool is the average pooling operation; Channel compression and spatial feature extraction are performed. Spatial features are extracted through multi-scale depthwise convolution. The formula for multi-scale depthwise convolution is as follows: (7); (8); in: The feature map is compressed from the channel; DWConv3×3 and DWConv5×5 are 3×3 and 5×5 depthwise separable convolutions, respectively; The output feature map is a 3×3 depth separable convolution. The output feature map is a 5×5 depth separable convolution. Multi-scale feature fusion, its calculation formula is as follows: (9); in, The fusion weights are the outputs of the 3×3 convolution; The fusion weights are the output of the 5×5 convolution; The spatial attention weights are calculated using the following formula: (10); Where: Conv5×5 is a 5×5 convolution; The calculation formula for the output via residual gated hybrid connection is: (11); LayerScale represents the layer scaling operation. For the input feature map, This is the enhanced output feature map.
6. The lightweight citrus disease identification method based on a dual attention mechanism according to claim 3, characterized in that: Step S2.4 specifically includes: The Enhanced Universal Inverted Bottleneck Block (EUIB) supports three convolution combination strategies: IB, ConvNext, and ExtraDW. The Enhanced Universal Inverted Bottleneck Block (EUIB) dynamically selects different convolution kernel sizes and depth convolution configurations based on network depth and feature complexity.
7. A lightweight citrus disease identification method based on a dual attention mechanism according to claim 3, characterized in that: Step S2.5 specifically includes: The dual attention collaboration mechanism adopts a strategic attention deployment strategy: no attention mechanism is used in the earliest layer to maintain computational efficiency, ECA channel attention is mainly used in the shallow and intermediate layers to preserve detailed features, and ECA and MSAA dual attention collaboration is used in the key downsampling layer and deep feature layer for enhancement. In the 10 enhanced general inverted bottleneck blocks EUIB, block 0 does not use an attention mechanism, blocks 1-4 and 6-8 mainly use ECA channel attention, and blocks 5 and 9 use ECA and MSAA dual attention synergistic enhancement.
8. A lightweight citrus disease identification method based on a dual attention mechanism according to claim 3, characterized in that: Step S2.6 specifically includes: The DACNet model uses a width multiplier. Reduce the number of channels, use depthwise separable convolution to reduce the number of parameters, and achieve a hardware-friendly design by optimizing the divisibility of the number of channels.
9. A lightweight citrus disease identification method based on a dual attention mechanism according to claim 1, characterized in that: In step S3: The network was trained using the AdamW optimizer; A cosine annealing learning rate scheduling strategy is adopted, and the learning rate is updated after each training epoch. Label smoothing technology is used, with a smoothing coefficient. During training, an early stopping mechanism is used. Training is stopped early when the accuracy on the validation set does not improve for 20 consecutive rounds, and the model weight with the highest disease recognition rate on the validation set is selected. The cross-entropy loss function is defined as: (12); in: These are real labels that have undergone label smoothing processing. Predict probabilities for the model; i: sample index, i=1,2,...,N, where N is the batch size; c: class index, c=1,2,...,C, where C is the number of classes; The formula for label smoothing is: (13); Where: smoothing coefficient ; For the original The encoded true labels; C is the number of categories; label smoothing is performed on the true labels before calculating the cross-entropy loss function. Replace the 1 in the tag with Replace 0 with ; A composite loss function that includes cross-entropy loss and label smoothing is adopted; Perform label smoothing on real labels to remove one-hot labels. Convert to smooth label ; Use smoothed labels The cross-entropy loss is calculated using the following formula: (14); in The smoothing coefficient is 0.1; The label is smoothed out; Predict probabilities for the model.
10. A lightweight citrus disease identification method based on a dual attention mechanism according to claim 1, characterized in that: The forward inference described in step S4 involves progressive downsampling through an efficient Stem module, feature extraction and dual attention enhancement through several enhanced general inverted bottleneck blocks (EUIB), and the final recognition result is obtained by outputting several class probability distributions through global average pooling and a classification head.