Blueberry freshness classification and quality detection method based on lightweight network
By using the improved lightweight network DHAF-Net, the accuracy problem of nine-level classification of blueberry freshness on low computing power devices is solved. It achieves efficient and accurate feature representation and cross-scale information interaction, and is suitable for mobile and edge devices, simultaneously outputting blueberry freshness and physicochemical quality indicators.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- QINGDAO UNIV OF TECH
- Filing Date
- 2026-04-24
- Publication Date
- 2026-07-14
AI Technical Summary
Existing lightweight models struggle to achieve high-precision nine-level classification of blueberry freshness on low-computing-power devices, and traditional deep learning networks have shortcomings in feature representation and cross-scale information interaction, particularly in their insufficient ability to distinguish features of similar or near-similar levels.
An improved lightweight network, DHAF-Net, is adopted. By replacing the SE attention module of MobileNetV3-Small with the parallel channel-coordinate attention module ParallelSECA, and embedding a dilated convolution sequence optimization module, combined with the cross-dimensional dynamic combination multi-head attention module CrossDimDCMHAttention, multi-scale feature adaptive interaction and global fusion are achieved.
It significantly improves the accuracy of blueberry freshness classification, is compatible with mobile and edge device deployment, and enables simultaneous detection of blueberry freshness grades and physicochemical quality indicators, reducing detection costs and operational complexity.
Smart Images

Figure CN122391736A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of intelligent grading and detection technology of fruit freshness, specifically involving a method for classifying and detecting the freshness and quality of blueberries based on lightweight networks. Background Technology
[0002] Blueberries, with their thin skin and juicy flesh, are prone to rapid freshness loss after harvesting due to respiration and microbial contamination. Furthermore, the taste, nutritional value, and other quality characteristics of blueberries are highly dependent on their freshness level. Unripe blueberries tend to be firm, highly tart, and lack typical flavor characteristics; overripe blueberries soften and rot easily, losing their commercial value. Therefore, post-harvest quality control of blueberries directly impacts both the economic benefits for businesses and the consumer experience. Traditional methods for testing blueberry freshness primarily rely on manual inspection, involving observing the skin color and the degree of bloom coverage, manually pressing to assess firmness, and tasting to evaluate sweetness. However, these methods are highly subjective, prone to error, and unsuitable for batch testing. While destructive laboratory testing can provide information such as sugar and organic acid content to objectively evaluate freshness and quality, it damages fruit samples and cannot meet the needs of post-harvest grading, storage monitoring, and automated online testing. Therefore, accurate, efficient, and non-destructive testing of post-harvest blueberries is a current research hotspot and a core requirement for ensuring stable quality of blueberries "from harvest to shelf" for businesses and providing consumers with reliable products.
[0003] In practical applications of post-harvest fruit inspection, the accuracy and ease of deployment of models must be highly coordinated. Whether it's consumer handheld devices for inspection or edge devices in the transportation quality inspection process, both are limited by computing power and power consumption. Traditional deep learning networks, due to their large number of parameters and high computational cost, are difficult to adapt to such mobile portable devices or edge inspection devices. However, the MobileNet series of networks, through its lightweight architecture design, achieves low computing power consumption, low memory usage, and high inference speed while ensuring detection accuracy, gradually becoming the preferred choice for mobile deployment in the fruit inspection field. Currently, lightweight models in the fruit inspection field generally adopt a single-branch backbone network structure, leaving significant room for optimization in multi-scale feature extraction and fusion. Features at different scales can typically capture information at different levels; low-level features focus on shape and contour, while high-level features focus on abstract semantic features. Aggregating features at different scales can better meet the complex practical needs of fruit freshness detection. Furthermore, attention mechanisms allow the model to ignore redundant information and focus on key features, improving detection effectiveness by suppressing noise interference. However, the MobileNet series of models were designed for lightweight deployment on mobile devices. They sacrifice some accuracy in exchange for fast classification on low-computing-power devices. However, the nine-class classification task of Blueberry is relatively complex, and it is difficult even for humans to classify it by eye. Therefore, the lightweight design of MobileNet results in relatively limited feature representation capabilities, especially insufficient discrimination of similar or close-level features. Summary of the Invention
[0004] To address the industry pain point that existing lightweight models struggle to balance low-computing deployment with high-precision identification of nine levels of freshness, this invention proposes a blueberry freshness classification and quality detection method based on lightweight networks. This method overcomes the technical shortcomings of traditional single-branch lightweight networks, such as insufficient feature representation, weak cross-scale information interaction, and attention mechanisms that focus only on channels and lose spatial location information. It solves the above-mentioned deficiencies of existing technologies and has good application results.
[0005] To achieve the above objectives, the present invention adopts the following technical solution: A method for blueberry freshness classification and quality detection based on lightweight networks includes the following steps: S1. Collect blueberry images of different freshness levels and construct a blueberry freshness image dataset containing multiple freshness levels; S2. Construct the blueberry freshness classification network DHAF-Net, which is obtained by improving the MobileNetV3-Small network structure as follows: S2.1 Replace the native SE attention module in the MobileNetV3-Small network with a parallel channel-coordinate attention module to enhance the perception of joint channel and spatial features; S2.2. After the parallel channel-coordinate attention module, a dilated convolution sequence optimization module is co-embedded to expand the receptive field and capture long-distance feature dependencies; S2.3 Extract three sets of semantic level features (low, medium, and high) from the improved network structure, input them into the cross-dimensional dynamic combination multi-head attention module, realize multi-scale feature adaptive interaction and global fusion, and output the final fused features. S2.4 Connect the classification head and output the classification probability of blueberry freshness based on the fusion features; S3. Train the blueberry freshness classification network DHAF-Net using the blueberry freshness image dataset; S4. Input the blueberry image to be detected into the trained blueberry freshness classification network DHAF-Net, and output the freshness classification result.
[0006] Furthermore, in S1, images of blueberries are collected at different times of the day, under different lighting conditions, and from multiple shooting angles, and the collection continues until the blueberries reach an inedible state; the freshness level is divided into nine categories based on the number of days of storage.
[0007] Furthermore, in S2.1, eight feature layers are selected from the MobileNetV3-Small network and divided into three low-dimensional feature layers, three mid-dimensional feature layers, and two high-dimensional feature layers; the two low-dimensional feature layers, three mid-dimensional feature layers, and one high-dimensional feature layer are respectively input into the parallel channel-coordinate attention module; The parallel channel-coordinate attention module includes an SE branch, a CA branch, and an adaptive fusion unit. It dynamically learns the weights of the two attention branches based on the input features to achieve adaptive fusion of channel attention and coordinate attention. The SE branch first performs global average pooling on the input feature map, compressing the spatial information into a 1×1 shape, as shown in the expression: ; in, It is a feature in the spatial dimension The result after performing global average pooling. For input features; Then, the number of channels is increased from the first fully connected layer. Reduced to Simultaneously, nonlinearity is introduced through ReLU activation, resulting in... The expression is: ; in, and The weights and biases of the first fully connected layer. Represents the ReLU function; The number of channels is restored using the second fully connected layer. The weights are then mapped to the [0,1] interval via Sigmoid activation to obtain the channel attention weights, expressed as: ; in, and For the weights and biases of the second fully connected layer, Represents the sigmoid function; Finally, a weighted output is performed, where the channel attention weights are multiplied element-wise by the input feature map, as shown in the expression: ; in, This represents element-wise multiplication; The CA branch first performs average pooling on the input feature map along both the height and width directions, as expressed by: ; ; in, and These are the results of average pooling the feature maps along the height and width directions, respectively. Then, channel compression is performed in both directions using a 1×1 convolution, expressed as follows: ; ; in, and These represent the spatial features after compression in two directions, respectively. The compressed spatial features are reshaped and used as input to the fully connected layer, which then generates weights in two directions: ; ; in, , These are the weights in the two directions, respectively; Then, spatial weight fusion is performed to obtain the final coordinate attention weights: ; Finally, a weighted output is performed, where the coordinate attention weights are multiplied element-wise by the input feature map, as shown in the expression: ; The adaptive fusion unit is used to weightedly fuse the outputs of the SE branch and the CA branch to obtain the final output of the module. First, the two attention weights are averaged along all non-batch dimensions to obtain the branch importance score for each sample. and : ; ; The scores are stacked, mapped through a fully connected layer, and activated by Softmax to convert the branch scores into normalized fusion weights. : ; Finally, the fusion weights are multiplied by the outputs of the SE branch and the CA branch respectively, and then summed. The expression is: ; ; in, , .
[0008] Furthermore, in S2.2, the six features processed by the parallel channel-coordinate attention module, together with the other two original features not processed by the parallel channel-coordinate attention module, for a total of eight features, are input into the dilated convolution sequence optimization module. This module flattens the feature map into a sequence, uses multi-dip rate one-dimensional convolution in parallel processing, and restores the spatial dimension after splicing, residual connection, and layer normalization. This expands the receptive field without significantly increasing the computational load and enhances the ability to capture long-distance feature dependencies.
[0009] The dilated convolution sequence optimization module performs the following operations: Input feature map The spatial dimension is flattened into a length of sequence : ; Will Each channel is assigned to Each with different void ratios The sequence is processed in parallel by one-dimensional convolutional branches to obtain the output of each branch. : ; The outputs of the K branches are concatenated along the channel dimension to obtain the result. : ; Will and Obtain by performing residual connection : ; right Layer normalization is performed to obtain : ; Will Restore spatial dimensions as module output : ; in .
[0010] Furthermore, after the output of the dilated convolution sequence optimization module, a skip residual connection and a batch normalization layer are introduced to stabilize the feature distribution, alleviate training gradient oscillations and overfitting, and ensure the consistency of feature inputs at multiple scales.
[0011] Furthermore, in S2.3, the outputs of the three low-dimensional features and two high-dimensional features processed by the dilated convolution sequence optimization module are added element-wise to obtain the fused low-dimensional features. and the high-dimensional features of fusion The residuals of the outputs from the three mid-dimensional features processed by the dilated convolution sequence optimization module are summed to obtain the fused mid-dimensional features. ; The cross-dimensional dynamic multi-head attention module performs the following operations: Input low-dimensional features Mid-dimensional characteristics High-dimensional features Mapped to the same dimension through linear layers respectively To obtain the mapping features , , ; The mapped features are concatenated into a token sequence. : ; will sequence The projections are respectively onto the Query matrix Q, Key matrix K, and Value matrix V; Calculate the original dot product : ; right Attention probabilities are obtained through Softmax. : ; Calculate single-head attention output: ; Concatenate all single-head attention outputs along the feature dimension to obtain the multi-head attention output. Perform residual connections and layer normalization on the multi-head attention output: ; set up The three token vectors in the data are as follows: , , These correspond to the fused representations of the low-dimensional, mid-dimensional, and high-dimensional features of the input, respectively. The final scale-fused feature output is: .
[0012] Furthermore, after obtaining the freshness classification result in step S4, a quality prediction step S5 is also included: based on the freshness classification result, a predefined mapping relationship is queried to obtain the predicted values of one or more physicochemical quality indicators of blueberries. The mapping relationship is established in the following way: under known storage conditions, the physicochemical indicators of blueberry samples with different freshness grades are measured, and a statistical model between freshness grade and physicochemical indicators is established. The statistical model is a quadratic polynomial regression model. The physicochemical indicators include at least one of weight, firmness, and sweetness.
[0013] The beneficial technical effects of this invention are as follows: The model in this invention uses a multi-dimensional feature extraction framework to extract features hierarchically, achieving full coverage of low, medium, and high dimensions, and accurately capturing key information at different scales. The CrossDimDCMHAttention module maps low, medium, and high-dimensional features to a unified dimension, uncovering the correlation between features at different scales, improving the overall integrity of feature representation, and solving the problems of isolated features and insufficient information complementarity at different scales in traditional models. Using MobileNetV3Small as the backbone network, the native SE module is replaced by the ParallelSECA module, and the DilatedConvSeqOptimizer module is combined to specifically address the problem that the native model is insufficient in capturing fine-grained features such as blueberry skin wrinkles and color gradients. High classification accuracy was achieved on independent test sets, significantly outperforming mainstream models such as AlexNet and DenseNet-121, and it can accurately distinguish similarity levels, meeting the practical requirement of 9-level classification of blueberries after harvest. The model achieves module synergy gains through specific level selection, dynamic fusion, and residual stability constraints. It maintains lightweight and high accuracy with a slight increase in the number of parameters, and is suitable for deployment on mobile and edge devices with low computing power. It solves the limitation that high accuracy of existing deep learning models usually requires high computing power, and provides a reliable solution for the field deployment of classification models for post-harvest blueberry grading. An innovative quadratic multinomial regression mapping model was constructed to correlate blueberry freshness grades with key quality indicators (weight, firmness, and sweetness). Based on visual freshness classification results, the model simultaneously outputs predicted quantitative quality indicators for fruit weight (g), firmness (N), and sweetness (°Brix). Compared to traditional methods, this approach eliminates steps such as physical testing and chemical analysis, achieving integrated testing from qualitative grading to quantitative assessment. This reduces equipment costs and operational complexity for post-harvest testing, enhancing its practicality for the industry. Attached Figure Description
[0014] Figure 1 This is a schematic diagram of the DHAF-Net structure in this invention.
[0015] Figure 2 This is a schematic diagram of the parallel channel-coordinate attention module structure in this invention.
[0016] Figure 3 This is a schematic diagram of the structure of the holed convolution sequence optimization module in this invention.
[0017] Figure 4 This is a schematic diagram of the cross-dimensional dynamic combination multi-head attention module structure in this invention.
[0018] Figure 5 This is a graph showing the daily temperature and relative humidity during blueberry storage.
[0019] Figure 6 This is a schematic diagram showing the distribution of blueberries at different freshness levels.
[0020] Figure 7 Images of blueberries at different levels of freshness.
[0021] Figure 8 A diagram illustrating the comparison of accuracy for different network models.
[0022] Figure 9 This is a schematic diagram of a confusion matrix; (a) is a schematic diagram of the confusion matrix of the model of the present invention; (b) is a schematic diagram of the confusion matrix of the MobileNetV3-Small model.
[0023] Figure 10 A graph showing the fitting results of the variation trend of blueberry physicochemical properties with storage days; Among them, (a) is a graph showing the trend of blueberry weight with the number of storage days, (b) is a graph showing the trend of blueberry firmness with the number of storage days, and (c) is a graph showing the trend of blueberry sweetness with the number of storage days. Detailed Implementation
[0024] The specific embodiments of the present invention will be further described below with reference to specific examples: A lightweight blueberry freshness classification and quality detection method based on convolutional neural networks includes the following steps: S1. Collect blueberry images of different freshness levels and construct a blueberry freshness image dataset containing multiple freshness levels; In S1, images of blueberries are collected at different times of the day, under different lighting conditions (natural light, flash), and from multiple shooting angles, and are continuously collected until the blueberries are no longer edible; they are then divided into nine freshness levels based on the number of days they have been stored.
[0025] S2. Construct the blueberry freshness classification network DHAF-Net, which is obtained by improving the pre-trained MobileNetV3-Small as the backbone network as follows: S2.1 Replace the native SE attention module in the MobileNetV3-Small network with the parallel channel-coordinate attention module ParallelSECA to enhance the perception of joint channel and spatial features; S2.2. An attenuated convolution sequence optimization module is embedded after the ParallelSECA parallel channel-coordinate attention module to expand the receptive field and capture long-distance feature dependencies. S2.3 Extract three groups of features at different semantic levels (low, medium, and high) from the improved network structure and input them into the cross-dimensional dynamic multi-head attention module CrossDimDCMHAttention to achieve multi-scale feature adaptive interaction and global fusion output of the final fused features. S2.4 Connect the classification head, which is used to output the classification probability of blueberry freshness based on the fusion features; The SE attention introduced in MobileNetV3 enhances the network's ability to focus on key features, adapting to the needs of lightweight deployment, real-time operation, and fine-grained feature capture in practical applications of blueberry freshness detection. Based on network depth and the amount of computational resources required, MobileNetV3 is further divided into Small and Large models to meet the different accuracy or efficiency requirements of different tasks. Their structures and related parameters are shown in Tables 1 and 2.
[0026] Table 1 MobileNetV3-Small Structure ; Table 2 MobileNetV3-Large Structure ; While the MobileNetV3 model boasts excellent performance, its network architecture is a general model balancing speed and accuracy. It only uses simplified channel attention (Squeeze-and-Excitation) in some layers and does not consider the spatial relationships of features. Furthermore, MobileNetV3's ability to learn associations between features at different scales is poor. The feature distribution of blueberries at different freshness levels exhibits multi-scale characteristics, making feature extraction and fusion from different scales crucial. In addition, in image classification tasks, target features often exhibit non-local associations; traditional convolutional receptive fields are limited to local regions, making it difficult to capture such long-distance dependencies. To address these issues, this invention, based on a pre-trained MobileNetV3-Small network, designs a multi-stage feature fusion architecture. Specific layers are selected for feature extraction. To improve the model's spatial awareness and enhance the learning ability of important features, this invention proposes a parallel SECA attention module to replace the SE attention mechanism in the feature extraction stage, combined with dilated convolutions to further expand the receptive field and strengthen long-distance feature dependencies. A dynamically composable multi-head attention mechanism is also adopted in the cross-dimensional feature fusion stage to enhance cross-scale feature interactions.
[0027] The DHAF-Net network architecture designed in this invention is as follows: Figure 1 As shown, using MobileNetV3-Small as the backbone network, this method significantly improves fine-grained classification performance while maintaining extremely low computational complexity. The network input is a 112×112 RGB image, and the final output is the probability of a 9-category classification of blueberry freshness. The entire model achieves stronger feature representation and fusion capabilities and better classification performance while maintaining a parameter count close to that of MobileNetV3-Small.
[0028] Eight representative feature extraction layers were selected from MobileNetV3-Small, which are divided into low-dimensional features, medium-dimensional features and high-dimensional features. They cover everything from shallow texture details to deep semantic feature information. The extracted feature layers are shown in Table 3.
[0029] Table 3 Feature layers extracted by the model ; The core idea of attention mechanisms originates from the selective attention mechanism of the human visual system. By dynamically calculating the weight distribution of features, it strengthens the representation of key features and weakens irrelevant information, thereby improving the feature extraction efficiency and classification performance of the model. In recent years, attention mechanisms have become a key technology for improving model performance. In the blueberry freshness classification task, image features often have large scale differences, sparse key features, and are easily affected by environmental interference. The original SE in MobileNetV3-Small only captures global information in the channel dimension, ignoring spatial location sensitivity. The currently popular CBAM hybrid attention mechanism uses fixed concatenation, which cannot adaptively adjust the fusion ratio according to the characteristics of features at different levels. To address the above problems, this invention proposes a parallel channel-coordinate attention module, ParallelSECA, which replaces the original SE attention module with the core idea of parallel computing and dynamic fusion. An additional parallel SECA attention block is inserted at the third low-dimensional level, thereby achieving full feature recalibration and solving the limitations of traditional attention mechanisms.
[0030] In S2.1, eight feature extraction layers are selected from the MobileNetV3-Small network; they are divided into three low-dimensional feature layers, three mid-dimensional feature layers, and two high-dimensional feature layers; the two low-dimensional feature layers, the three mid-dimensional feature layers, and the one high-dimensional feature layer are respectively input into the parallel channel-coordinate attention module; like Figure 2 As shown, the parallel channel-coordinate attention module includes an SE branch, a CA branch, and an adaptive fusion unit. Let the input features be... , ,in For batch size, For the height and width of the feature map, The number of channels is given, and the output is the attention-enhanced feature map. The SE branch first performs global compression on the input feature map, that is, it compresses the spatial information to 1×1 through global average pooling, while preserving the global statistical features of the channel dimension. The expression is: ; in, It is a feature in the spatial dimension The result after performing global average pooling. For input features; Then channel compression is performed, reducing the number of channels from [previous level] through the first fully connected layer. Reduced to Simultaneously, ReLU activation introduces nonlinearity, reducing computational redundancy and enhancing feature representation capabilities, resulting in... The expression is: ; in, and The weights and biases of the first fully connected layer. Represents the ReLU function; Subsequently, channel expansion is performed, restoring the number of channels to [the desired level] through a second fully connected layer. The weights are then mapped to the [0,1] interval via Sigmoid activation to obtain the channel attention weights, expressed as: ; in, and For the weights and biases of the second fully connected layer, Represents the sigmoid function; Finally, a weighted output is performed, multiplying the channel attention weights element-wise with the input feature map to enhance important channels and suppress redundant channels. The expression is as follows: ; in, This represents element-wise multiplication; Subsequently, the CA branch first performs average pooling on the input feature map along both the height and width directions, preserving the positional information of a single spatial dimension and avoiding the loss of spatial details caused by global pooling. The expression is as follows: ; ; in, and These are the results of average pooling the feature maps along the height and width directions, respectively. Then, spatial feature compression is performed by using 1×1 convolutions to compress channels in both directions, reducing the computational cost of subsequent fully connected layers. The expression is: ; ; in, and These represent the spatial features after compression in two directions, respectively. The compressed spatial features are reshaped and used as input to the fully connected layer, which then generates weights in two directions: ; ; in, , These are the weights in the two directions, respectively; Then, spatial weight fusion is performed, averaging the weights in the horizontal and vertical directions to obtain the final coordinate attention weights: ; Finally, a weighted output is performed, multiplying the coordinate attention weights element-wise with the input feature map to enhance local discriminative regions and suppress background redundancy regions. The expression is as follows: ; The adaptive fusion unit is used to weightedly fuse the outputs of the SE branch and the CA branch to obtain the final output of the module. First, the two attention weights are averaged along all non-batch dimensions to obtain the branch importance score for each sample. and : ; ; The scores are stacked, mapped through a fully connected layer, and activated by Softmax to convert the branch scores into normalized fusion weights. : ; Finally, the fusion weights are multiplied by the outputs of the SE branch and the CA branch respectively, and then summed to obtain the final output feature map, expressed as: ; ; in, , .
[0031] Through this design, the ParallelSECA module simultaneously models channel and spatial orientation attention. The two attention paths are complementary, enabling the network to achieve stronger feature representation capabilities in challenging tasks such as the nine-class classification of blueberry freshness, where inter-class differences are subtle. Instead of directly adding SE and CA, the ParallelSECA module automatically learns the importance weights of the SE and CA branches based on the input features. This not only adaptively adjusts the attention emphasis according to features of different dimensions but also automatically balances channel enhancement and spatial orientation attention, avoiding performance bottlenecks caused by manually setting fixed ratios and improving the model's robustness and generalization ability. Furthermore, compared to other complex attention structures, such as SECA, this invention has lower parameter and computational costs.
[0032] Although the ParallelSECA module achieves channel-space dynamic enhancement of features, the model may still struggle to fully aggregate long-range dependencies across spatial locations. To address this, this invention designs a dilated convolution sequence optimization module, DilatedConvSeqOptimizer, such as... Figure 3As shown, by flattening the two-dimensional features into a sequence and then applying multi-rate dilated convolutions in the sequence dimension, and finally refining the features through residual connections and layer normalization, the receptive field is significantly expanded with almost no increase in computation.
[0033] In S2.2, the six features processed by the parallel channel-coordinate attention module, together with the other two original features not processed by the parallel channel-coordinate attention module, for a total of eight features, are input into the dilated convolution sequence optimization module for processing. The dilated convolution sequence optimization module performs the following operations: Input feature map The spatial dimension is flattened into a length of sequence : ; Will Each channel is assigned to Each with different void ratios The sequence is processed in parallel by one-dimensional convolutional branches to obtain the output of each branch. In this embodiment, we take The void ratios used are respectively A three-branch one-dimensional dilated convolution parallel processing sequence; ; in It is a standard convolution with an equivalent receptive field of 3. The equivalent receptive field is 5. The equivalent receptive field is 9; The outputs of the K branches are concatenated along the channel dimension to obtain the result. : ; Will and Obtain by performing residual connection : ; right Layer normalization is performed to obtain : ; Will Restore spatial dimensions as module output : ; in .
[0034] After the dilated convolution sequence optimizer is embedded into the ParallelSECA module, the features are enhanced by the ParallelSECA module and then fed into the dilated convolution sequence optimization module. Without increasing the computational cost, multi-scale receptive field expansion is performed, enabling the model to adaptively capture multi-scale discriminative information while strengthening key features, ultimately improving the accuracy and robustness of the classification task.
[0035] Experiments showed that when ParallelSECA and DilatedConvSeqOptimizer were added to mid-level features simultaneously, slight gradient oscillations and overfitting were prone to occur in the later stages of training. This is because mid-level features possess strong local details and preliminary semantic information, causing representation shifts or distribution fluctuations. Since low, medium, and high-scale features need to be input into the cross-dimensional attention fusion module later, unstable mid-level features will disrupt the consistency of multi-scale fusion.
[0036] To alleviate this problem, an additional skip residual connection is introduced after the DilatedConvSeqOptimizer for the mid-level features, and BatchNorm is further applied to enhance the stability of training, keeping the distribution of mid-dimensional features similar to that of low-dimensional and high-dimensional features, so that the subsequent cross-dimensional attention module can receive stable input.
[0037] After ParallelSECA, DilatedConvSeqOptimizer, and mid-level stabilization of residuals, channel selectivity, dilated scale receptive field, and local feature stability are enhanced, respectively, and the model obtains three sets of feature representations with different semantic levels. However, there is a lack of a unified and learnable cross-dimensional modeling mechanism between features of different semantic depths. How to efficiently fuse low, medium, and high-dimensional features becomes the key to determining the final performance. Traditional methods often use simple concatenation with 1×1 convolution or element-wise weighted summation, ignoring the dynamic importance differences of features at different levels on the current sample. To this end, this invention proposes a lightweight cross-dimensional dynamic combination multi-head attention module, CrossDimDCMHAttention, to achieve adaptive inter-level interaction and fusion of low-dimensional, medium-dimensional, and high-dimensional features. The CrossDimDCMHAttention structure is as follows: Figure 4 As shown; In S2.3, the outputs of the three low-dimensional features and two high-dimensional features processed by the dilated convolution sequence optimization module are added element-wise to obtain the fused low-dimensional features. and the high-dimensional features of fusion The residuals of the outputs from the three mid-dimensional features processed by the dilated convolution sequence optimization module are summed to obtain the fused mid-dimensional features. ; Input low-dimensional features Mid-dimensional characteristics High-dimensional features Mapped to the same dimension through linear layers respectively To obtain the mapping features , , : ; ; ; The mapped features are concatenated into a single length. token sequence : ; will sequence Projected onto the Query matrix Q, Key matrix K, and Value matrix V respectively: ; ; ; in, The number of parallel sub-attention heads selected Calculate the original dot product : ; right Attention probabilities are obtained through Softmax. : ; Calculate single-head attention output: ; Concatenate all single-head attention outputs along the feature dimension to obtain the multi-head attention output. Perform residual connections and layer normalization on the multi-head attention output: ; set up The three token vectors in the data are as follows: , , These correspond to the fused representations of the low-dimensional, mid-dimensional, and high-dimensional features of the input, respectively. The final scale-fused feature output is: .
[0038] The CrossDimDCMHAttention module addresses the issue of independent feature propagation across multiple levels through a progressive design involving dimensionality unification, dynamic convolutional attention, and residual fusion, enabling the model to model cross-dimensional information. This module significantly enhances the complementarity, robustness, and feature representation capabilities of multi-scale features while maintaining extremely low computational cost. Together with the ParallelSECA and DilatedConvSeqOptimizer modules, this module forms the core feature processing chain of the model, providing high-quality global feature representations for subsequent classification tasks.
[0039] The classification head is used to output the classification probability of blueberry freshness based on the fused features; S3. Train the blueberry freshness classification network DHAF-Net using the blueberry freshness image dataset; S4. Input the blueberry image to be detected into the trained blueberry freshness classification network DHAF-Net to obtain its corresponding freshness classification result.
[0040] After obtaining the freshness classification result in step S4, a quality prediction step S5 is also included: based on the freshness classification result, a predefined mapping relationship is queried to obtain the predicted values of one or more physicochemical quality indicators corresponding to blueberries. The mapping relationship is established in the following way: under known storage conditions, the physicochemical indicators of blueberry samples of different freshness grades are measured, and a statistical model between freshness grade and physicochemical indicators is established. The statistical model is a quadratic polynomial regression model. The physicochemical indicators include at least one of weight, firmness, and sweetness. Example
[0041] Building a dataset High-quality datasets are crucial for training high-performance deep learning models. Therefore, this invention first constructs a large, high-quality nine-class dataset of blueberry freshness.
[0042] The selected blueberry variety is Brilliant, currently the only blueberry variety exported from my country. The blueberries were harvested from the Guizhou China Original Ecological Organic Standard Blueberry Demonstration Garden and transported to the laboratory under refrigeration after harvesting. To ensure the dataset closely reflects real-world application scenarios, blueberry images were continuously collected daily at different times, under varying light intensities, and from different shooting angles until the blueberries became inedible. Environmental temperature and relative humidity were recorded in real-time during storage. Relevant data are as follows: Figure 5 As shown in the image, blueberry freshness was evenly divided into nine consecutive levels based on storage days, constructing a blueberry freshness image dataset containing multiple scenes, lighting conditions, and angles. The final dataset contains a total of 22,281 images. The freshness was divided according to storage days, and blueberries of different freshness levels are shown below. Figure 6As shown in the image. In addition, 50 blueberries are randomly selected daily for testing, and their weight, firmness, sweetness, and other indicators are recorded.
[0043] The 22,281 images were divided into training and testing sets in a 7:3 ratio. 20% of the training set was then used as a validation set for monitoring model performance and storing optimal weights during training. The training set consisted of 12,476 images, the validation set of 3,120 images, and the testing set of 6,685 images. The data distribution of blueberries at different freshness levels is shown in Table 4. Figure 7 Images are uniformly scaled to 112×112×3.
[0044] Table 4. Distribution of blueberry data at different freshness levels Model training and testing environment This invention uses the deep learning frameworks TensorFlow and Keras for training, validation, and testing. The hardware environment consists of an Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz processor and an NVIDIA GeForce RTX 2060 GPU with 6GB of video memory. The operating system is Windows 11, the programming language is Python 3.10.19, and the integrated development environment is Anaconda.
[0045] Hyperparameter settings During model training, all images were uniformly scaled to 112×112 pixels, with a batch size of 8. This ensured model training stability and gradient estimation accuracy while adapting to hardware computing resource limitations and avoiding memory overflow issues caused by excessively large batch sizes. The training process consisted of two phases: the first phase involved freezing the backbone network and training for 25 epochs; the second phase involved fine-tuning the parameters of the last 50 layers of the backbone network, also training for 25 epochs, thus achieving step-by-step optimization of feature extraction and parameter optimization. For the optimizer, the Adam optimization method was used. To balance model convergence speed and parameter update stability, and to reduce the risk of gradient oscillations in the early stages of training, a 5×10n optimizer was employed. -5 The initial learning rate. When the validation set loss does not decrease for 5 consecutive epochs, the learning rate is multiplied by a decay factor of 0.5; the minimum learning rate threshold is set to 1×10⁻⁻⁶. 6 To avoid the model stagnation due to an excessively low learning rate in later stages, the validation set accuracy is used as the monitoring metric. If there is no improvement after 6 consecutive epochs, training is terminated and the optimal weights are restored to effectively suppress overfitting.
[0046] Experimental test design To verify the effectiveness of the proposed model, an ablation experiment was conducted on the blueberry freshness classification model to compare the effects of transfer learning, multi-layer feature extraction, cross-dimensional dynamic combination of multi-head attention, ParallelSECA, and dilated convolution on the proposed model. The experimental design is shown in Table 5.
[0047] Table 5 Ablation Experiment Design ; Ablation experiments were conducted to evaluate each improvement in the model sequentially to verify its effectiveness. Common classification evaluation metrics were used, including the number of model parameters, classification accuracy (Acc), prec, recall, F1 score, spec, and map. The experimental results are shown in Table 6.
[0048] Table 6 Ablation Experiment Results ; Table 6 shows that after using transfer learning in the MobileNetV3-Small model, the classification accuracy improved from 87.05% to 94.06%, an increase of 7.01%, verifying the significant role of transfer learning in accelerating convergence and enhancing feature extraction for the target task by utilizing pre-trained model weights. The multi-layer feature extraction plus averaging fusion strategy improved accuracy by 0.75% with only an 8.04% increase in parameters, laying the foundation for the introduction of subsequent modules. Combining CrossDimDCMHAttention to achieve cross-dimensional dynamic attention fusion, significant increases in various metrics were achieved without a significant increase in parameters, demonstrating that advanced attention-based fusion can more efficiently improve model performance compared to simple concatenation. Replacing the original SE attention module with a parallel SECA module improved accuracy and map by 1.01% and 0.47% respectively with a slight increase in parameters, resulting in higher classification accuracy. This indicates that the hybrid attention mechanism, which preserves spatial dimensional information, can more accurately focus on key feature regions and effectively suppress redundant information interference. Finally, DilatedConvSeqOptimizer and intermediate residual connections were introduced. Although this increased the number of parameters, dilated convolution captured long-range feature dependencies by expanding the receptive field, while intermediate residuals alleviated the gradient vanishing problem in deep training, enabling the model to maintain excellent performance in complex tasks. That is, the proposed method and the trained model achieved the highest classification accuracy of 97.37%.
[0049] To verify the performance of the parallel SECA module, a comparative experiment was designed. Under the conditions of keeping the same experimental data, the same model structure and other settings, the improved model of the present invention was compared with the original SE attention, CBAM, SE and CA in series and parallel SECA respectively. The experimental results are shown in Table 7.
[0050] Table 7 Attention Comparison Results ; As shown in Table 7, the ParallelSECA designed in this invention has the best performance indicators.
[0051] The proposed model was compared with classic models such as AlexNet, DesNet121, SqueezeNet, MobileNetV1, MobileNetV2, and MobileNetV3. The corresponding changes in validation accuracy during training are shown below. Figure 8 As shown, the validation accuracy of different networks gradually improves during training and eventually stabilizes. The proposed DHAF-Net model converges faster than the other six models and achieves higher accuracy on the validation set with fewer iterations, significantly outperforming other models and demonstrating high optimization efficiency and high stability.
[0052] Table 8 shows the performance comparison of the proposed model with other models. The DHAF-Net model achieves the highest evaluation metrics in terms of accuracy, precision, recall, F1 score, specificity, and map size. It is worth noting that DHAF-Net has a small parameter count (2.62 × 10⁻⁶). 6 It is significantly lower than AlexNet (2.16×10). 7 ) and DesNet121 (7.17×10 6 Despite its superior overall performance, this feature aligns with the deployment requirements of lightweight models in resource-constrained scenarios, validating the effectiveness of the proposed model design in balancing performance and complexity.
[0053] Table 8 Model Comparison Results ; The confusion matrices of the model proposed in this invention and MobileNetV3-Small are as follows: Figure 9 As shown in (a) and 9(b), the diagonal values represent correct classifications; the darker the color and the larger the number, the better the classification performance.
[0054] The results show that the classification performance of the model in this invention is superior to that of MobileNetV3. The fusion of ParallelSECA and dilated convolution enhances the extraction capability of category-specific features, making the main diagonal of the confusion matrix more prominent. The reduction in misclassified samples means that the model's category judgment is more reliable in practical applications.
[0055] Quality index fitting During dataset collection, we also measured the physicochemical properties of blueberries, such as weight, firmness, and sweetness, to quantify their correlation with fruit freshness. Fifty blueberries were randomly sampled daily, and their physicochemical properties were tested, with the average value for each property calculated. Subsequently, quadratic multinomial regression was used to model the relationship between the average physicochemical data and freshness, facilitating automatic quality indicator prediction after freshness classification. This method is beneficial for high-quality blueberry processing and targeted sales strategies. The fitting results are as follows: Figure 10 As shown.
[0056] The fitted graphs show a significant regularity in the changes of blueberry weight, firmness, and sweetness with storage days. A mathematical model is used to fit and analyze these dynamic changes. The dynamic changes in blueberry quality attributes (weight, firmness, and sweetness) during storage were fitted using a quadratic multinomial regression model. The independent variable was the number of days of storage (x, unit: days), and the corresponding quality indicators (y1, y2, y3) were the dependent variables. The fitted equation and their respective coefficients of determination (R²) were obtained. 2 As shown below: The fitting formula for blueberry weight as a function of storage days is: ; The fitting formula for blueberry firmness as a function of storage days is: ; The fitting formula for blueberry sweetness as a function of storage days is: ; All regression models showed excellent fit, R0 2 All values exceeded 0.88, indicating that each quadratic polynomial function effectively described the changes in blueberry quality indicators over time during storage. In application, one or more corresponding blueberry physicochemical indicators can be obtained simply by inputting the classification results (storage days) output by the DHAF-Net model into the above polynomials.
[0057] Of course, the above description is not intended to limit the present invention, and the present invention is not limited to the examples given above. Any changes, modifications, additions or substitutions made by those skilled in the art within the scope of the present invention should also fall within the protection scope of the present invention.
Claims
1. A method for blueberry freshness classification and quality detection based on lightweight networks, characterized in that, Includes the following steps: S1. Collect blueberry images of different freshness levels and construct a blueberry freshness image dataset containing multiple freshness levels; S2. Construct the blueberry freshness classification network DHAF-Net, which is obtained by improving the MobileNetV3-Small network structure as follows: S2.1 Replace the SE attention module in the MobileNetV3-Small network with a parallel channel-coordinate attention module; S2.2 After the parallel channel-coordinate attention module, a dilated convolution sequence optimization module is embedded; S2.3 Extract three groups of features at different semantic levels (low, medium, and high) from the improved network structure, and input them into the cross-dimensional dynamic multi-head attention module for fusion, outputting the final fused features; S2.4 Connect a classification head to output the classification probability of blueberry freshness based on the fusion features; S3. Train the blueberry freshness classification network DHAF-Net using the blueberry freshness image dataset; S4. Input the blueberry image to be detected into the trained blueberry freshness classification network DHAF-Net to obtain its freshness classification result.
2. The method for blueberry freshness classification and quality detection based on lightweight networks according to claim 1, characterized in that, In step S1, images of blueberries are collected at different times of the day, under different lighting conditions, and from multiple shooting angles, and the collection continues until the blueberries are no longer edible. The freshness level is divided into nine categories based on the number of days of storage.
3. The method for blueberry freshness classification and quality detection based on lightweight networks according to claim 1, characterized in that, In step S2.1, eight feature extraction layers are selected from the MobileNetV3-Small network and divided into three low-dimensional feature layers, three mid-dimensional feature layers, and two high-dimensional feature layers. The three mid-dimensional features of the second group, the two low-dimensional features of the first group, and one high-dimensional feature of the third group are respectively input into the parallel channel-coordinate attention module. The parallel channel-coordinate attention module includes an SE branch, a CA branch, and an adaptive fusion unit; The SE branch first performs global average pooling on the input feature map, compressing the spatial information into a 1×1 shape, as shown in the expression: ; in, It is a feature in the spatial dimension The result after performing global average pooling. Input features; Then, the number of channels is increased from the first fully connected layer. Reduced to Simultaneously, nonlinearity is introduced through ReLU activation, resulting in... The expression is: ; in, and The weights and biases of the first fully connected layer. Represents the ReLU function; The number of channels is restored using the second fully connected layer. The weights are then mapped to the [0,1] interval via Sigmoid activation to obtain the channel attention weights, expressed as: ; in, and The weights and biases for the second fully connected layer. Represents the sigmoid function; Finally, a weighted output is performed, where the channel attention weights are multiplied element-wise by the input feature map, as shown in the expression: ; in, This represents element-wise multiplication; The CA branch first performs average pooling on the input feature map along both the height and width directions, as expressed by: ; ; in, and These are the results of average pooling the feature maps along the height and width directions, respectively. Then, channel compression is performed in both directions using a 1×1 convolution, expressed as follows: ; ; in, and These represent the spatial features after compression in two directions, respectively. The compressed spatial features are reshaped and used as input to the fully connected layer, which then generates weights in two directions: ; ; in, , These are the weights in the two directions, respectively; Then, spatial weight fusion is performed to obtain the final coordinate attention weights: ; Finally, a weighted output is performed, where the coordinate attention weights are multiplied element-wise by the input feature map, as shown in the expression: ; The adaptive fusion unit is used to weightedly fuse the outputs of the SE branch and the CA branch to obtain the final output of the module. First, the two attention weights are averaged along all non-batch dimensions to obtain the branch importance score for each sample. and : ; ; The scores are stacked, mapped through a fully connected layer, and activated by Softmax to convert the branch scores into normalized fusion weights. : ; Finally, the fusion weights are multiplied by the outputs of the SE branch and the CA branch respectively, and then summed. The expression is: ; ; in, , .
4. The method for blueberry freshness classification and quality detection based on lightweight networks according to claim 1, characterized in that, In step S2.2, the six features processed by the parallel channel-coordinate attention module, together with the other two original features not processed by the parallel channel-coordinate attention module, for a total of eight features, are input into the dilated convolution sequence optimization module for processing. The dilated convolution sequence optimization module performs the following operations: Input feature map The spatial dimension is flattened into a length of sequence : ; Will Each channel is assigned to Each with different void ratios The sequence is processed in parallel by one-dimensional convolutional branches to obtain the output of each branch. : ; The outputs of the K branches are concatenated along the channel dimension to obtain the result. : ; Will and Obtain by performing residual connection : ; right Layer normalization is performed to obtain : ; Will Restore spatial dimensions as module output : ; in .
5. The method for blueberry freshness classification and quality detection based on lightweight networks according to claim 1, characterized in that, Following the output of the dilated convolution sequence optimization module, skip residual connections and batch normalization layers are introduced to stabilize the feature distribution.
6. The method for blueberry freshness classification and quality detection based on lightweight networks according to claim 1, characterized in that, In step S2.3, the outputs of the three low-dimensional features and two high-dimensional features processed by the dilated convolution sequence optimization module are added element-wise to obtain the fused low-dimensional features. and the high-dimensional features of fusion The residuals of the outputs from the three mid-dimensional features processed by the dilated convolution sequence optimization module are summed to obtain the fused mid-dimensional features. ; The cross-dimensional dynamic multi-head attention module performs the following operations: Input low-dimensional features Mid-dimensional characteristics High-dimensional features Mapped to the same dimension through linear layers respectively To obtain the mapping features , , ; The mapped features are concatenated into a token sequence. : ; will sequence The projections are respectively onto the Query matrix Q, Key matrix K, and Value matrix V; Calculate the original dot product : ; right Attention probabilities are obtained through Softmax. : ; Calculate single-head attention output: ; Concatenate all single-head attention outputs along the feature dimension to obtain the multi-head attention output. Perform residual connections and layer normalization on the multi-head attention output: ; set up The three token vectors in the data are as follows: , , These correspond to the fused representations of the low-dimensional, mid-dimensional, and high-dimensional features of the input, respectively. The final scale-fused feature output is: 。 7. The method for blueberry freshness classification and quality detection based on lightweight networks according to claim 1, characterized in that, After obtaining the freshness classification result in step S4, a quality prediction step S5 is also included: based on the freshness classification result, a predefined mapping relationship is queried to obtain the predicted values of one or more physicochemical quality indicators of blueberries. The mapping relationship is established in the following way: under known storage conditions, the physicochemical indicators of blueberry samples of different freshness grades are measured, and a statistical model between freshness grade and physicochemical indicators is established. The statistical model is a quadratic polynomial regression model. The physicochemical indicators include at least one of weight, firmness, and sweetness.