Cold fresh mutton freshness nondestructive testing method based on double-branch hierarchical spectral feature sensing network

By combining the method of the dual-branch hierarchical spectral feature perception network, combining multi-index and hyperspectral data, preprocessing and feature selection are optimized, position coding and multi-head attention mechanism are introduced, and hierarchical classifiers with dynamic loss weights are designed, which solves the accuracy of mutton freshness detection in the existing technology, and achieves freshness detection with high accuracy and strong generalization ability.

CN119992541AActive Publication Date: 2025-05-13INNER MONGOLIA AGRICULTURAL UNIVERSITY

Patent Information

Application Number
CN202510480795.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-17
Publication Date
2025-05-13
Estimated Expiration
2045-04-17

AI Technical Summary

Technical Problem

The existing hyperspectral combined with deep learning algorithms have problems such as noise interference, specific distribution, loss of feature information, sample dependence, feature redundancy and category imbalance in lamb freshness detection, resulting in low detection accuracy.

Method used

Using a method based on a dual-branch hierarchical spectral feature perception network, a freshness evaluation is performed through multi-index combined with hyperspectral data, a pre-processing and feature selection method is preferred, a position-encoding bidirectional cross attention module and a multi-scale enhanced multi-head attention mechanism are introduced, and a dynamic loss weight-driven hierarchical classifier is designed.

Benefits of technology

It significantly improves the accuracy of the recognition of freshness rating of lamb, enhances the model's modeling ability of long-range dependencies and local differences in spectral sequences, improves the ability to recognize complex freshness changes patterns, and alleviates the problems of fuzzy and misjudgment of intermediate ratings.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119992541A_ABST
    Figure CN119992541A_ABST
Patent Text Reader

Abstract

The invention discloses a cold fresh mutton freshness nondestructive testing method based on a double-branch hierarchical spectral feature sensing network, and relates to the field of mutton freshness detection.The cold fresh mutton freshness nondestructive testing method comprises the steps that mutton samples with different freshness are obtained, and freshness index determination and hyperspectral image acquisition are conducted; determining a sample label according to the freshness index; the method comprises the following steps: processing a hyperspectral image by using different preprocessing and feature selection combination methods as sample features, and constructing a plurality of training data sets; constructing a double-branch hierarchical spectral feature sensing network as a detection model, and performing training by using different training data sets; and calculating evaluation indexes of the trained detection models, and carrying out nondestructive detection on the freshness of the chilled fresh mutton by taking the detection model corresponding to the optimal pretreatment and feature selection combination method as a final freshness detection model. According to the spectrum feature sensing network based on the double-branch hierarchy, spectrum features are fully sensed by applying a multi-module joint mechanism, and high-precision detection of the freshness of the chilled fresh mutton is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of mutton freshness detection, and more specifically to a non-destructive detection method for the freshness of chilled mutton based on a double-branch hierarchical spectral feature perception network. Background Art

[0002] In the context of modern animal husbandry, mutton mainly relies on cold storage and cold chain transportation. The nutritional value and flavor of mutton are closely related to its freshness, and freshness is the key basis for evaluating mutton quality. Therefore, accurate detection of the freshness level of mutton is of great significance for ensuring consumer safety and real-time quality monitoring.

[0003] With the increasing attention paid to food safety, the methods for detecting the freshness of mutton have gradually transitioned from early sensory evaluation to more reliable physical and chemical index analysis, instrument detection and dye color development. However, the analysis process of physical and chemical indicators is complex, time-consuming, sample-destructive and costly, and is often used to provide accurate quantitative data for other detection technologies. Hyperspectral technology has unique advantages due to its rapid, non-invasive and non-destructive detection characteristics. Compared with traditional detection methods, it can not only reflect the subtle changes in the spoilage process of meat through correlation analysis of different bands, but also accurately classify the freshness by combining data analysis models. However, in the actual application of mutton detection, the existing hyperspectral combined with deep learning algorithms are affected by the fluctuations of mutton sample preparation specifications and experimental environment, and the spectral data is prone to noise interference and shows specific distribution; inappropriate data processing strategies will lead to the loss of spectral feature information; most models still do not fully exploit the band information. In addition, deep learning models generally have problems such as sample dependence, feature redundancy and category imbalance in practical applications, especially in the fuzzy boundary area between adjacent freshness levels, the model misjudgment rate is high.

[0004] Therefore, how to improve the detection accuracy of non-destructive detection of mutton freshness is an urgent problem that technical personnel in this field need to solve. Summary of the invention

[0005] In view of this, the present invention provides a nondestructive detection method for the freshness of chilled mutton based on a double-branch hierarchical spectral feature perception network to improve the accuracy of mutton freshness grade identification.

[0006] In order to achieve the above object, the present invention provides the following technical solutions: The present invention discloses a nondestructive detection method for the freshness of chilled mutton based on a double-branch hierarchical spectral feature perception network, and the specific steps are as follows: Obtain mutton samples of different freshness, measure freshness index and collect hyperspectral images; Determining the sample label of the corresponding training sample according to the freshness index of each of the mutton samples; Processing the hyperspectral images using different preprocessing and feature selection combination methods as sample features of training samples, and constructing several training data sets corresponding to the combination methods; Constructing a dual-branch hierarchical spectral feature perception network as a detection model, and using different training data sets to train them respectively; The evaluation indicators of each trained detection model were calculated, and the detection model corresponding to the optimal preprocessing and feature selection combination method was used as the final freshness detection model for non-destructive detection of the freshness of fresh mutton.

[0007] Furthermore, the freshness indicators include: volatile basic nitrogen, total colony count and approximate E. coli count; the sample label is the mutton freshness grade, including: fresh, sub-fresh, slightly corrupt and corrupt.

[0008] Furthermore, the preprocessing includes: SG filter, multivariate scattering correction, standard normal variable transformation, first-order derivative and moving average method; the feature selection includes: maximum mutual information minimization feature selection method and incremental feature selection method.

[0009] Furthermore, the sample features include global feature data and local feature data; the global feature data is image data containing all band information after preprocessing of the hyperspectral image, and the local feature data is image data containing part of the band information after feature selection of the global feature data.

[0010] Furthermore, the dual-branch hierarchical spectral feature perception network includes: a feature extraction module, a feature interaction module, a feature fusion module and an output module connected in sequence; The feature extraction module performs feature extraction on the global feature data and the local feature data respectively to obtain global features and local features; The feature interaction module uses a bidirectional cross attention mechanism to perform information interaction on the global features and the local features to obtain optimized global features and optimized local features; The feature fusion module performs multi-scale enhancement on the optimized global features and the optimized local features, and fuses the multi-scale features using a multi-head attention mechanism to obtain a fused feature; The output module outputs the recognition result using a hierarchical classifier based on the fusion features.

[0011] Furthermore, the feature extraction module includes a global feature extraction branch and a local feature extraction branch, each feature extraction branch is composed of a convolution layer, an activation function layer and a pooling layer connected in series in sequence, the global feature extraction branch performs feature extraction on the global feature data, and the local feature extraction branch performs feature extraction on the local feature data.

[0012] Furthermore, the feature interaction module includes a position encoding unit and a bidirectional cross attention unit; The position encoding unit performs position encoding on the global feature and the local feature respectively to generate a corresponding dynamic position vector, and the formula is: ; in, is the band index, is the position encoding dimension, is the dimension of the input features; The bidirectional cross attention unit constructs a bidirectional interactive channel between global features and local features through bidirectional cross attention, and performs information flow between global and local features. The formula is: ; in, , They are respectively used to optimize global features and local features. , They are global features and local features respectively.

[0013] Furthermore, the feature fusion module includes: a multi-scale pooling layer, a multi-head attention layer and a fully connected layer connected in sequence; The multi-scale pooling layer extracts features of different granularities through different scale pooling strategies. The formula is: ; in, , They are respectively used to optimize global features and local features. , They are the corresponding pooled results, , Represent global pooling and local pooling respectively; The multi-head attention layer is equipped with four parallel attention heads. Each attention head takes the multi-scale pooled features as input and first performs a linear transformation to generate the corresponding query, key and value. The formula is: ; in, is the input feature, , and Respectively The query, key, and value of each attention head, , and Respectively The linear transformation matrix of the query, key, and value corresponding to each attention head; Then calculate the attention of each attention head , the formula is: ; in, is the dimension of the key, represents the activation function, Represents the square root operation, Represents a matrix transpose operation; The fully connected layer concatenates the outputs of all attention heads and obtains fused features through linear transformation. , the formula is: ; in, represents the fully connected layer, is the linear transformation matrix, Represents a concatenation operation.

[0014] Furthermore, the hierarchical classifier includes a coarse-grained classifier and a fine-grained classifier. First, the coarse-grained classifier is used to classify the fusion features. Divide into major categories and obtain intermediate features ; Then, the fine-grained classifier is used to perform refined classification based on the intermediate features to obtain the final detection result , the specific formula is as follows: ; ; in, are the weight and bias of the coarse-grained classifier, are the weight and bias of the fine-grained classifier, is the activation function.

[0015] Furthermore, the coarse-grained classifier and the fine-grained classifier both use a cross entropy loss function, and by introducing dynamic weights, the total loss function of the output module is obtained, and the specific formula is: ; in, represents the total loss function, They are the loss functions of the coarse-grained classifier and the fine-grained classifier respectively; Represents dynamic weight, the formula is: ; ; in, Represent the training rounds and the maximum training rounds respectively, , They represent the dynamic weights at the early and late stages of training, respectively.

[0016] It can be seen from the above technical solutions that, compared with the prior art, the present invention discloses a non-destructive detection method for the freshness of chilled mutton based on a double-branch hierarchical spectral feature perception network, which has the following outstanding technical features and innovative advantages: (1) The freshness evaluation was performed using multiple indicators (TVB-N, TAC, MPN) combined with hyperspectral data, providing more biologically and chemically meaningful data support for the model; (2) Through the optimization of preprocessing and characteristic wavelength selection methods, a more universal and data-adaptive spectral feature extraction strategy is achieved; (3) In the feature interaction stage, the bidirectional cross attention module (PBCA) combined with position encoding is introduced for the first time, which improves the model's ability to jointly model the long-range dependencies and local differences of spectral sequences; (4) In the feature fusion stage, a multi-scale enhanced multi-head attention mechanism (MSMHA) was designed to significantly enhance the model's ability to recognize complex freshness change patterns; (5) In the classification output stage, a hierarchical classification mechanism (HCM) driven by dynamic loss weights is proposed to effectively alleviate the problems of intermediate level ambiguity and misjudgment, and enhance the stability and accuracy of the model in multi-category scenarios.

[0017] The invention discloses a nondestructive detection method for the freshness of chilled mutton with high precision, strong generalization ability and practical deployable potential, which has significant theoretical significance and application value. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0019] Figure 1 It is a schematic diagram of the overall process of an embodiment of the present invention.

[0020] Figure 2 It is a schematic diagram of the overall structure of the dual-branch hierarchical spectral feature perception network of the present invention. DETAILED DESCRIPTION

[0021] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0022] The embodiment of the present invention discloses a non-destructive detection method for the freshness of chilled mutton based on a double-branch hierarchical spectral feature perception network. Figure 1 As shown, the specific steps are as follows: Obtain mutton samples of different freshness, measure freshness index and collect hyperspectral images; Determine the sample label of the corresponding training sample according to the freshness index of each mutton sample; Using different preprocessing and feature selection combination methods to process hyperspectral images as sample features of training samples, several training data sets corresponding to the combination methods are constructed; A dual-branch hierarchical spectral feature perception network is constructed as a detection model, and trained using different training data sets. The evaluation indicators of each trained detection model were calculated, and the detection model corresponding to the optimal preprocessing and feature selection combination method was used as the final freshness detection model for non-destructive detection of the freshness of fresh mutton.

[0023] In a specific embodiment, the freshness indicators include: volatile basic nitrogen, total colony count and approximate E. coli count; the sample labels are mutton freshness levels, including: fresh, sub-fresh, slightly corrupt and corrupt.

[0024] Specifically, a hyperspectral system is composed of a hyperspectral imager, a scanning platform and two adjustable 100W halogen lamps. The imager covers a spectral range of 400nm~1000nm, with a resolution of 2.8nm, and contains a total of 750 spectral channels. Before collecting spectral images, preheat the hyperspectral imager 30 min in advance, and adjust the maximum light flux to F2.0. During the experiment, the mutton sample was placed on the scanning platform about 30cm away from the lens and placed directly opposite the imaging lens. The pixel mixing times were set to 6 times, and then the exposure time was adjusted to keep DN below 8500 to avoid signal loss. Two 100W halogen lamps were symmetrically arranged at an angle of 45° on both sides of the sample, about 35cm away from the sample. By gradually adjusting the light knob, the uniformity of the light distribution was higher than 90%. Click the acquisition button to obtain a hyperspectral image of the sample in the computer system. Using the formula The spectral image is subjected to black and white correction, where I represents the original image, B represents the black correction image, W represents the white correction image, and G represents the corrected spectral image. Hyperspectral data acquisition is completed by the hyperspectral system and data acquisition software.

[0025] After the hyperspectral image is collected, the software is used to select the region of interest of the hyperspectral image of the chilled fresh mutton sample. First, the false color image is constructed by selecting the band 650nm, band 554nm and band 553nm based on the RGB principle, so as to more clearly identify the distribution of tissue on the sample surface at the visualization level. Then, in order to exclude the interference of a small amount of connective tissue, only the lean meat area is marked, and 20 regions of interest with a size of 10×10 pixels are randomly selected from each image, and the original spectral pixel brightness values ​​of all bands in the region are recorded. Finally, the spectral information corresponding to each region of interest is generated according to the band order to generate the freshness original spectral data set, and a total of 20×210=4200 sample data are obtained.

[0026] Finally, the freshness index of the samples within 14 days was determined: the content of volatile basic nitrogen (TVB-N) was determined according to GB / 5009.228-2016 "National Food Safety Standard for the Determination of Volatile Basic Nitrogen in Foods by Semi-micro Kjeldahl Nitrogen Determination", the total bacterial count (TAC) was tested according to GB / 4789.2-2022 "National Food Safety Standard for the Determination of the Total Bacterial Count in Food Microbiological Examination", and the approximate number of Escherichia coli (MPN) was counted according to GB / 4789.3-2016 "National Food Safety Standard for the Count of Escherichia coli in Food Microbiological Examination". At present, most studies divide freshness into simple 2 or 3 categories. In order to reflect the synergistic effect of multiple indicators and refine the freshness level, this embodiment adopts the threshold cross-classification method to accurately divide the freshness level by the content range of three freshness indicators. Set 4 types of freshness labels: fresh, subfresh, prespoiled, and spoiled. Table 1 shows the corresponding relationship between the indicator content and freshness.

[0027] Table 1 Classification of freshness In a specific embodiment, preprocessing includes: SG filter (SG), multivariate scatter correction (MSC), standard normal variable transformation (SNV), first-order derivative (FD) and moving average method (MA); feature selection includes: maximum mutual information minimization feature selection method and incremental feature selection method.

[0028] Specifically, the raw spectral data of freshness is easily disturbed by noise generated by instruments, lighting and other conditions, as well as the unevenness of mutton cut samples and the uncontrollable surface roughness. Therefore, a preprocessing method must be used to clean the data.

[0029] In the analysis of hyperspectral data, feature selection can significantly reduce the data dimension and effectively retain information that is highly correlated with the target variable. In this example, the content of TVB-N, TAC, and MPN, the freshness indicators of chilled mutton, is used as the marker variable. The preprocessed freshness spectral data set is used to extract the spectral bands most related to the freshness index by using the maximum mutual information minimization (MIM) and incremental feature selection (IFS) methods, and four key regression indicators are used to evaluate the model performance under different pre-feature selection methods: determination coefficient (R²), root mean square error (RMSE), mean absolute error (MAE), and residual prediction deviation (RPD). R² measures the degree of fit of the model, and a higher R² value indicates better model performance; RMSE and MAE measure the prediction error, and the smaller the value, the higher the model accuracy; RPD is used to evaluate the generalization ability of the model, and the model has excellent regression performance when it is greater than 3.0. In addition, the SHAP value (SHapley Additive exPlanations) is used to further verify the effectiveness of key features.

[0030] Table 2: Comparison of prediction performance of feature selection under different preprocessing methods Table 2 compares the prediction performance of MIM and IFS for freshness indicators under different preprocessing methods. The data performance of the combined method is evaluated by combining the regression indicators R², RMSE, MAE and RPD, and the contribution of the characteristic bands is verified based on the interpretability of the SHAP value. According to the table results and the visualization results of the SHAP value, the selection of characteristic bands has a significant impact on the improvement of preprocessing methods and prediction performance. From the prediction results, the application of MIM and IFS significantly improves the prediction effect of the model. By modeling the full-frequency spectrum of TVB-N, TAC and MPN, and preprocessing them using MSC, SNV and FD methods, the key bands selected by MIM and IFS show high prediction accuracy. Among them, under the FD-IFS combination, the determination coefficient R² and regression error RMSE of TVB-N are 0.8757 and 0.3601 respectively, which show the best error performance compared with the original data and other combined methods. In the prediction of TAC and MPN indicators, RPD>3.5 shows extremely strong model stability. The combination of preprocessing and feature selection not only significantly improves the prediction accuracy of the hyperspectral data model, but also optimizes the computational efficiency and enhances the robustness and interpretability of local branches. The selected key bands have high feasibility for the input of the subsequent detection network, provide accurate feature information, make the attention of the local network more efficient, and provide reliable spectral feature support for the freshness assessment task. The specific descriptions of MIM, IFS and SHAP are as follows.

[0031] The maximum mutual information minimization is based on the mutual information theory. It measures the statistical correlation by calculating the mutual information between a single spectral band and the target variable, thereby screening a set of highly correlated characteristic bands, which can reflect the importance of spectral bands in predicting indicators such as TVB-N, TAC, and MPN. The specific formula is: ;in, Representation characteristics X and the target variable Y The mutual information between , Characteristics X With the target variable Y Entropy of It is a feature X and the target variable Y The joint entropy of .

[0032] Incremental feature selection, based on the joint mutual information algorithm, can screen out band sets with high correlation and high interactivity by analyzing the joint information between spectral band combinations and target variables. Different from traditional single-variable feature selection, incremental feature selection considers the synergy between features and uses combined evaluation technology to deeply explore the importance of features. The specific formula is: ; in, Representation characteristics Xi and Xj With the target variable y The joint mutual information between and A single feature Xi and Xj With the target variable y The mutual information between them.

[0033] The SHAP value is based on the Shapley value in game theory to quantify the contribution of each feature to the model prediction results. The specific formula is: ; in, is the Shapley value of the ith feature; N The full set of features, S is a feature subset, f(S) In the feature subset S The prediction output under . By generating a SHAP contribution graph, the relative importance of all spectral bands and selected features in the prediction is displayed. In addition, a regression evaluation is performed on all freshness spectral feature sets to verify the prediction ability of the selected feature set in practical applications to obtain the best feature selection method. In order to better verify the performance of the dual-branch information interaction mechanism, the feature band set will be used as the focus information of the local branch to improve the detection performance of freshness.

[0034] In a specific embodiment, the sample features include global feature data and local feature data; the global feature data is image data containing all band information after hyperspectral image preprocessing, and the local feature data is image data containing part of the band information after feature selection of the global feature data.

[0035] In a specific embodiment, Figure 2 As shown, the dual-branch hierarchical spectral feature perception network includes: a feature extraction module, a feature interaction module (PBCA), a feature fusion module (MSMHA) and an output module (HCM) connected in sequence; The feature extraction module extracts features from the global feature data and the local feature data to obtain global features and local features; The feature interaction module uses a bidirectional cross-attention mechanism to interact with global features and local features to obtain optimized global features and optimized local features. The feature fusion module performs multi-scale enhancement on the optimized global features and optimized local features, and uses the multi-head attention mechanism to fuse the multi-scale features to obtain the fused features; The output module outputs the recognition results based on the fusion features using a hierarchical classifier.

[0036] In a specific embodiment, the feature extraction module includes a global feature extraction branch and a local feature extraction branch. Each feature extraction branch is composed of a convolution layer, an activation function layer and a pooling layer connected in series. The global feature extraction branch performs feature extraction on global feature data, and the local feature extraction branch performs feature extraction on local feature data.

[0037] Specifically, the global feature extraction branch is mainly used to extract the global features of the entire input data, while the local feature extraction branch is used to extract local feature data. Each feature extraction branch consists of a series of convolutional layers, activation function layers, and pooling layers connected in series, aiming to extract features of different scales through a hierarchical structure. In addition, the outputs of the global and local feature extraction branches will be fused in subsequent network modules to further improve the model's expressiveness and classification accuracy.

[0038] In a specific embodiment, the feature interaction module includes a position encoding unit and a bidirectional cross attention unit; The position encoding unit performs position encoding on the global features and local features respectively to generate the corresponding dynamic position vector. The formula is: ; in, is the band index; is the position encoding dimension; is the dimension of the input feature, indicating the total dimension of the encoded feature, and is used to normalize the position; The bidirectional cross attention unit constructs a bidirectional interactive channel between global features and local features through bidirectional cross attention, and performs information flow between global and local features. The formula is: ; in, , They are respectively used to optimize global features and local features. , are global features and local features respectively. In cross attention, and It is used as both key and value input to guide global and local features to focus on global context information, thereby enhancing the discriminability of local features.

[0039] Specifically, in the feature interaction stage, the traditional two-branch method usually processes the global features and local features independently, lacks the interaction modeling between features, and causes the loss of dependencies. Especially in the hyperspectral data analysis task, the high dimensionality of the data and the redundancy between bands make it difficult for simple feature fusion methods to fully capture the dependencies between bands, resulting in insufficient utilization of the spatial similarity of features or band correlation. In addition, the hyperspectral bands are sequentially sensitive, and the position of each band in the spectrum provides key contextual information. If the spectral data is directly input into the network, the relative position information of the bands may be lost. Therefore, the model requires an efficient feature interaction module to assist the model in dynamically learning and capturing the interaction information between global features and local features, so as to enhance the model's learning ability for long-range dependencies, thereby enhancing its classification discrimination. Therefore, the PBCA module is designed in the present invention. First, the global and local features of the input are respectively encoded by position ( Figure 2 The PE (in PE) is processed to generate a dynamic position vector related to the band order, and a learnable position encoding is added to it, so that the model can effectively distinguish the relative importance and order relationship of each band, and enhance the feature interaction of hyperspectral data. Then, a bidirectional cross attention mechanism is introduced: a bidirectional interaction channel between global features and local features is constructed through bidirectional cross attention, the information flow of global and local features is realized, and the model is further promoted to learn long-range dependencies to improve the expression ability of features.

[0040] In a specific embodiment, the feature fusion module includes: a multi-scale pooling layer, a multi-head attention layer, and a fully connected layer connected in sequence; The multi-scale pooling layer extracts features of different granularities through different scale pooling strategies. The formula is: ; in, , They are respectively used to optimize global features and local features. , They are the corresponding pooled results, , Represent global pooling and local pooling respectively; There are four parallel attention heads in the multi-head attention layer. Each attention head takes the multi-scale pooled features as input and first performs a linear transformation to generate the corresponding query, key, and value. The formula is: ; in, is the input feature, , and Respectively The query, key, and value of each attention head, , and Respectively The linear transformation matrix of the query, key, and value corresponding to each attention head; Then calculate the attention of each attention head , the formula is: ; in, is the dimension of the key, represents the activation function, which is used to limit the output to the range of 0 to 1 and perform probability distribution processing. Represents a square root operation (used for queries ( Q ) and keys ( K ) to avoid excessively large values ​​when calculating the attention score as the dimension increases). represents the matrix transpose operation (when calculating the attention score, the query vector Q With key vector K A dot product needs to be performed, so the key vector needs to be transposed); The fully connected layer concatenates the outputs of all attention heads and obtains fused features through linear transformation , the formula is: ; in, represents the fully connected layer, is the linear transformation matrix, represents the concatenation operation (joining multiple attention heads ( Head 1 , Head 2 , ..., Head i ) are concatenated together to form a new feature vector).

[0041] Specifically, in the feature fusion stage, many existing studies are limited to simple global and local feature splicing or weighted averaging for feature fusion. However, these methods fail to fully capture the complex dependencies between different scales and different features; and may ignore slight differences between feature data; in addition, in the freshness detection task of chilled mutton, the cross-scale correlation between bands is crucial to the discriminability and robustness of the freshness level. Effectively capturing the multi-level feature relationships can reduce the model's dependence on large-scale samples. Therefore, how to more accurately model the complex interactions between different feature scales and enhance their representation capabilities in freshness detection has become the key to improving detection accuracy. Therefore, the present invention designs an MSMHA module and proposes a multi-scale enhanced multi-head attention mechanism, which aims to make full use of multi-scale features through the combination of multi-scale pooling and multi-head attention, thereby modeling complex relationships across scales.

[0042] First, a multi-scale pooling strategy is applied to extract features of different granularities for optimizing global features and optimizing local features. After multi-scale enhancement, the model can capture features of different granularities and provide rich cross-scale feature information.

[0043] Then, four parallel attention heads are used using the multi-head attention mechanism. Head 1 (Global trend attention Head): global trend modeling, focusing on capturing global spectral trends, focusing on modeling the overall change pattern in the freshness spectrum; Head 2 (Local detail attention Head): local feature modeling, focusing on specific band areas that are strongly related to the chemical composition of freshness, enhancing the model's sensitivity to spectral bands; Head 3 (Long-distance Dependency Attention Head): cross-band long-distance dependency modeling, strengthening the understanding of nonlinear dependencies between different bands in hyperspectral data; Head 4 (Multi-scale Interaction Attention Head): multi-scale feature interaction modeling, compensating for possible distribution differences between features of different scales. Each attention head can focus on different spectral feature patterns and spectral data dependencies, providing the model with multi-perspective relationship modeling capabilities and forming a richer feature representation.

[0044] In a specific embodiment, the hierarchical classifier includes a coarse-grained classifier and a fine-grained classifier. First, the coarse-grained classifier is used to classify the Divide into major categories and obtain intermediate features ; Then, through the fine-grained classifier, the classification is refined based on the intermediate features to obtain the final detection result , the specific formula is as follows: ; ; in, are the weight and bias of the coarse-grained classifier, are the weight and bias of the fine-grained classifier, is the activation function.

[0045] Specifically, in the output stage, the extracted fusion features are input into the hierarchical classifier for two-stage classification. This paper aims to solve the problems of overlapping category features, uneven sample distribution and insufficient intermediate features when detecting the freshness of chilled mutton. The present invention designs an HCM module and proposes a hierarchical classifier with dynamic joint loss function optimization. Through the staged optimization of coarse-grained and fine-grained classifiers and the dynamic balance design of the joint loss function, the classification difficulties are gradually solved. First, the samples are divided into large categories through a coarse-grained classifier to simplify the task and ensure that the model can initially distinguish large categories and provide intermediate features. Then, a fine-grained classifier is used to receive the intermediate features and perform refined classification, process the subtle differences between categories, and finally output the prediction results.

[0046] In a specific embodiment, both the coarse-grained classifier and the fine-grained classifier use a cross entropy loss function, and by introducing dynamic weights, the total loss function of the output module is obtained. The specific formula is: ; in, represents the total loss function, They are the loss functions of the coarse-grained classifier and the fine-grained classifier respectively; Represents dynamic weight, the formula is: ; ; in, Represent the training rounds and the maximum training rounds respectively, , They represent the dynamic weights at the early and late stages of training, respectively.

[0047] Specifically, in order to dynamically adjust the attention of coarse-grained and fine-grained tasks during the training process, the present invention introduces dynamic weights. In the early stage of training, the dynamic weight of the coarse-grained task is a larger value, and the model is adjusted by the training round and the maximum round, gradually paying more attention to the fine-grained tasks; at the same time, during the training process, the dynamic weight is adjusted by the relative value of the loss at each stage. Through the dynamic loss optimization strategy, the model can automatically adjust the weight according to the different stages of training, so that the model can focus more on the tasks or goals that need to be optimized most at different stages, thereby accelerating convergence and improving performance.

[0048] In a specific embodiment, in order to meet the high-precision requirements of mutton freshness detection, accuracy, weighted precision, weighted recall, and weighted F1 score are used as evaluation criteria to evaluate the performance of the dual-branch hierarchical spectral feature perception network.

[0049] Set the number of categories to n , No. i The number of samples of the class is N i The total number of samples is N For sample classification, the effective positive class (effective positive, EP i ) refers to the number of samples correctly identified as positive; undetected positive, UP i ) is the number of positive samples that are not detected and mistakenly classified as negative; false alert positive, FAP i ) is the number of negative samples incorrectly classified as positive; effective negative ( EN i ) refers to the number of samples correctly identified as negative classes.

[0050] The accuracy calculation formula is: ; The weighted recall calculation formula is: ; The weighted precision calculation formula is: ; The weighted F1 score calculation formula is: .

[0051] in, EP i Indicates i The number of samples correctly identified in the class, EN Represents the total number of samples correctly identified as non-target classes, UP i Indicates i The number of samples in the class that are misclassified as other classes, FAP i Indicates that other classes are misclassified as i The number of samples of the class, N i Indicatesi The total number of samples of the class, N represents the total number of samples, n Represents the total number of categories.

[0052] In order to verify the effectiveness of the dual-branch hierarchical spectral feature perception network (DBHSNet) in the freshness detection of chilled mutton, an ablation experiment and a comparative analysis of the classification indicators of the typical algorithm model were set up, and the detection results were output.

[0053] On the one hand, a system performance detection and evaluation framework of CNN, SVM, LightGBM, RF and DBHSNet is constructed to ensure the accuracy of the results of mutton freshness detection. The preprocessed cold fresh mutton full-frequency spectrum dataset is used as the input of the DBHSNet network, and the spectral band information obtained by different combination methods is used as the focus of the local branch. The detection performance comparison of the model under different preprocessing-feature selection combinations is shown in Table 3.

[0054] Table 3 Comparison of detection performance of models under different preprocessing-feature selection combinations By comparing the experimental results, the DBHSNet model performs best in all indicators under the FD-IFS combination method. On the one hand, its accuracy is 99.72%, which is 0.97% higher than the second-best model LightGBM, and the weighted F1 score is greater than 99.5%, indicating that the model has good stability in multi-class and sample imbalance. On the other hand, the weighted precision and weighted recall of the model exceed 99%, indicating that the model can efficiently use intermediate features when subdividing freshness levels. Under food safety, DBHSNet can prevent spoiled mutton from entering the market as much as possible in practical applications to reduce health hazards and economic losses. Secondly, for different preprocessing methods, FD and MSC improve the model performance by extracting frequency domain features, correcting scattering noise, and enhancing the stability of chemical features, respectively. Therefore, both contribute more to the extraction of relevant features of freshness. On the contrary, although the moving average (MA) can smooth the noise, it may cause the loss of some corruption signals, reflecting its limitations in freshness detection. In addition, under the FD and MSC methods, CNN, LightGBM, and RF showed higher performance, indicating that the two preprocessing methods can more appropriately handle the noise and redundancy in the original spectral data.

[0055] On the other hand, an ablation experiment of the DBHSNet model is set up, and the experimental results are shown in Table 4.

[0056] Table 4 Ablation experiment results of DBHSNet It can be seen from the ablation experiment results in Table 4 that with the gradual enhancement and combination comparison of modules, the overall performance of the model shows obvious nonlinear gain. First, the HCM (hierarchical classification) module shows basic optimization ability in a single enabled state. When only HCM is enabled, the accuracy of the three groups of experiments is significantly improved, with the FD-MIM group increasing by 3.33%, the FD-IFS group increasing by 2.36%, and the MSC-MIM group increasing by 2.92%. In addition, the difference between the weighted F1 score and the accuracy of the model is always less than 0.07%, indicating that it can enhance the inter-class discrimination of the freshness feature. Second, in the FD-MIM group, the PBCA+HCM combination is 2.08% higher than the MSMHA+HCM, and the gain is expanded to 5.83% after adding MSMHA to form a full module combination. The super-superposition results show that the hierarchical classifier constructed by HCM can effectively mine the cross-scale feature fusion information of MSMHA. The module combination shows the specificity advantage of the method. Therefore, in actual detection applications, the module combination strategy needs to be customized according to the data characteristics. Third, the full module collaboration showed a performance peak in freshness detection. The accuracy of the FD-IFS group increased by 11.80% compared with the baseline, and the fluctuation of the index was less than 1%, indicating that FD-IFS formed a positive coupling with the spectral feature perception ability of the model. The weighted indexes of the FD-MIM and FD-IFS groups were greater than 99% when the full module was activated. Therefore, the PBCA, MSMHA and HCM proposed in the present invention can effectively improve the performance of the model when combined, and enhance the expressive ability of the features and the robustness of the network, which is of great value for real-time quality monitoring of fresh chilled mutton.

[0057] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0058] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A nondestructive detection method for freshness of chilled mutton based on a double-branch hierarchical spectral feature perception network, characterized in that: The specific steps are as follows: Obtain mutton samples of different freshness, measure freshness index and collect hyperspectral images; Determining the sample label of the corresponding training sample according to the freshness index of each of the mutton samples; Processing the hyperspectral images using different preprocessing and feature selection combination methods as sample features of training samples, and constructing several training data sets corresponding to the combination methods; Constructing a dual-branch hierarchical spectral feature perception network as a detection model, and using different training data sets to train them respectively; The evaluation indicators of each trained detection model were calculated, and the detection model corresponding to the optimal preprocessing and feature selection combination method was used as the final freshness detection model for non-destructive detection of the freshness of fresh mutton.

2. According to claim 1, a nondestructive detection method for freshness of chilled mutton based on a double-branch hierarchical spectral feature perception network is characterized in that: The freshness indicators include: volatile basic nitrogen, total colony count and approximate E. coli count; the sample label is the mutton freshness grade, including: fresh, sub-fresh, slightly corrupt and corrupt.

3. According to claim 1, a nondestructive detection method for freshness of chilled mutton based on a double-branch hierarchical spectral feature perception network is characterized in that: The preprocessing includes: SG filter, multivariate scattering correction, standard normal variable transformation, first-order derivative and moving average method; the feature selection includes: maximum mutual information minimization feature selection method and incremental feature selection method.

4. According to claim 1, a nondestructive detection method for freshness of chilled mutton based on a double-branch hierarchical spectral feature perception network is characterized in that: The sample features include global feature data and local feature data; the global feature data is the image data containing all band information after the hyperspectral image is preprocessed, and the local feature data is the image data containing part of the band information after feature selection of the global feature data.

5. According to claim 4, a nondestructive detection method for freshness of chilled mutton based on a double-branch hierarchical spectral feature perception network is characterized in that: The dual-branch hierarchical spectral feature perception network includes: a feature extraction module, a feature interaction module, a feature fusion module and an output module connected in sequence; The feature extraction module performs feature extraction on the global feature data and the local feature data respectively to obtain global features and local features; The feature interaction module uses a bidirectional cross attention mechanism to perform information interaction on the global features and the local features to obtain optimized global features and optimized local features; The feature fusion module performs multi-scale enhancement on the optimized global features and the optimized local features, and fuses the multi-scale features using a multi-head attention mechanism to obtain a fused feature; The output module outputs the recognition result using a hierarchical classifier based on the fusion features.

6. According to claim 5, a nondestructive detection method for freshness of chilled mutton based on a double-branch hierarchical spectral feature perception network is characterized in that: The feature extraction module includes a global feature extraction branch and a local feature extraction branch, each feature extraction branch is composed of a convolution layer, an activation function layer and a pooling layer connected in series in sequence, the global feature extraction branch performs feature extraction on the global feature data, and the local feature extraction branch performs feature extraction on the local feature data.

7. According to claim 5, a nondestructive detection method for freshness of chilled mutton based on a double-branch hierarchical spectral feature perception network is characterized in that: The feature interaction module includes a position encoding unit and a bidirectional cross attention unit; The position encoding unit performs position encoding on the global feature and the local feature respectively to generate a corresponding dynamic position vector, and the formula is: ; in, is the band index, is the position encoding dimension, is the dimension of the input features; The bidirectional cross attention unit constructs a bidirectional interactive channel between global features and local features through bidirectional cross attention, and performs information flow between global and local features. The formula is: ; in, , They are respectively used to optimize global features and local features. , They are global features and local features respectively.

8. According to claim 5, a nondestructive detection method for freshness of chilled mutton based on a double-branch hierarchical spectral feature perception network is characterized in that: The feature fusion module includes: a multi-scale pooling layer, a multi-head attention layer and a fully connected layer connected in sequence; The multi-scale pooling layer extracts features of different granularities through different scale pooling strategies. The formula is: ; in, , They are respectively used to optimize global features and local features. , They are the corresponding pooled results, , Represent global pooling and local pooling respectively; The multi-head attention layer is equipped with four parallel attention heads. Each attention head takes the multi-scale pooled features as input and first performs a linear transformation to generate the corresponding query, key and value. The formula is: ; in, is the input feature, , and Respectively The query, key, and value of each attention head, , and Respectively The linear transformation matrix of the query, key, and value corresponding to each attention head; Then calculate the attention of each attention head , the formula is: ; in, is the dimension of the key, represents the activation function, Represents the square root operation, Represents a matrix transpose operation; The fully connected layer concatenates the outputs of all attention heads and obtains fused features through linear transformation. , the formula is: ; in, represents the fully connected layer, is the linear transformation matrix, Represents a concatenation operation.

9. According to claim 5, a nondestructive detection method for freshness of chilled mutton based on a double-branch hierarchical spectral feature perception network is characterized in that: The hierarchical classifier includes a coarse-grained classifier and a fine-grained classifier. First, the coarse-grained classifier is used to classify the fusion features. Divide into major categories and obtain intermediate features ; Then, the fine-grained classifier is used to perform refined classification based on the intermediate features to obtain the final detection result. , the specific formula is as follows: ; ; in, are the weight and bias of the coarse-grained classifier, are the weight and bias of the fine-grained classifier, is the activation function.

10. A non-destructive detection method for freshness of chilled mutton based on a double-branch hierarchical spectral feature perception network according to claim 9, characterized in that: The coarse-grained classifier and the fine-grained classifier both use the cross entropy loss function, and by introducing dynamic weights, the total loss function of the output module is obtained. The specific formula is: ; in, represents the total loss function, They are the loss functions of the coarse-grained classifier and the fine-grained classifier respectively; Represents dynamic weight, the formula is: ; ; in, Represent the training rounds and the maximum training rounds respectively, , They represent the dynamic weights at the early and late stages of training, respectively.

Citation Information

Patent Citations

  • Mechanical fault prediction method based on hierarchical convolutional neural network

    CN109406118A

  • Traffic sign target detection method based on multilevel divide-and-conquer network

    CN113392930A

  • Hyperspectral detection method for ripeness of camellia oleifera fruits based on deep learning and sorting equipment

    CN114112932A

  • Hyperspectral image denoising method based on residual learning and mixed domain attention

    CN114972075A

  • Painting intelligent scoring method and system based on attention convolutional network

    CN116310491A

Cited By

  • Signal unmixing and multi-task learning fused fresh corn quality detection method

    CN120489982A

  • A fresh corn quality detection method fusing signal unmixing and multi-task learning

    CN120489982B

  • Blueberry fresh-keeping quality prediction model construction method and prediction method

    CN121278323A

  • A method for constructing a blueberry fresh-keeping quality prediction model and a prediction method

    CN121278323B