Hyperspectral pork freshness grade assessment method based on spectral and spatial dual-branch attention
The hyperspectral pork freshness grading method using spatial-spectral dual-branch attention solves the problems of high-dimensional redundancy and heterogeneous noise interference in hyperspectral non-destructive testing of pork quality, and realizes rapid, non-destructive, and automated grading of pork freshness, which is suitable for industrial production lines.
Patent Information
- Application Number
- CN202611207988.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-11
- Publication Date
- 2026-11-24
Smart Images

Figure CN123155448A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of non-destructive testing of food quality and artificial intelligence computer vision technology, and in particular to a hyperspectral meat quality feature analysis and rapid automatic grading method suitable for meat processing production lines, specifically a hyperspectral method for evaluating the freshness grade of pork based on spatial-spectral bibranch attention. Background Technology
[0002] Rapid assessment and grading of pork freshness is a key technical step in ensuring food safety and regulating market pricing. With the increasing demands of modern meat processing and industrialized sorting, achieving rapid, non-destructive, and automated discrete grading of pork freshness (e.g., sorting into fresh, acceptable, and spoiled meat) in actual production lines has become a critical technical challenge that urgently needs to be addressed.
[0003] Current meat quality testing and analysis methods mainly rely on traditional physicochemical and biochemical testing methods and conventional machine learning classification techniques. Traditional physicochemical testing methods (such as volatile basic nitrogen (TVB-N) determination and total bacterial count (TVC) determination) typically require destructive sampling, which is time-consuming and difficult to meet the real-time and high-volume non-destructive testing requirements of industrial production lines. Meanwhile, while some spectral analysis methods based on traditional machine learning can achieve non-destructive assessment to a certain extent, they heavily rely on manual feature engineering and struggle to automatically extract deep discriminative features when faced with massive amounts of high-dimensional spatial-spectral combined data. They are also prone to prediction bias under complex environmental conditions and lack stability.
[0004] In practical hyperspectral imaging (HSI) detection environments, the extraction of spatial spectral features from meat is severely hampered by a variety of complex factors. On one hand, hyperspectral data suffers from the curse of spatial dimensionality and redundancy interference. It contains hundreds of continuous bands, with high collinearity between adjacent bands, and is mixed with a large amount of redundant information useless for freshness grading. Directly inputting this data into a deep network can easily lead to the submergence of deep discriminative features. On the other hand, pork samples exhibit strong spatial heterogeneity noise. Surface fat, connective tissue, and localized sap exudation cause high-brightness reflections, creating strong visual interference in the spatial image and severely affecting the model's accurate focusing and extraction of effective spectral features from pure muscle regions.
[0005] Furthermore, the decline in pork freshness is essentially a continuous biochemical evolution process from fresh to spoilage, and this continuity leads to extreme ambiguity in category boundaries. Samples at the sub-fresh or acceptable boundary are easily confused with fresh or spoiled samples due to their internal chemical composition evolution and appearance texture, placing extremely high demands on the feature discrimination capabilities of classification networks. Existing conventional models often struggle to effectively separate and independently represent samples at each critical state when dealing with such ambiguous boundaries caused by continuous gradients.
[0006] In recent years, deep learning technology has made significant progress in the field of hyperspectral image classification. Convolutional Neural Networks (CNNs) are good at extracting local spatial-spectral features, and Transformers can model global dependencies. However, existing methods based on the combination of CNNs and Transformers still have the following problems in hyperspectral pork freshness detection: (1) Most methods directly transfer the architecture applicable to remote sensing image classification to the field of meat detection, ignoring the spatial noise of fat / connective tissue and the interference of juice reflection unique to pork samples; (2) Existing methods do not fully consider the problem of category boundary blurring caused by the continuous biochemical evolution of pork freshness when extracting spatial-spectral features, and lack special modeling for long-range dependencies in the spectral dimension; (3) In the dual-branch structure, the spatial branch and the spectral branch usually operate independently, and there is a lack of adaptive feature recalibration mechanism for meat detection scenarios.
[0007] In summary, existing technologies for hyperspectral nondestructive testing of pork quality still face challenges in simultaneously addressing issues such as high-dimensional redundancy dimensionality reduction, resistance to heterogeneous noise, and accurate classification of fuzzy boundaries. There is an urgent need to propose a hyperspectral pork freshness assessment model and method that can adapt to high-dimensional complex spatial spectral data, adaptively shield heterogeneous spatial noise, and possess highly sensitive feature decoupling capabilities for category boundaries. Summary of the Invention
[0008] To address the shortcomings of existing technologies in hyperspectral nondestructive testing of pork quality, such as band redundancy, heterogeneous spatial noise interference, and blurred boundaries between adjacent freshness grades, this invention provides a hyperspectral method for assessing pork freshness grades based on spatial-spectral dual-branch attention. This method uses a unified three-dimensional hyperspectral tensor as input, sequentially connecting dimensionally decoupled pseudo-3D feature mining, spatial-spectral dual-branch recalibration, branch feature fusion, band-sequential Transformer global modeling, and discrete grade output in both the tensor dimension and data stream. This reduces spatial-spectral redundancy while suppressing interference caused by fat, connective tissue, and juice reflections, and enhances the ability to distinguish between adjacent freshness grades. To achieve the above objectives, this invention employs the following technical solution.
[0009] A hyperspectral method for assessing pork freshness based on spatial-spectral dual-branch attention includes: Step 1: Obtain hyperspectral image data of pork samples, and perform radiometric correction and spectral smoothing on the hyperspectral image data to obtain a preprocessed hyperspectral tensor; Step 2: Use dimensional decoupled pseudo 3D convolution to extract local spatial-spectral features from the preprocessed hyperspectral tensor. First, use spatial convolution kernels to perform spatial-dimensional texture feature convolution on each band plane to obtain spatial texture features. Then, use spectral convolution kernels to perform spectral-dimensional sequence convolution on the spatial texture features along the band axis to couple spatial texture and spectral response into spatial-spectral joint features. Step 3: Using the joint spatial-spectral features as the common input of the spatial branch and the spectral branch, the spatial branch generates a spatial mask through pooling and spatial convolution, and performs spatial recalibration on the joint spatial-spectral features to obtain spatial recalibrated features. The spectral branch generates band weights through global pooling and a fully connected network, and performs spectral recalibration on the joint spatial-spectral features to obtain spectral recalibrated features. The spatial recalibrated features and the spectral recalibrated features are then fused into attention fusion features. Step 4: Using the attention fusion feature as input, flatten each two-dimensional spatial plane of the attention fusion feature in the band dimension into a sequence unit, arrange them in band order and add band position encoding, establish global correlation between different band units through a multi-head self-attention mechanism to obtain global spectral features; Step 5: Aggregate the global spectral features along the band sequence dimension into a global feature vector, map it into logical values for each category through a multilayer perceptron, and then map it into the predicted probability of each freshness level through a Softmax function. The level corresponding to the highest probability is used as the freshness level assessment result of the pork sample.
[0010] Furthermore, step 2 specifically includes: Step 2.1: Use Spatial convolution kernel Slide within each band plane to extract spatial texture features. : in, Indicates band In output space location Texture features at the location; For the spatial convolution kernel in the th The weight of each core position; This is the kernel position index; The output index starts with 0, therefore Indicates the current Input response within the spatial neighborhood; Step 2.2: Using the aforementioned spatial texture features For input, use spectral convolution kernel Sliding along the band axis yields the joint spatial-spectral features. : in, Indicates the spatial-spectral joint feature location in the output space. Location, band The value at that location, For the spectral convolution kernel in the th The weight of each core position; For spectral convolution kernel position index; for band For cases outside the spectral dimension range, mirror filling is used.
[0011] Furthermore, step 3 specifically includes: Step 3.1: Perform average pooling and max pooling on the spatial-spectral joint features along the spectral dimension, and then concatenate the pooling results. Spatial convolution followed by the application of a sigmoid activation function generates a spatial mask. : The space mask After broadcasting along the spectral dimension, the spatial recalibration feature is obtained by multiplying it element-wise with the spatial-spectral joint feature. ;in, It is a joint feature of the spatial spectrum; Step 3.2: Perform global average pooling on the joint spatial-spectral features along the spatial dimension to obtain the spectral statistical vector. , This represents the total number of bands; band weights are calculated using a two-layer fully connected network. : The band weight After broadcasting along two spatial dimensions, the spectral recalibration features are multiplied element-wise with the joint spatial-spectral features to obtain the spectral recalibration features. ; Step 3.3: Add the spatial recalibration features and the spectral recalibration features element-wise to obtain the attention fusion features. .
[0012] Furthermore, step 4 specifically includes: Step 4.1: For the first Each band, representing the attention fusion feature in each two-dimensional spatial plane of the band dimension. Flattened ,according to After arrangement, through the projection matrix Mapped to 3D embedding space, and add band position coding. The embedded sequence is obtained. , Indicates the total number of bands; where, , Represents an embedded sequence The Row vectors; Let be the side length of the output space after spatial convolution. The flattened length of the spatial plane; Step 4.2: From the embedded sequence The query matrix is obtained through linear projection. Key matrix Sum matrix Calculate single-head self-attention: in, The dimension of the key vector is given. The outputs of multiple attention heads are processed through concatenation, output projection, residual connections, layer normalization, and a feedforward network to obtain the global spectral features. .
[0013] Furthermore, step 5 specifically includes: The global feature vector is obtained by averaging and aggregating the global spectral features along the band sequence. ,in, Indicates the first Global spectral feature vectors for each band Represents the total number of bands; the global feature vector Mapped by a multilayer perceptron to 3D logical vector ,in For the first The classification logic value for each freshness level. ; The Softmax function is used to convert the above 3D logical vector mapping to the corresponding Predicted probability of each freshness grade: in, Indicates that the sample belongs to the first Predicted probability of each freshness grade; The index for summing the categories in the denominator of the Softmax function; .
[0014] Furthermore, the spatial mask in step 3 is used to softly shield the spatially heterogeneous noise region on the surface of the pork sample caused by adipose tissue, connective tissue, edge shadows and juice reflection, and the band weight is used to enhance the response of sensitive bands related to biochemical changes in pork freshness.
[0015] Furthermore, in step 4, each two-dimensional spatial plane of the attention fusion feature in the band dimension is used as an independent sequence unit, and the global correlation established by the multi-head self-attention mechanism is a non-local dependency relationship between different bands in the spectral dimension, which is used to capture the long-range spectral change law in the continuous biochemical evolution process of pork from fresh to spoilage.
[0016] Furthermore, in step 2, the spatial dimension feature convolution is performed first, followed by the spectral dimension sequence convolution, thus decoupling the spatial texture features. This makes the spatial texture features the direct input for the spectral convolution kernel to couple the spectral response. The spatial-spectral joint features simultaneously contain the joint change information between the pork surface texture structure information and the spectral response of adjacent bands.
[0017] Furthermore, it also includes an end-to-end joint optimization step: taking the complete data chain formed by steps 1 to 5 as a whole, and minimizing the cross-entropy loss function. Backpropagation is performed to update all trainable parameters, where The One-hot code for the True Freshness Grade label is in the first... Values that can be taken on a class.
[0018] Furthermore, the radiometric correction in step 1 includes: acquiring the original image. Image with a completely black background and standard whiteboard images Calculate the normalized reflectance image using the following formula. The spectral smoothing process employs the Savitzky-Golay smoothing algorithm to denoise the spectral sequence of each spatial pixel.
[0019] The beneficial effects of this invention are: (1) The present invention uses the three-dimensional hyperspectral tensor of pork samples as a unified data carrier that runs through all processing modules. It directly converts the complex spectral signal reflecting the morphology and composition of pork into the probability of freshness level, avoiding the limitations of traditional physical and chemical detection which is time-consuming and destructive, and is more suitable for large-scale non-destructive testing in industrial production lines.
[0020] (2) At the local feature extraction end, this invention splits the standard 3D convolution into two low-dimensional convolutions (3×3×1 spatial convolution + 1×1×3 spectral convolution) in the order of spatial first and then spectral, so that the spatial texture features It becomes the explicit input for spectral response coupling and the output is coupled with the original. Figure 1 Joint spatial-spectral characteristics While reducing the number of parameters and computational cost, it preserves the joint information of pork texture and adjacent band response; (3) At the anti-interference recalibration end, the spatial branch and the spectral branch are the same. Parallel modeling: Spatial branching Soft shielding is applied to areas such as fat, connective tissue, marginal shadows, and fluid reflections, with spectral branches passing through... The band responses related to changes in freshness are reweighted; the outputs of the two branches are fused into... This allows spatial denoising and band selection to work together in subsequent global modeling; (4) In the global feature modeling end, the present invention uses Λ Each band slice is used as a sequence unit. After adding band position encoding, non-local dependencies between arbitrary bands are established through multi-head self-attention. From the data structure perspective, this ensures that the learned long-range correlation corresponds to the spectral dimension rather than the spatial dimension, thereby enhancing the ability to distinguish between fuzzy boundary samples such as near-fresh ones. (5) The above steps are passed The clear data chain is connected step by step to form a collaborative processing mechanism of "local spatial spectrum decoupling - heterogeneity interference suppression - key band reweighting - cross-band long-range correlation - discrete level output", which directly outputs the freshness level probability that can be called by the robotic arm or sorting baffle. Attached Figure Description
[0021] Figure 1 This is a diagram of the overall architecture of the hybrid spatial spectrum hierarchical network based on spatial spectrum dual-branch attention in this invention. Figure 2 This is a schematic diagram of the pseudo-3D spatial spectrum joint feature extraction module and decoupling principle of the present invention; Figure 3 This is a schematic diagram of the spatial spectrum dual-branch attention mechanism module of the present invention. Detailed Implementation
[0022] The present invention will now be described in detail with reference to the accompanying drawings. Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention. The directional terms such as left, center, right, top, and bottom in the embodiments of the present invention are only relative concepts or referenced to the normal use state of the product, and should not be considered restrictive.
[0023] This invention provides a hyperspectral method for assessing the freshness grade of pork based on spatial-spectral dual-branch attention. For example... Figure 1 As shown, this method connects preprocessed hyperspectral tensors, spatial texture features and spatial-spectral joint features, spatial masks and band weights, attention fusion features, embedded sequences, global spectral features, and predicted probabilities via a unified data link to achieve automated and non-destructive determination of pork freshness. The specific implementation process is as follows: Step 1: Hyperspectral Data Preprocessing This step acquires optical information from pork samples using hardware devices and eliminates physical noise introduced by ambient light and device dark current, aiming to provide a high-quality, distortion-free, standardized data source for subsequent deep learning networks.
[0024] Step 1.1: Original Image Acquisition and Black and White Correction This step completes the initial conversion from the biochemical state of the real physical world to digital signals and establishes a unified imaging benchmark.
[0025] Step 1.1.1, Hardware Parameter Setting: Use a hyperspectral camera to scan the pork sample, and set the spectral range to 400nm. 1000nm. This wavelength range covers the comprehensive reflectance response related to changes in myoglobin state, water content, lipid content, and protein state in the visible and near-infrared regions.
[0026] Step 1.1.2, Radiometric Correction Calculation: Acquire the original image Image with a completely black background and standard whiteboard images The normalized reflectance image is calculated using the following formula: in, Spatial location In the band Normalized reflectance at that location; , and These represent the grayscale values of the original image, the image with a completely black background, and the standard white image at this location and in this band, respectively. During correction, ensure... .
[0027] Step 1.2: Data Reconstruction and Spatial Spectrum Preprocessing This step transforms unstructured image data into tensors adapted to the input format of a 3D neural network and further filters out high-frequency random fluctuations.
[0028] Step 1.2.1, Target Region of Interest (ROI) Extraction: Background is removed using a threshold segmentation algorithm, and the extracted region is [size missing]. hyperspectral tensor .in Let be the side length of the space. Λ This represents the total number of bands; in subsequent formulas, Indicates the current band index, and .
[0029] Step 1.2.2, Signal Smoothing Processing: The Savitzky-Golay smoothing algorithm is used to denoise the spectral sequence of each spatial pixel. The calculation formula is as follows: in, Center band Nearby The original reflection response of each band; For the first The smoothed response of each band; The offset index within the window; The radius of the window; Fit weights to Savitzky-Golay; As the weight normalization factor, take ,when Normalized After smoothing, Write back the corresponding band position to form the input tensor for subsequent steps. .
[0030] Step 2: Pseudo-3D Spatial-Spectral Joint Feature Extraction Combination Figure 2 As shown, this step decomposes standard 3D convolution into two consecutive stages: spatial convolution and spectral convolution, and then... The data chain enables spatial texture features to become a direct input for spectral response coupling.
[0031] Step 2.1: Spatial Dimension Feature Convolution This step focuses on extracting the physical morphology and tissue structure characteristics of pork in a two-dimensional plane.
[0032] Step 2.1.1, Space Core Design: Adopting Spatial convolution kernel Sliding within each band plane, the output space side length is [length missing] when using effective convolution. .
[0033] Step 2.1.2, Texture Feature Mapping: Using preprocessed hyperspectral tensors Using this as input, extract spatial texture features. : in, For band In output space location Texture features at the location; For the spatial convolution kernel in the th The weight of each core position; This is the kernel position index; The output index starts with 0, therefore Indicates the current Input response within the spatial neighborhood.
[0034] This operation performs multiplication and addition along the spatial dimension, specifically extracting intuitive visual discriminative features such as the texture of the pork surface, the distribution of fat particles, and the direction of muscle fibers.
[0035] Step 2.2, Spectral Dimension Sequence Convolution This step uses spatial texture features Using this as input, the coupling relationship between the responses of adjacent bands at the same location is extracted while keeping the spatial position unchanged.
[0036] Step 2.2.1, Spectral kernel design: Immediately following spatial convolution, use... spectral convolution kernel Slide along the band axis and fill the band boundaries to preserve the output. Λ Each band position.
[0037] Step 2.2.2, Spectral Feature Coupling: Convolve adjacent spectral responses along the band dimension to obtain joint spatial-spectral features. : in, Indicates the spatial-spectral joint feature location in the output space. Location, band The value at; For the spectral convolution kernel in the th The weight of each core position; For the spectral convolution kernel position index; For cases outside the spectral dimension range, mirror filling is used.
[0038] This step does not directly identify any specific chemical bond. Instead, it utilizes the changes in reflectance response across adjacent wavelengths caused by changes in the state of water, pigments, lipids, and proteins in pork to couple spatial texture with spectral response. This serves as the input for step 3.
[0039] Step 3: Spatial Spectrum Two-Branch Attention Recalibration Combination Figure 3 As shown, this step uses the joint spatial-spectral features Using the spatial branch and spectral branch as common inputs, spatial recalibration features are generated respectively. and spectral recalibration characteristics Then, they are fused into attention fusion features. .
[0040] Step 3.1, Spatial Attention Branch This step aims to eliminate visual misleading effects caused by glistening juices on the surface of meat, shadows at the edges, or large chunks of pure fat.
[0041] Step 3.1.1, Spatial Statistical Compression: Combining Spatial and Spectral Features along the Spectral Dimension Perform average pooling and max pooling respectively to obtain and .
[0042] Step 3.1.2, Spatial Weight Generation: The pooling results are concatenated and then... Convolution is performed and a sigmoid activation function is applied to generate a spatial mask. Used to shield against reflections from fat / connective tissue / sap: in, Indicates splicing along the channel; express Spatial convolution; This is the Sigmoid function.
[0043] Step 3.1.3, Spatial Feature Recalibration: Recalibrate the spatial mask. Combined features of broadcasting along the spectral dimension with spatial spectrum Element-wise multiplication yields spatial recalibration features. .
[0044] Step 3.2, Spectral Attention Branch This step aims to address the issues of high collinearity and redundant background information among hundreds of bands in the hyperspectral spectrum.
[0045] Step 3.2.1, Global Context Modeling: Joint Features of Spatial Spectrum Along Spatial Dimension Perform global average pooling to obtain Figure 3 The spectral statistical vector shown .
[0046] Step 3.2.2, Band Correlation Learning: Band weights are calculated by first reducing and then increasing the dimensionality using two fully connected layers. : in, and This is the weight matrix for two fully connected layers; This refers to the band channel compression ratio; This is the spectral band weight vector.
[0047] Step 3.2.3, Spectral Feature Recalibration: Adjust band weights Joint features with spatial spectrum after broadcasting along two spatial dimensions Element-wise multiplication yields the spectral recalibration characteristics. .
[0048] Step 3.3, Dual-branch feature fusion: Spatial recalibration features Spectral recalibration characteristics Element-wise addition is performed to obtain attention fusion features. . As input to step 4, its spatial dimensions remain unchanged. .
[0049] Step 4: Transformer Global Long-Range Evolution Modeling This step uses attention fusion characteristics As input, the two-dimensional spatial plane corresponding to each band is taken as a sequence unit, and the global correlation between different band units is established through Transformer.
[0050] Step 4.1: Serialization Feature Embedding This step converts the three-dimensional feature tensor into a sequence that preserves the band arrangement order and explicitly adds band position encoding so that self-attention can utilize both band feature content and band order information simultaneously.
[0051] Step 4.1.1: Flatten by band: Attention fusion feature Each two-dimensional spatial plane in the band dimension is represented as ,in For the first Each band corresponds to a two-dimensional spatial plane. Flattened , The length of the output space after spatial convolution in step 2.1 is given. This is the flattened length of the spatial plane. (According to...) After arranging, the length is obtained as The band characteristic sequence.
[0052] Step 4.1.2, Linear Projection and Position Encoding: Through the projection matrix Map each band vector to 3D embedding space, and add band position coding. The embedded sequence is obtained. ,in, , Represents an embedded sequence The Row vectors.
[0053] Step 4.2, Multi-head Self-Attention Calculation This step calculates the correlation between any two band units in different subspaces using multiple attention heads, and then fuses the multi-head outputs into a global spectral feature. .
[0054] Step 4.2.1, Query key-value mapping: For the first... An attention head, composed of embedded sequences The query matrix is obtained through linear projection. Key matrix Sum matrix .
[0055] Step 4.2.2, Self-Attention Score: The single-head calculation formula is as follows: in, The dimension of the key vector is given; the outputs of multiple attention heads are concatenated, projected, connected in the output, normalized by layers, and fed forward to obtain the global spectral features. This serves as the sole input for step 5.
[0056] Step 5: Discrete and graded output This step will analyze the global spectral characteristics. Clustering along the band sequence into a global feature vector Then, it is mapped to a multilayer perceptron containing a Dropout layer. 3D classification logistic vector The final output probability vector .
[0057] Step 5.1: Feature Clustering and Mapping This step compresses and aggregates high-dimensional deep feature maps and introduces an anti-overfitting mechanism to improve engineering robustness.
[0058] Step 5.1.1, Band sequence aggregation: Global spectral features The global feature vector is obtained by averaging and aggregating along the band sequence dimension. ,in Indicates the first Global spectral feature vectors for each band.
[0059] Step 5.1.2, Fully Connected Nonlinear Mapping: Mapping the global feature vector Input a multilayer perceptron with a Dropout layer, and obtain 3D logical vector ,in For the first The classification logic value for each freshness level. .
[0060] Step 5.2: Hierarchical Output and Model Optimization This step performs the final mathematical transformation, outputting physical classification instructions that can be directly invoked by the assembly line robotic arm or sorting baffle, and guiding the model to learn itself.
[0061] Step 5.2.1, Softmax probability grading: Classification logical values... Mapped to Predicted probability of each freshness grade : in, For the sample to belong to the first Predicted probability of each freshness grade; For the first Logical values; The index for summing the categories in the denominator of the Softmax function; The total number of freshness grades, and The freshness grade of the pork sample is determined by the grade corresponding to the highest predicted probability.
[0062] Step 5.2.2, Optimization of Cross-Entropy Loss Function: During the model training phase, the cross-entropy loss function is optimized by minimizing the cross-entropy loss. Optimize network parameters: in, The One-hot code for the True Freshness Grade label is in the first... Values on the class; This represents the predicted probability for the corresponding category; This is the cross-entropy loss. According to... Reverse update all trainable parameters, making End-to-end joint optimization of the data chain.
[0063] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely illustrative of the principles of the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the present invention as claimed. The scope of protection of the present invention is defined by the appended claims and their equivalents.
Claims
1. A hyperspectral method for assessing the freshness grade of pork based on spatial-spectral dual-branch attention, characterized in that: include: Step 1: Obtain hyperspectral image data of pork samples, and perform radiometric correction and spectral smoothing on the hyperspectral image data to obtain a preprocessed hyperspectral tensor; Step 2: Use dimensional decoupled pseudo 3D convolution to extract local spatial-spectral features from the preprocessed hyperspectral tensor. First, use spatial convolution kernels to perform spatial-dimensional texture feature convolution on each band plane to obtain spatial texture features. Then, use spectral convolution kernels to perform spectral-dimensional sequence convolution on the spatial texture features along the band axis to couple spatial texture and spectral response into spatial-spectral joint features. Step 3: Using the joint spatial-spectral features as the common input to the spatial branch and the spectral branch, the spatial branch generates a spatial mask through pooling and spatial convolution, and spatially recalibrates the joint spatial-spectral features to obtain spatially recalibrated features. The spectral branch generates band weights through global pooling and a fully connected network, and spectrally recalibrates the joint spatial-spectral features to obtain spectral recalibrated features. The spatial recalibrated features and the spectral recalibrated features are then fused into attention fusion features. Step 4: Using the attention fusion feature as input, flatten each two-dimensional spatial plane of the attention fusion feature in the band dimension into a sequence unit, arrange them in band order and add band position encoding, establish global correlation between different band units through a multi-head self-attention mechanism to obtain global spectral features; Step 5: Aggregate the global spectral features along the band sequence dimension into a global feature vector, map it into logical values for each category through a multilayer perceptron, and then map it into the predicted probability of each freshness level through a Softmax function. The level corresponding to the highest probability is used as the freshness level assessment result of the pork sample.
2. The hyperspectral pork freshness grading method based on spatial-spectral dual-branch attention according to claim 1, characterized in that, Step 2 specifically includes: Step 2.1: Use Spatial convolution kernel Slide within each band plane to extract spatial texture features. : in, Indicates band In output space location Texture features at the location; For the spatial convolution kernel in the th The weights of each core position; This is the kernel position index; The output index starts with 0, therefore Indicates the current Input response within the spatial neighborhood; Step 2.2: Using the aforementioned spatial texture features For input, use spectral convolution kernel Sliding along the band axis yields the combined spatial and spectral features. : in, Indicates the spatial-spectral joint feature location in the output space. Location, band The value at that location, For the spectral convolution kernel in the th The weights of each core position; For spectral convolution kernel position index; for band For cases outside the spectral dimension range, mirror filling is used.
3. The hyperspectral pork freshness grading method based on spatial-spectral dual-branch attention according to claim 1, characterized in that, Step 3 specifically includes: Step 3.1: Perform average pooling and max pooling on the spatial-spectral joint features along the spectral dimension, and then concatenate the pooling results. Spatial convolution followed by the application of a sigmoid activation function generates a spatial mask. : The space mask After broadcasting along the spectral dimension, the spatial recalibration feature is obtained by multiplying it element-wise with the spatial-spectral joint feature. ;in, It is a joint feature of the spatial spectrum; Step 3.2: Perform global average pooling on the joint spatial-spectral features along the spatial dimension to obtain the spectral statistical vector. , This represents the total number of bands; band weights are calculated using a two-layer fully connected network. : The band weight After broadcasting along two spatial dimensions, the spectral recalibration features are multiplied element-wise with the joint spatial-spectral features to obtain the spectral recalibration features. ; Step 3.3: Add the spatial recalibration features and the spectral recalibration features element-wise to obtain the attention fusion features. .
4. The hyperspectral pork freshness grading method based on spatial-spectral dual-branch attention according to claim 1, characterized in that, Step 4 specifically includes: Step 4.1: For the first Each band, representing the attention fusion feature in each two-dimensional spatial plane of the band dimension. Flattened ,according to After arrangement, through the projection matrix Mapped to 3D embedding space, and add band position coding. The embedded sequence is obtained. , Indicates the total number of bands; where, , Represents an embedded sequence The Row vectors; Let be the side length of the output space after spatial convolution. The flattened length of the spatial plane; Step 4.2: From the embedded sequence The query matrix is obtained through linear projection. Key matrix Sum matrix Calculate single-head self-attention: in, The dimension of the key vector is given. The outputs of multiple attention heads are concatenated, projected, connected via residuals, normalized through layers, and processed by a feedforward network to obtain the global spectral features. .
5. The hyperspectral pork freshness grading method based on spatial-spectral dual-branch attention according to claim 1, characterized in that, Step 5 specifically includes: The global feature vector is obtained by averaging and aggregating the global spectral features along the band sequence. ,in, Indicates the first Global spectral feature vectors for each band Represents the total number of bands; the global feature vector Mapped by a multilayer perceptron to 3D logical vector ,in For the first The classification logic value for each freshness level. ; The Softmax function is used to convert the above 3D logical vector mapping to the corresponding Predicted probability of each freshness grade: in, Indicates that the sample belongs to the first Predicted probability of each freshness grade; The index for summing the categories in the denominator of the Softmax function; .
6. The hyperspectral pork freshness grading method based on spatial-spectral dual-branch attention according to claim 1, characterized in that, The spatial mask in step 3 is used to softly shield the spatially heterogeneous noise region on the surface of the pork sample caused by adipose tissue, connective tissue, edge shadows and juice reflection. The band weight is used to enhance the response of sensitive bands related to biochemical changes in pork freshness.
7. The hyperspectral pork freshness grading method based on spatial-spectral dual-branch attention according to claim 1, characterized in that, In step 4, each two-dimensional spatial plane of the attention fusion feature in the band dimension is used as an independent sequence unit. The global correlation established by the multi-head self-attention mechanism is the non-local dependency between different bands in the spectral dimension, which is used to capture the long-range spectral variation law of pork in the continuous biochemical evolution process from fresh to spoilage.
8. The hyperspectral pork freshness grading method based on spatial-spectral dual-branch attention according to claim 1, characterized in that, In step 2, the spatial dimension feature convolution is performed first, followed by the spectral dimension sequence convolution, thus decoupling the spatial texture features. This makes the spatial texture features the direct input for the spectral convolution kernel to couple the spectral response. The spatial-spectral joint features simultaneously contain the joint change information between the pork surface texture structure information and the spectral response of adjacent bands.
9. The hyperspectral pork freshness grading method based on spatial-spectral dual-branch attention according to claim 1, characterized in that, It also includes an end-to-end joint optimization step: taking the complete data chain formed by steps 1 to 5 as a whole, and minimizing the cross-entropy loss function. Backpropagation is performed to update all trainable parameters, where The One-hot code for the True Freshness Grade label is in the first... Values that can be taken on a class.
10. The hyperspectral pork freshness grading method based on spatial-spectral dual-branch attention according to claim 1, characterized in that, The radiometric correction in step 1 includes: acquiring the original image. Image with a completely black background and standard whiteboard images Calculate the normalized reflectance image using the following formula. The spectral smoothing process employs the Savitzky-Golay smoothing algorithm to denoise the spectral sequence of each spatial pixel.
