A hyperspectral unmixing method for detecting meat freshness

CN122990459APending Publication Date: 2026-10-27DALIAN POLYTECHNIC UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611015754.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-09
Publication Date
2026-10-27

AI Technical Summary

Technical Problem

[0003]本发明的目的是解决传统检测肉品方法检测时间较长、样品破坏和难以实现逐件检测,以及肉品高光谱图像中肌肉、脂肪、背景及腐败相关区域相互混合、样本新鲜度难以稳定表征的问题

Benefits of technology

[0065]本发明的有益效果如下:本发明提出端元感知的Transformer高光谱解混网络SEAHU。将先验光谱端元嵌入解码层,在确保丰度物理可解释性的同时实现了高精度的光谱重建。发现并验证了高光谱解混中的"最优重构不等于最优解混"现象。实验表明,端元数量从 5 增至 7 时 MSE 仍然下降,但新鲜度相关性由1.0骤降至-0.4—单纯降低重建误差并不能保证丰度的物理语义正确。构建了光谱-语义联合的多维解混评价体系。在传统 MSE/SAM/SID 基础上引入新鲜度指数、腐败比例等可解释指标,将评价维度从光谱准不准扩展至趋势对不对。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122990459A_ABST
    Figure CN122990459A_ABST
Patent Text Reader

Abstract

This invention discloses a hyperspectral unmixing method for detecting meat freshness. It utilizes endmembers and abundance responses to describe the spectral changes in meat as it progresses from fresh to spoilage, further generating two sample-level indices: a freshness index and a spoilage ratio. A Transformer autoencoder structure is employed, where the encoder maps input hyperspectral pixels to abundance vectors, and the decoder reconstructs the original spectrum based on a linear mixture model. Five endmembers are set, corresponding to five material components: background, dry fat, fresh fat, dry lean meat, and fresh lean meat. Based on the material properties of the endmembers, these components are categorized into background, spoilage, and fresh categories. The spoilage ratio and freshness index are then calculated accordingly. This method aims to shorten the detection time for meat, avoid sample damage and enable piece-by-piece detection, and achieve stable characterization of sample freshness by preventing the mixing of muscle, fat, background, and spoilage-related regions in the hyperspectral image of the meat.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of deep learning technology, and specifically to a hyperspectral unmixing method for detecting the freshness of meat products. Background Technology

[0002] Meat is a major source of protein in our daily diet, and its freshness directly affects food safety, nutritional quality, and commercial value. During storage, transportation, and sales, temperature, humidity, packaging methods, and microbial activity all influence meat quality, leading to phenomena such as protein decomposition, lipid oxidation, moisture migration, and microbial proliferation. These changes are usually accompanied by deterioration in color, odor, and texture, and in severe cases, can pose food safety risks. Traditional methods for detecting meat freshness mainly include total bacterial count, volatile basic nitrogen, pH, color difference, texture, and sensory evaluation. These methods can reflect changes in meat quality from different perspectives, but they typically require sampling, pretreatment, and laboratory testing, resulting in long testing times, sample damage, and difficulty in performing piece-by-piece testing. With the increasing demand for intelligent detection and online monitoring in the food industry, non-destructive testing methods based on machine vision and spectral technology are gaining attention. Hyperspectral imaging combines spatial image information with continuous spectral information, enabling pixel-level spectral response without damaging the sample. Changes in chemical composition and tissue structure during meat spoilage leave reflectivity differences in the near-infrared band, making this technology suitable for freshness evaluation. It should be noted that the surface of meat products often contains muscle, fat, fascia, background and putrefaction-related areas at the same time. Multiple components superimpose at the pixel level to form a mixed spectrum, which makes it difficult to characterize freshness and identify putrefaction areas. Summary of the Invention

[0003] The purpose of this invention is to solve the problems of long detection time, sample damage and difficulty in performing piece-by-piece testing in traditional meat testing methods, as well as the mixing of muscle, fat, background and putrefaction-related areas in hyperspectral images of meat products, and the difficulty in stably characterizing sample freshness.

[0004] To address the above problems, this invention proposes a hyperspectral unmixing method for detecting meat freshness, comprising:

[0005] Step 1: Data Splitting; Obtain 19 sets of 3D hyperspectral cube data in .mat format, and divide them into training and test sets according to the CSV file. The test set consists of sets 10, 11, 12, and 13, and the remaining data is used as the training set.

[0006] Step 2: Preprocess the 3D hyperspectral cube file of the training set to obtain a one-dimensional spectral vector. ;

[0007] Step 3: Transformer encoder feature extraction;

[0008] one-dimensional spectral vector As input, it contains: B band reflection scalars, taking the first... The original reflection scalar corresponding to each band The original reflection scalar is transformed using the linear projection formula. Mapped to one-dimensional band latent vector The formula is:

[0009]

[0010] In the formula, For the first One-dimensional band latent vectors obtained by linear projection of each band; For band projection, a shared weight matrix is ​​used; As a globally shared bias term for the projection layer, the original feature sequence of the bands is obtained by concatenating the one-dimensional latent vectors of all bands. , , The size of the latent vector dimension;

[0011] Introducing sinusoidal position coding, let p be the band number, p=1, 2...B, and s be the latent dimension index. The even-numbered dimension position coding formula is as follows:

[0012]

[0013] In the formula, The position encoding value for the p-th band in even-numbered dimensions; the position encoding formula for odd-numbered dimensions:

[0014]

[0015] In the formula, Encode the position value for the p-th band in odd-numbered dimensions;

[0016] Based on the position-by-position filling rule, the p-th band and even-numbered column indexes are... Substitute into the formula Fill in the corresponding positions in the matrix, indexing the p-th band and odd-numbered columns. Substitute into the formula Fill in the corresponding positions in the matrix; complete traversal of all matrices. , After filling all cell values ​​row by row and column by column, the complete location encoding matrix PE is obtained;

[0017] The positional encoding matrix PE has the same size as the original feature sequence H, with dimensions of 1. The position encoding matrix PE is added element-wise to the original feature sequence H, and the corresponding position values ​​are directly summed to obtain the initial feature matrix carrying the position information. The formula is:

[0018]

[0019] The formula for calculating multi-head self-attention is:

[0020]

[0021] No. The input to the layer is the output feature matrix of the previous layer. ;

[0022]

[0023] In the formula, To query the feature matrix, The key feature matrix, The eigenvalue matrix, These are the learnable weight matrices for the query, key, and value branches, respectively. , For single-head attention dimension; For multi-head attention, output the number of heads. Three sets of feature matrices, the i-th row of the feature matrix Q is denoted as the single-band query vector. ;

[0024] Scaling dot product attention, the formula is:

[0025]

[0026] In the formula, To provide multi-head attention fusion output features, For exponentially normalized activation functions; To perform the inner product operation between the query feature matrix and the key feature matrix;

[0027] Let the i-th row of the feature matrix Q be denoted as the single-band query vector. The key vector corresponding to the t-th band in the summation traversal stage. Traverse all B spectral bands. Let be the key vector of band j, used to calculate the correlation score between the reference band i and the paired band j; the input is... , , The formula is:

[0028]

[0029] In the formula, The attention weights associated with the i-th band and the j-th band; Perform natural index calculations; output the pairwise correlation weight matrix for all bands. Multiplying the weight matrix A by the value feature matrix V yields the single-head attention output. Then, the 8 sets of single-head features are concatenated into a multi-head output. The formula is:

[0030]

[0031] The original input feature matrix of this layer is: The first layer input is The inputs for layers 2, 3, and 4 are ;

[0032] The first-level formula is:

[0033]

[0034] The formulas for layers 2, 3, and 4 are:

[0035]

[0036] In the formula, The attention features are obtained after residual fusion; nonlinear feature mapping is achieved through two layers of learned weight matrices, as shown in the formula:

[0037]

[0038] In the formula, The feedforward network outputs nonlinear characteristics; These are the learnable weight matrices for the two layers of the feedforward network; This refers to the globally shared bias term for the corresponding layer of the feedforward network; The activation function is ReLU; the hidden layer dimension of FFN is set to... ;

[0039] The feedforward network outputs nonlinear characteristics. And attention features after residual fusion Adding them together yields the composite characteristic matrix. ; to combine the feature matrix The execution layer normalization and standardization operation is performed using the following formula:

[0040]

[0041] In the formula, U is the normalized feature matrix; U is the composite feature matrix. denoted as the scalar feature value corresponding to the g-th latent vector dimension within the composite feature matrix U; To enable learnable scaling, These are translation parameters; The characteristic mean, The characteristic variance; Take as the minimum constant To prevent the denominator from being 0; For Hadamard, multiply element by element;

[0042] The formula for calculating a single-layer encoder is:

[0043]

[0044] In the formula, This is the final output feature matrix of the l-th layer Transformer encoder; This is the normalized feature matrix; the process is repeated for four layers, and after all four layers of operations are completed, the global context feature matrix is ​​output. ;

[0045] Step 4: Calculate abundance, reconstruct the spectrum, and solve for freshness index based on the global context feature matrix;

[0046] Step 5: Use the mean squared error (MSE) as the loss function for model training, as shown in the following formula:

[0047]

[0048] In the formula, The mean squared error loss per batch; N is the total number of pixels involved in the calculation per batch; minimized through backpropagation. Complete the update of all learnable weights in the SEAHUFormer network.

[0049] In the preferred embodiment, step 2 includes: three-dimensional hyperspectral cube data. The cube has dimensions of H is the image height, W is the image width, and B is the number of effective spectral bands;

[0050] Spatial dimension flattening processing unfolds the spatial dimensions of the three-dimensional hyperspectral cube data, eliminating the two-dimensional spatial structure of the image and generating a two-dimensional spectral matrix. Each row represents the complete one-dimensional spectral vector of a single pixel. ;

[0051] Iterate through all pixels in the training set, for each band Calculate the distribution parameters for each band, including: band mean. Band standard deviation minimum value of the band maximum value of the band ;

[0052] The training set is input into the SEAHUFormer model for training, and the model outputs a one-dimensional spectral vector. , among which, when Less than ,make equal ; Greater than ,make equal .

[0053] In the preferred embodiment, step 4 includes: adaptive global average pooling, with the following formula:

[0054]

[0055] In the formula, This is a fixed-dimensional global one-dimensional feature vector after pooling compression; This is a global adaptive average pooling operation;

[0056] The abundance estimation head calculation formula is as follows:

[0057]

[0058] In the formula, As a 5-dimensional abundance vector, it naturally satisfies the constraints. , ; m represents the endmember category; To estimate the learnable weight matrix for the first two layers of abundance; This is a globally shared bias term for the corresponding layer; This is a random deactivation operation;

[0059] Endmember linear spectral reconstruction, the formula is:

[0060]

[0061] In the formula, The single-pixel spectral vector reconstructed by the model; The matrix consists of five types of endmembers; This is the abundance vector corresponding to the m-th class of endmembers; This represents the complete band spectral vector of the m-th endmember;

[0062] The freshness index is calculated as follows: the input is a 5-dimensional abundance vector a; the endmember classification rule is: endmember 0 is the background class, endmembers 1 and 3 are spoilage components, and endmembers 2 and 4 are fresh components.

[0063] Freshness Index: Excluding background elements Afterwards, fresh end-members The weighted summation shows that the value decreases continuously as the meat deteriorates during storage.

[0064] Corruption rate: Excluding background-related end-users Later, corruption-related end-level officials The weighted summation shows that the value increases continuously as the meat deteriorates during storage.

[0065] The beneficial effects of this invention are as follows: This invention proposes an endmember-aware Transformer hyperspectral unmixing network, SEAHU. By embedding prior spectral endmembers into the decoding layer, high-precision spectral reconstruction is achieved while ensuring the physical interpretability of abundance. The phenomenon that "optimal reconstruction is not equal to optimal unmixing" in hyperspectral unmixing is discovered and verified. Experiments show that when the number of endmembers increases from 5 to 7, MSE still decreases, but the freshness correlation drops sharply from 1.0 to -0.4—simply reducing the reconstruction error cannot guarantee the correct physical semantics of abundance. A multi-dimensional unmixing evaluation system jointly based on spectral and semantic meaning is constructed. Interpretable indicators such as freshness index and spoilage ratio are introduced on the basis of traditional MSE / SAM / SID, expanding the evaluation dimension from spectral accuracy to trend correctness. Attached Figure Description

[0066] Figure 1 This is the flowchart of the SEAHUFormer invention;

[0067] Figure 2 It is a diagram of 5 endmembers of SEAHUFormer;

[0068] Figure 3 This is a relatively recent sample image of the present invention;

[0069] Figure 4 This is the magnified area of ​​a relatively fresh sample in this invention;

[0070] Figure 5 This is a relatively corrupted sample image of the present invention;

[0071] Figure 6 This refers to the changes in MSE when the number of endmembers in this invention is 5 and 7, respectively; Detailed Implementation

[0072] Example 1:

[0073] like Figure 1 As shown, a hyperspectral unmixing method for detecting the freshness of meat products includes:

[0074] Step 1: Data partitioning;

[0075] Nineteen sets of 3D hyperspectral cube data in .mat format were obtained and divided into training and test sets according to CSV files. The test set consists of sets 10, 11, 12, and 13, and the rest are used as the training set. The 3D hyperspectral cube files of the training set are used as input for step 2.

[0076] Step 2: Data preprocessing;

[0077] 3D hyperspectral cube data The cube has dimensions of H is the image height, W is the image width, and B is the number of effective spectral bands;

[0078] Spatial dimension flattening processing unfolds the spatial dimensions of the three-dimensional hyperspectral cube data, eliminating the two-dimensional spatial structure of the image and generating a two-dimensional spectral matrix. Each row represents the complete one-dimensional spectral vector of a single pixel. ;

[0079] Band-by-band statistical processing involves iterating through all pixels in the training set for each band. Calculate the distribution parameters for each band, including: band mean. Band standard deviation minimum value maximum value The same set of statistical parameters is applied synchronously to the training and test sets. This set of statistical parameters is used for dataset distribution analysis and abnormal spectral numerical truncation during the inference stage. The model directly uses the original reflectance values ​​for calculation.

[0080] Batch pixel sampling involves inputting the training set into the SEAHUFormer model for training, randomly selecting a batch of pixels from the training set for iteration, without retaining the original image's spatial coordinates; the model outputs a one-dimensional spectral vector. ,in,

[0081] when Less than ,make equal ; Greater than ,make equal ;

[0082] Step 3: Construct the SEAHUFormer model;

[0083] Based on TensorFlow / Keras, an autoencoder architecture is built to implement the SEAHUFormer corruption endmember-aware hyperspectral demixing framework, including:

[0084] The input is a normalized hyperspectral pixel spectral vector of meat. The complete spectral vector is sequentially processed through a spectral serialization module, a multi-layer Transformer encoding module, an abundance estimation head, and a linear decoder to output the reconstructed spectrum and freshness index. The model is divided into two main modules: an encoder and a decoder. The encoder is used to extract band features and estimate the abundance vector, while the decoder uses a linear mixing layer to reconstruct the original spectrum. The basic assumption of this framework is that the hyperspectral pixels of meat are composed of a linear mixture of the spectra of four pure substances: muscle, fat, background, and putrefaction area. By using endmember representation and abundance estimation, the spectral responses of each component can be separated from the mixed spectrum, and then the proportion of putrefaction and the freshness index of meat can be calculated.

[0085] This model simultaneously sets two types of optimization objectives: first, to reduce the deviation between the reconstructed spectrum and the original input spectrum; and second, to ensure that the output index conforms to the changing law of meat freshness, that is, as the reference freshness score decreases, the model output freshness index decreases synchronously, and the abundance ratio of spoilage area gradually increases. Among them, the spectral unmixing satisfies the linear mixture model constraint, and the abundance vector must simultaneously satisfy the non-negativity constraint and the sum of one constraint.

[0086] Step 4: Transformer encoder feature extraction;

[0087] Spectral serialization projection; transforming a one-dimensional spectral vector As input, it contains: B band reflection scalars, taking the first... The original reflection scalar corresponding to each band The original reflection scalar is transformed using the linear projection formula. Mapped to one-dimensional band latent vector The formula is:

[0088]

[0089] In the formula, For the first One-dimensional band latent vectors obtained by linear projection of each band; For band projection, a shared weight matrix is ​​used; As a globally shared bias term for the projection layer, all bands are stitched together to obtain the original feature sequence of the bands. , , The size of the latent vector dimension;

[0090] Sine position encoding overlay: This overlays the original feature sequence of the band output from the previous section. As input; since the Transformer's self-attention mechanism itself does not have the ability to sense sequence position, while spectral bands have a natural physical order;

[0091] Introducing sinusoidal position coding, let p be the band number, p=1, 2...B, and s be the latent dimension index. The latent vector dimension size (representing only the model dimension, not used as a loop index), and the encoding formula for even-numbered dimension positions are as follows:

[0092]

[0093] In the formula, Encode the position value for the p-th band in an even-numbered dimension; Let the size of the latent vector dimension be 128; the encoding formula for odd-dimensional positions is as follows:

[0094]

[0095] In the formula, Encode the position value for the p-th band in odd-numbered dimensions;

[0096] According to the position-by-position filling rule, for the p-th band (corresponding to the p-th row of the matrix), the even-numbered column index... Substitute into the formula Fill in the corresponding positions in the matrix, and index the p-th row and odd-numbered columns. Substitute into the formula Fill in the corresponding positions in the matrix; complete traversal of all matrices. , After filling in all cell values ​​row by row and column by column, the complete location encoding matrix PE can be obtained.

[0097] The positional encoding matrix PE has the same size as the feature sequence H, with dimensions of 1. The position encoding matrix PE is added element-wise to the feature sequence H, and the corresponding position values ​​are directly summed to obtain the initial feature matrix carrying the position information. The formula is:

[0098]

[0099] The formula for calculating multi-head self-attention is:

[0100]

[0101] No. The input to the layer is the output feature matrix of the previous layer. ;

[0102]

[0103] In the formula, To query the feature matrix, The key feature matrix, The eigenvalue matrix, These are the learnable weight matrices for the query, key, and value branches, respectively. , For single-head attention dimension; To accommodate the number of heads in a multi-head attention system, this invention sets it to 8, and outputs... Three sets of feature matrices, where the i-th row of matrix Q is denoted as the single-band query vector. ;

[0104] Scaling dot product attention, the formula is:

[0105]

[0106] In the formula, To provide multi-head attention fusion output features, For exponentially normalized activation functions; To perform the inner product operation between the query feature matrix and the key feature matrix;

[0107] Inter-band attention weights reflect the correlation between the i-th reference band and the j-th paired band. The output of the i-th band is the value vector of all bands weighted. Weighted summation allows each band to aggregate information from a global perspective.

[0108] Let the i-th row of the feature matrix Q be denoted as the single-band query vector. The key vector corresponding to the t-th band in the summation traversal stage. Traverse all B spectral bands. Let be the key vector of band j, used to calculate the correlation score between the reference band i and the paired band j; the input is... , , The formula is:

[0109]

[0110] In the formula, The attention weights associated with the i-th band and the j-th band; For natural index calculations; This involves summing the index results for all B bands; where B is the number of effective spectral bands; and outputting the pairwise correlation weight matrix between all bands. Multiplying the weight matrix A by the value feature matrix V yields the single-head attention output. Then, the 8 sets of single-head features are concatenated into a multi-head output. ;

[0111] Multi-head attention residual connections; residual connections ensure that gradients can be directly backpropagated from the top layer to the lower layers, making it possible to train deeper networks; the original input feature matrix of this layer is... The first layer input is The inputs for layers 2, 3, and 4 are ;

[0112] The first-level formula is:

[0113]

[0114] The formulas for layers 2, 3, and 4 are:

[0115]

[0116] In the formula, Attention features after residual fusion; This is a multi-head feature operation, describing the meaning of the multi-head features. The output is the residual fusion feature. The data is fed into the feedforward network FFN.

[0117] Feedforward Neural Network (FFN); input is residual features Nonlinear feature mapping is achieved through two layers of learnable weight matrices, as shown in the formula:

[0118]

[0119] In the formula, The feedforward network outputs nonlinear characteristics; These are the learnable weight matrices for the two layers of the feedforward network; This refers to the globally shared bias term for the corresponding layer of the feedforward network; It is a ReLU activation function; This outputs the residual fusion features from the previous step in this section. The hidden layer dimension of the FFN is set to... The output is the FFN nonlinear transformation characteristic, which is then fed into the layer normalization module.

[0120] Layer normalization processing is performed to normalize the output features of the feedforward network from the previous section. And the multi-head attention residual fusion output features in the previous two subsections Adding them together yields the composite characteristic matrix. ; to combine the feature matrix As input to the layer normalization module, perform the layer normalization operation. Layer normalization formula:

[0121]

[0122] In the formula, U is the normalized feature matrix; U is the composite feature matrix. Let g be the scalar feature value corresponding to the g-th latent vector dimension within the composite feature matrix U; To enable learnable scaling and translation parameters, the network initialization is randomly generated and automatically updated during training. The characteristic mean, The characteristic variance; Take as the minimum constant To prevent the denominator from being 0; This is an element-wise multiplication of Hadamard. The output is the normalized non-linear characteristic.

[0123] The final output of a single-layer encoder;

[0124] Input is residual attention features The formula is:

[0125]

[0126] In the formula, This is the final output feature matrix of the l-th layer Transformer encoder; Residual fusion characteristics; The feedforward network outputs nonlinear characteristics; The normalized feature matrix; the complete encoded features of the l-th layer. This is used as the input for the next layer of encoding blocks; this module executes four layers in a loop, and after all four layers of operations are completed, the global context feature matrix is ​​output. Then, it is sent to the abundance solution module in step 5.

[0127] Step 5: Abundance calculation, spectral reconstruction, and freshness index determination

[0128] Adaptive global average pooling

[0129] The input is the global context feature matrix, which is the final output of the four-layer encoder in step 4. The formula is:

[0130]

[0131] In the formula, This is a fixed-dimensional global one-dimensional feature vector after pooling compression; This is a global adaptive average pooling operation. The output is a global feature vector z, which is fed into the abundance estimation head.

[0132] Abundance estimation head operation

[0133] The input is a pooled output global one-dimensional feature vector z, which is then processed through two fully connected layers, Dropout, and Softmax constraints to output a five-dimensional abundance vector. The formula is:

[0134]

[0135] In the formula, As a 5-dimensional abundance vector, it naturally satisfies the constraints. , ;m represents the end-member category and is only used in this section; Normalized output of the mixing ratio of each terminal element; To estimate the learnable weight matrix for the first two layers of abundance; This is a globally shared bias term for the corresponding layer; This is a random deactivation operation. The output is a 5-dimensional abundance vector 'a', which is fed into the spectral reconstruction and freshness calculation branches, respectively.

[0136] Endmember linear spectral reconstruction;

[0137] The input is an abundance vector a and a pre-extracted 5-row endmember matrix E, and the formula is:

[0138]

[0139] In the formula, The single-pixel spectral vector reconstructed by the model; The matrix consists of five types of material endmembers, which are extracted in advance from the training set using the VCA algorithm. This is the abundance vector corresponding to the m-th class of endmembers; This is the complete band spectral vector of the m-th endmember. The output is the reconstructed spectral vector. This vector, together with the original spectral vector x from step 2, serves as the input for the loss calculation module in step 6.

[0140] Freshness index calculation;

[0141] The input is a 5-dimensional abundance vector a;

[0142] Endmember classification rules: Endmember 0 is the background component, endmembers 1 and 3 are putrefactive components, and endmembers 2 and 4 are fresh components;

[0143] Freshness Index: Background Abundance Excluded Afterwards, fresh end-members The weighted summation shows that the value decreases continuously as the meat deteriorates during storage.

[0144] Corruption ratio: background abundance removed Later, corruption-related end-level officials The weighted summation shows that the value increases continuously as the meat deteriorates during storage.

[0145] Step 6: Calculate the loss function;

[0146] This invention uses only the mean square error (MSE) as the model training loss function, and takes the mean squared error of each band of the original spectrum and the reconstructed spectrum as the optimization objective. The calculation formula is as follows:

[0147]

[0148] In the formula, denoted as mean square error loss for a single batch; N is the total number of pixels involved in the calculation for a single batch; B is the number of effective spectral bands. Represents a one-dimensional spectral vector; This represents the single-pixel spectral vector reconstructed by the model. It is minimized through backpropagation. Complete the update of all learnable weights in the SEAHUFormer network.

[0149] The hyperspectral dataset in this invention is derived from

[0150] Hyperspectral-Meat-OverTime.

[0151] This invention proposes an endmember-aware Transformer hyperspectral unmixing network, SEAHU. Prior spectral endmembers are embedded into the decoding layer, achieving high-precision spectral reconstruction while ensuring the physical interpretability of abundance. The phenomenon that "optimal reconstruction is not equal to optimal unmixing" in hyperspectral unmixing is discovered and verified. Experiments show that while MSE still decreases when the number of endmembers increases from 5 to 7, the freshness correlation drops sharply from 1.0 to -0.4—simply reducing reconstruction error does not guarantee the correct physical semantics of abundance. A multi-dimensional unmixing evaluation system jointly based on spectral and semantic meaning is constructed. Interpretable indicators such as freshness index and spoilage ratio are introduced on the basis of traditional MSE / SAM / SID, expanding the evaluation dimension from "spectral accuracy" to "trend correctness".

[0152] Figure 2 The invention is illustrated by five terminal units: background, dried fat, fresh fat, dried lean meat, and fresh lean meat.

[0153] Figure 3 A relatively fresh sample image of the present invention is shown. The image uses end-member color coding: green represents fresh lean meat, gold represents fresh fat, red represents spoiled lean meat, purple represents spoiled fat, and light gray represents the background area.

[0154] Figure 4 An enlarged view of a relatively fresh sample of the present invention is shown. The image uses end-member color coding: green represents fresh lean meat, gold represents fresh fat, red represents spoiled lean meat, purple represents spoiled fat, and light gray represents the background area.

[0155] Figure 5 An image of a relatively rotten sample of the present invention is shown. The image uses end-member color coding: green represents fresh lean meat, gold represents fresh fat, red represents rotten lean meat, purple represents rotten fat, and light gray represents the background area.

[0156] Figure 6 The figure shows the MSE values ​​when the number of endmembers is 5 and 7, respectively. As can be seen from the figure, the MSE decreases by 0.3% when the number of endmembers increases from 5 to 7.

[0157] 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 present invention. Various changes and modifications can be made to the present invention without departing from its spirit and scope. All such changes and modifications fall within the scope of the present invention as claimed, which is defined by the appended claims and their equivalents.

Claims

1. A hyperspectral unmixing method for detecting the freshness of meat products, characterized in that, include: Step 1: Obtain 3D hyperspectral cube data, divide the 3D hyperspectral cube data, and obtain the test set and training set; Step 2: Preprocess the 3D hyperspectral cube file of the training set to obtain a one-dimensional spectral vector. ; Step 3: Transformer encoder feature extraction; one-dimensional spectral vector As input, it contains: B band reflection scalars, taking the first... The original reflection scalar corresponding to each band The original reflection scalar is transformed using the linear projection formula. Mapped to one-dimensional band latent vector The formula is: In the formula, For the first One-dimensional band latent vectors obtained by linear projection of each band; For band projection, a shared weight matrix is ​​used; As a globally shared bias term for the projection layer, the original feature sequence of the bands is obtained by concatenating the one-dimensional latent vectors of all bands. , , The size of the latent vector dimension; Introducing sinusoidal position coding, let p be the band number, p=1, 2...B, and s be the latent dimension index. The even-numbered dimension position coding formula is as follows: In the formula, The position encoding value for the p-th band in even-numbered dimensions; the position encoding formula for odd-numbered dimensions: In the formula, Encode the position value for the p-th band in odd-numbered dimensions; Based on the position-by-position filling rule, the p-th band and even-numbered column indexes are... Substitute into the formula Fill in the corresponding positions in the matrix, indexing the p-th band and odd-numbered columns. Substitute into the formula Fill in the corresponding positions in the matrix; complete traversal of all matrices. , After filling all cell values ​​row by row and column by column, the complete location encoding matrix PE is obtained; The positional encoding matrix PE has the same size as the original feature sequence H, with dimensions of 1. The position encoding matrix PE is added element-wise to the original feature sequence H, and the corresponding position values ​​are directly summed to obtain the initial feature matrix carrying the position information. The formula is: The formula for calculating multi-head self-attention is: No. The input to the layer is the output feature matrix of the previous layer. ; In the formula, To query the feature matrix, The key feature matrix, The eigenvalue matrix, These are the learnable weight matrices for the query, key, and value branches, respectively. , For single-head attention dimension; For multi-head attention, output the number of heads. Three sets of feature matrices, the i-th row of the feature matrix Q is denoted as the single-band query vector. ; Scaling dot product attention, the formula is: In the formula, To provide multi-head attention fusion output features, For exponentially normalized activation functions; To perform the inner product operation between the query feature matrix and the key feature matrix; Let the i-th row of the feature matrix Q be denoted as the single-band query vector. The key vector corresponding to the t-th band in the summation traversal stage. Traverse all B spectral bands. Let be the key vector of band j, used to calculate the correlation score between the reference band i and the paired band j; the input is... , , The formula is: In the formula, The attention weights associated with the i-th band and the j-th band; For natural index calculations; Output the pairwise correlation weight matrix for all bands. Multiplying the weight matrix A by the value feature matrix V yields the single-head attention output. Then, the 8 sets of single-head features are concatenated into a multi-head output. The formula is: The original input feature matrix of this layer is: The first layer input is The inputs for layers 2, 3, and 4 are ; The first-level formula is: The formulas for layers 2, 3, and 4 are: In the formula, The attention features are obtained after residual fusion; nonlinear feature mapping is achieved through two layers of learned weight matrices, as shown in the formula: In the formula, The feedforward network outputs nonlinear characteristics; These are the learnable weight matrices for the two layers of the feedforward network; This refers to the globally shared bias term for the corresponding layer of the feedforward network; The activation function is ReLU; the hidden layer dimension of FFN is set to... ; The feedforward network outputs nonlinear characteristics. And attention features after residual fusion Adding them together yields the composite characteristic matrix. ; to combine the feature matrix The execution layer normalization and standardization operation is performed using the following formula: In the formula, The normalized feature matrix; U is the composite characteristic matrix. denoted as the scalar feature value corresponding to the g-th latent vector dimension within the composite feature matrix U; To enable learnable scaling, These are translation parameters; The characteristic mean, The characteristic variance; Take as the minimum constant To prevent the denominator from being 0; For Hadamard, multiply element by element; The formula for calculating a single-layer encoder is: In the formula, This is the final output feature matrix of the l-th layer Transformer encoder; This is the normalized feature matrix; the process is repeated for four layers, and after all four layers of operations are completed, the global context feature matrix is ​​output. ; Step 4: Calculate abundance, reconstruct the spectrum, and solve for freshness index based on the global context feature matrix; Step 5: Use the mean squared error (MSE) as the loss function for model training, as shown in the following formula: In the formula, The mean squared error loss per batch; N is the total number of pixels involved in the calculation per batch; minimized through backpropagation. Complete the update of all learnable weights in the SEAHUFormer network.

2. The hyperspectral unmixing method for detecting meat freshness according to claim 1, characterized in that, Step 2 includes: three-dimensional hyperspectral cube data The cube has dimensions of H is the image height, W is the image width, and B is the number of effective spectral bands; Spatial dimension flattening processing unfolds the spatial dimensions of the three-dimensional hyperspectral cube data, eliminating the two-dimensional spatial structure of the image and generating a two-dimensional spectral matrix. Each row represents the complete one-dimensional spectral vector of a single pixel. ; Iterate through all pixels in the training set, for each band Calculate the distribution parameters for each band, including: band mean. Band standard deviation minimum value of the band maximum value of the band ; The training set is input into the SEAHUFormer model for training, and the model outputs a one-dimensional spectral vector. , among which, when Less than ,make equal ; Greater than ,make equal .

3. The hyperspectral unmixing method for detecting meat freshness according to claim 1, characterized in that, Step 4 includes: adaptive global average pooling, the formula is: In the formula, This is a fixed-dimensional global one-dimensional feature vector after pooling compression; This is a global adaptive average pooling operation; The abundance estimation head calculation formula is as follows: In the formula, As a 5-dimensional abundance vector, it naturally satisfies the constraints. , ; m represents the endmember category; To estimate the learnable weight matrix for the first two layers of abundance; This is a globally shared bias term for the corresponding layer; This is a random deactivation operation; Endmember linear spectral reconstruction, the formula is: In the formula, This is the single-pixel spectral vector reconstructed by the model; The matrix consists of five types of endmembers; This is the abundance vector corresponding to the m-th class of endmembers; This represents the complete band spectral vector of the m-th endmember; The freshness index is calculated as follows: the input is a 5-dimensional abundance vector a; the endmember classification rule is: endmember 0 is the background class, endmembers 1 and 3 are spoilage components, and endmembers 2 and 4 are fresh components. Freshness Index: Excluding background elements Afterwards, fresh end-members The weighted summation shows that the value decreases continuously as the meat deteriorates during storage. Corruption rate: Excluding background-related end-users Later, corruption-related end-level officials The weighted summation shows that the value increases continuously as the meat deteriorates during storage.

4. The hyperspectral unmixing method for detecting meat freshness according to claim 1, characterized in that, Step 1 includes obtaining 19 sets of 3D hyperspectral cube data in .mat format. The test set consists of sets 10, 11, 12, and 13, and the rest are the training set.