A non-destructive method for detecting chicken freshness
By combining hyperspectral imaging technology with an improved residual network, the problems of time-consuming and destructive testing of chicken freshness have been solved, enabling rapid, non-destructive, and efficient testing of chicken freshness, thus improving testing efficiency and accuracy.
Patent Information
- Application Number
- CN202410120065.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-29
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2044-01-29
AI Technical Summary
Existing methods for detecting chicken freshness are time-consuming, destructive to samples, and highly subjective, making it difficult to achieve rapid, efficient, and non-destructive testing.
This study employs hyperspectral imaging technology combined with improved residual networks, feature band selection, and data fusion techniques. Data is collected using a visible light hyperspectral analyzer and a short-wave near-infrared spectrometer. The data undergoes mean normalization preprocessing, a competitive adaptive reweighted sampling algorithm to select feature bands, and data fusion. Finally, the improved residual network is used to classify the freshness of chicken.
It enables rapid, efficient, and non-destructive testing of chicken freshness, improving testing efficiency and accuracy while avoiding sample damage and subjective influence.
Smart Images

Figure CN117953490B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the technical field of food safety testing, and in particular to a non-destructive testing method for chicken freshness. Background Technology
[0002] With increasing awareness of food safety, consumers have higher and higher requirements for the quality and safety of chicken. Because chicken is prone to spoilage and deterioration during production and transportation, its freshness directly affects public expectations regarding the quality and safety of chicken consumption. Currently, traditional methods for detecting chicken freshness mainly include sensory evaluation and physicochemical analysis. These methods suffer from drawbacks such as being time-consuming, damaging samples, and having highly subjective results. Therefore, developing a new chicken freshness detection technology is urgently needed to achieve rapid, efficient, and non-destructive testing. Summary of the Invention
[0003] The purpose of this invention is to overcome the shortcomings and disadvantages of the prior art and provide a non-destructive testing method for chicken freshness, which can achieve rapid and non-destructive testing and improve the efficiency and accuracy of chicken freshness testing.
[0004] To achieve the above objectives, the technical solution provided by this invention is: a non-destructive method for detecting the freshness of chicken, comprising the following steps:
[0005] S1: Collect hyperspectral image data of the chicken sample to be tested, wherein the hyperspectral image data includes visible hyperspectral data and short-wave near-infrared spectral data;
[0006] S2: The acquired hyperspectral image data is preprocessed by mean normalization to form a visible hyperspectral dataset and a short-wave near-infrared spectral dataset. These two datasets together constitute the preprocessed hyperspectral image data. The mean normalization preprocessing is performed by subtracting the average value of each feature value and making the overall data distribution centered at zero, thereby eliminating the influence of different dimensions and numerical ranges.
[0007] S3: The competitive adaptive reweighted sampling algorithm is used to extract feature wavelengths from the preprocessed hyperspectral image data to screen out feature bands closely related to chicken freshness, and feature band datasets are formed by selecting feature bands and corresponding hyperspectral image data.
[0008] S4: Perform data fusion on the preprocessed visible light hyperspectral dataset and short-wave near-infrared spectral dataset to form a data fusion dataset;
[0009] S5: The preprocessed visible light hyperspectral dataset, shortwave near-infrared spectral dataset, feature band dataset, and data fusion dataset are input into a pre-trained chicken freshness classification model. This chicken freshness classification model is an improved residual network. The output of the improved residual network includes the accuracy of modeling on the test set and the model building time required. By comparing these two metrics, the result with the highest accuracy and the shortest model building time on the test set is selected as the lossless classification result for chicken freshness. The improved residual network introduces a one-dimensional convolutional layer for hyperspectral image data processing and optimizes the design of the residual blocks, making the residual blocks contain 1×1 convolutional layers for adjusting the number of channels and stride. At the same time, the residual blocks also contain batch normalization and ReLU activation functions, which enhance the network's ability to process hyperspectral image data and improve the information flow and learning efficiency of the network in the deep structure.
[0010] Furthermore, the specific steps of step S1 are as follows:
[0011] S11: Before acquiring hyperspectral image data, start the visible hyperspectral instrument and the short-wave near-infrared spectrometer and warm up for 30 minutes.
[0012] S12: Visible hyperspectral images are acquired using a visible hyperspectral instrument with a spectral resolution of 5.5 nm and a spectral wavelength range of 397-1003 nm;
[0013] S13: Acquire short-wave near-infrared spectral images using a short-wave near-infrared spectrometer with a spectral resolution of 8 nm and a wavelength range of 935-1720 nm;
[0014] S14: Select the region of interest in the visible hyperspectral image and the short-wave near-infrared spectral image, acquire the visible hyperspectral data and the short-wave near-infrared spectral data, merge all the visible hyperspectral data to form a visible hyperspectral dataset, merge all the short-wave near-infrared spectral data to form a short-wave near-infrared spectral dataset, and the visible hyperspectral dataset and the short-wave near-infrared spectral dataset together constitute the required hyperspectral image data.
[0015] Furthermore, in step S2, the mean normalization preprocessing specifically includes:
[0016] S21: For each band of the hyperspectral image data, calculate the mean of all samples. Let X be an m×n data matrix, where m represents the number of samples and n represents the number of bands. For the j-th band, calculate the mean of all samples:
[0017]
[0018] In the formula, X ij It is the value of the i-th sample in the j-th band. It is the mean of the j-th sample;
[0019] S22: Subtract the average value of the corresponding band from the value of each sample in each band to obtain the mean-normalized value:
[0020]
[0021] In the formula, X norm.ij It is the normalized value of the mean of the i-th sample in the j-th band.
[0022] Furthermore, in step S3, a competitive adaptive reweighted sampling algorithm is used to extract the feature wavelengths, specifically including:
[0023] S31: Monte Carlo model sampling is adopted, the dataset is randomly split with a split ratio of 75%-85%, and a partial least squares model is established, using the percentage of absolute values of regression coefficients as the importance index of variables.
[0024] S32: Employs an exponential decay function.
[0025] r s =ae -ks
[0026] Determine the number of variables to retain in each iteration, where a and k are parameters of the exponential decay function, and r s is the number of variables determined in the s-th iteration; where a and k are determined by the following constraints:
[0027] r1 = P
[0028]
[0029] In the formula, r1 is the number of variables determined in the initial iteration, denoted by P, and r N This is the number of variables determined in the Nth iteration, where N is the number of iterations. Then, a and k can be calculated using the following formula:
[0030]
[0031]
[0032] S33: Based on the number of variables determined in step S32, variables are eliminated, and the frequency of occurrence of variables is represented by weights. Then, an analysis and prediction model based on the selected variables is established, and the root mean square error of its cross-validation is calculated.
[0033] S34: Set the number of iterations. Determine the optimal set of variables based on the minimum root mean square error during the iteration process. This set is the desired characteristic band.
[0034] After selecting the characteristic bands, the characteristic bands and the data they contain are extracted from the preprocessed hyperspectral image data to form a characteristic band dataset for subsequent modeling and analysis.
[0035] Furthermore, in step S4, the specific operations of data fusion are as follows:
[0036] Visible hyperspectral dataset and shortwave near-infrared spectral dataset are stitched together using software algorithms to form a multi-feature data fusion dataset, which can provide richer information than individual spectral components.
[0037] The visible light hyperspectral dataset is a one-dimensional array, represented as: V=[v1,v2,...,v o The shortwave near-infrared spectral dataset is a one-dimensional array, represented as: NIR=[nir1,nir2,...,nir] q ], where o and q represent the number of bands in the visible hyperspectral and short-wave near-infrared spectra, respectively, and v o This represents visible light hyperspectral data for a specific band within the visible light hyperspectral spectrum. (nir) q This represents shortwave near-infrared spectral data for a specific band within the shortwave near-infrared spectrum.
[0038] Data fusion is represented as the concatenation of two arrays, which places data from two spectral regions into a new contiguous array F:
[0039] F = [v1, v2, ..., v o ,nir1,nir2,...,nir q ]
[0040] The resulting array, or data fusion dataset, is used for subsequent chicken freshness classification modeling.
[0041] Furthermore, the improved residual network includes:
[0042] Input layer: Hyperspectral image data is input into the network. This data is acquired by a visible hyperspectral imager and a short-wave near-infrared imager and is preprocessed to represent the spectral characteristics of chicken samples.
[0043] Initial convolutional layer: The input hyperspectral image data first flows through a convolutional layer with 64 filters, each filter being 5×5 in size, with a stride of 2 and padding of 2. The purpose of this convolutional layer is to extract primary features of the chicken sample while reducing the dimensionality of the data.
[0044] Batch normalization layer and ReLU activation function: After the initial convolutional layer, a batch normalization layer is set to adjust the distribution of activation values, thereby reducing the influence of internal covariate shift. Then there is the ReLU activation function, which introduces the necessary non-linearity to the network and helps to enhance the network's ability to classify chicken freshness.
[0045] Max pooling layer: The feature map is further processed using a max pooling layer with a pooling kernel size of 3×3, a stride of 2, and padding of 1. This max pooling layer helps to reduce the feature dimension and highlight important spectral features.
[0046] Residual blocks: The main body of a residual network consists of multiple residual blocks. Each residual block contains two convolutional layers with the same output dimension and includes skip connections to directly add the input to the output. When the dimension needs to be changed, a 1×1 convolution with a stride of 2 is used to achieve dimension matching. These residual blocks help maintain gradient stability during training, thereby ensuring the effective training of deep networks.
[0047] The basic idea of residual blocks is to learn the residual mapping F(x) = H(x) - x between the input and output, where H(x) is the desired mapping and x is the input of the block;
[0048] The formula for the residual block is expressed as:
[0049] Y = F(Z, {w i})+G(Z)
[0050] In the formula, Z is the input, {w i} is the weight set of the convolutional layer, F(Z,{w i}) is the residual mapping learned through weights, Y is the final output; G(Z) is a transformation function used to ensure that the dimension of Z is the same as that of F(Z,{w) when using a 1×1 convolution kernel for convolution. i The dimensions match;
[0051] Adaptive average pooling layer: After processing multiple residual blocks, the feature map is processed by the adaptive average pooling layer, which reduces the spatial size of each feature map to 1×1. The adaptive average pooling layer transforms the feature map into a fixed-size vector for use in subsequent fully connected layers.
[0052] Fully connected layer and Dropout layer: After the feature map is converted into a fixed-size vector, it is fed into a fully connected layer. The number of output nodes of the fully connected layer is determined by the number of chicken freshness categories, including fresh, slightly fresh, and spoiled. To reduce the risk of overfitting, a Dropout layer is set before the fully connected layer. The Dropout layer randomly discards a portion of neurons to increase the generalization ability of the chicken freshness classification model.
[0053] Furthermore, specific improvements to the residual network include:
[0054] Introducing a one-dimensional convolutional layer is beneficial because hyperspectral image data is one-dimensional; therefore, a one-dimensional convolutional layer can adapt to the processing of hyperspectral image data, thereby extracting features more effectively.
[0055] The design optimizes the residual blocks by including 1×1 convolutional layers and batch normalization layers for adjusting the number of channels, as well as ReLU activation functions, to enhance the expressive power of the chicken freshness classification model and accelerate the training process. The residual blocks also contain identity mapping residual connections to preserve feature information, which helps prevent gradient vanishing and allows for the training of deeper network structures without performance loss.
[0056] Furthermore, in step S5, the specific steps of the freshness modeling analysis are as follows:
[0057] The visible light hyperspectral image dataset and the short-wave near-infrared spectral dataset, which have undergone mean normalization preprocessing, are input into the improved residual network;
[0058] The feature band dataset, composed of feature bands selected by a competitive adaptive reweighted sampling algorithm, is input into the improved residual network.
[0059] The data fusion dataset, which is organized and spliced using data fusion technology, is input into the improved residual network;
[0060] The performance and efficiency of the model are evaluated by comparing the accuracy on the test set and the time spent building the model after the above dataset is input into the improved residual network for modeling. By comparing the two indicators of accuracy and time, the result with the highest accuracy on the test set and the shortest model building time is selected as the non-destructive classification result of chicken freshness.
[0061] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0062] This invention employs hyperspectral imaging technology to non-destructively acquire information from chicken samples. Combined with improved residual networks, feature band selection, and data fusion techniques, it achieves rapid and efficient classification of chicken freshness without requiring additional sample processing or damage. This not only enables continuous and non-destructive detection but also ensures accurate results, making it worthy of widespread application. Attached Figure Description
[0063] Figure 1 This is a schematic diagram of the visible light hyperspectral portion / short-wave near-infrared spectral portion system.
[0064] Figure 2A schematic diagram of the confusion matrix for the test set of the visible light hyperspectral image dataset for chicken freshness classification modeling after mean normalization preprocessing.
[0065] Figure 3 A schematic diagram of the confusion matrix for the test set of chicken freshness classification modeling for a shortwave near-infrared spectral image dataset.
[0066] Figure 4 A schematic diagram of the confusion matrix for the test set in the chicken freshness classification model of the feature band dataset.
[0067] Figure 5 A schematic diagram of the confusion matrix for the test set in the data fusion dataset for classifying chicken freshness. Detailed Implementation
[0068] The present invention will be further described below with reference to specific embodiments.
[0069] This embodiment provides a non-destructive method for detecting the freshness of chicken. The hyperspectral system used in this method consists of two imaging spectrometers and their corresponding accessories, such as... Figure 1 As shown, in the visible light hyperspectral part, an imaging spectrometer (called a visible light hyperspectral spectrometer, used to acquire visible light hyperspectral images) with a spectral resolution of 5.5 nm, a spectral wavelength range of 397-1003 nm, and the ability to acquire 224 wavelength points is used. This spectrometer has the ability to acquire one wavelength point every 2.68 nm on average, with an image resolution of 1024×1024, a pixel size of 8×8 μm, and a signal-to-noise ratio of 600:1. This part of the system also includes a 280W halogen tungsten lamp light source, a stepper motor, and a computer equipped with data acquisition software. Secondly, in the short-wave near-infrared spectroscopy section, an imaging spectrometer (called a short-wave near-infrared spectrometer, used to acquire short-wave near-infrared images) with a spectral resolution of 8 nm, a wavelength range of 935-1720 nm, and the ability to acquire 224 wavelength points is used. This spectrometer has the ability to acquire one wavelength point every 3.57 nm on average, with an image resolution of 640×640, a pixel size of 15×15 μm, and a signal-to-noise ratio of 1000:1. This part of the system is also equipped with a 280W halogen tungsten lamp light source, a stepper motor, and a computer with data acquisition software, and an Ingasa surface detector is added to improve the detection accuracy.
[0070] Before acquiring hyperspectral image data, the system should be preheated for 30 minutes to avoid noise. After adjusting the system parameters, place the chicken sample on a black tray and then place the tray on the stepper motor. A scanning method should be used to acquire data, ensuring a clear hyperspectral image. Because the raw spectral image contains camera undercurrent noise and uneven intensity distribution of light sources in different bands, it needs to be corrected. Black and white correction is performed using a standard white board and a black image, correcting the image to reflectance mode. Then, the relative reflectance image R is obtained by correcting the raw hyperspectral image using the following equation:
[0071]
[0072] In the formula, I O For the original spectral image, I B For the standard blue reference image, I W This is a standard white reference image.
[0073] Select regions of interest from visible hyperspectral and shortwave near-infrared spectral images, acquire visible hyperspectral and shortwave near-infrared spectral data, merge all visible hyperspectral data into a visible hyperspectral dataset, and merge all shortwave near-infrared spectral data into a shortwave near-infrared spectral dataset. The visible hyperspectral dataset and the shortwave near-infrared spectral dataset together constitute the required hyperspectral image data.
[0074] Before establishing a classification model for hyperspectral image data, the extracted raw spectral data contains noise, background interference, and baseline drift caused by the size of solid particles. Therefore, to improve the performance and stability of the model, preprocessing of the raw hyperspectral image data is necessary. This method uses mean normalization as a preprocessing method for spectral preprocessing.
[0075] Mean normalization involves subtracting the mean of each spectral vector from its mean, thereby centering the data mean to 0. This way, the range or distribution of the data remains unchanged; only the central location of the data is shifted. In this embodiment, the spectral vector refers to the reflectance or radiance value of each pixel in the hyperspectral image across all wavelengths.
[0076] After mean normalization, the mean of all spectral vectors will be 0, which allows for a fairer comparison of the characteristics between different spectra.
[0077] Suppose we have hyperspectral data of a sample, x = [x1, x2, x3, ..., x n If we represent a vector, then the mean normalization process is as follows:
[0078] For each band of the hyperspectral image data, calculate the mean of all samples. Let X be an m×n data matrix, where m represents the number of samples and n represents the number of bands. For the j-th band, calculate the mean of all samples:
[0079]
[0080] In the formula, X ij It is the value of the i-th sample in the j-th band. It is the mean of the j-th sample;
[0081] Subtracting the mean value of the corresponding band from the value of each sample in that band yields the mean-normalized value:
[0082]
[0083] In the formula, X norm.ij It is the normalized value of the mean of the i-th sample in the j-th band.
[0084] After mean normalization, the deviation of each band from its average value is clearly defined, effectively eliminating the scale differences that may exist between bands in the spectral data, and laying a solid foundation for further analysis of hyperspectral image data and model training and establishment.
[0085] After performing mean normalization preprocessing on the hyperspectral image data, to address the challenges of large data volume, numerous overtone bands, information overlap, and high noise content in hyperspectral image data, a competitive adaptive reweighted sampling algorithm is proposed to select feature bands. This simplifies spectral information, reduces data processing time, and improves the efficiency and stability of subsequent modeling. Through this algorithm, the key feature bands closely related to chicken freshness classification can be effectively selected from numerous bands, thereby optimizing the analysis process and improving the performance of the final model.
[0086] The competitive adaptive reweighted sampling algorithm mainly consists of the following steps:
[0087] (1) Monte Carlo model sampling
[0088] This step involves randomly partitioning the dataset and building a model for analysis. Typically, the partition ratio is chosen between 75% and 85%, partial least squares is used for modeling, and the percentage of the absolute value of the regression coefficient is used as an indicator of the variable's importance.
[0089] (2) Selection of exponential decay wavelength
[0090] The competitive adaptive reweighted sampling algorithm initially models all variables. During N iterations, the number of variables determined in each iteration gradually decreases, based on the following exponentially decreasing function:
[0091] r s =ae -ks
[0092] r here s This is the number of variables determined in the s-th iteration, where a and k are parameters of the exponentially decaying function, which can be determined by the constraints r1 = P and The process is determined by P, where r1 is the number of variables determined in the initial iteration, and N is the number of iterations. This process is divided into a "rapid selection" phase and a "refined selection" phase.
[0093] a and k can be obtained using the following formula:
[0094]
[0095]
[0096] (3) Adaptive reweighting sampling
[0097] The variables are eliminated based on the number of variables determined iteratively in step (2). The frequency of occurrence of the variables is represented by weights. Then, an analysis and prediction model based on the selected variables is established, and the root mean square error of its cross-validation is calculated.
[0098] (4) Iteration
[0099] Set the number of iterations, and determine the optimal set of variables based on the minimum root mean square error during the iteration process. This set is the desired feature variable.
[0100] After selecting the characteristic bands, a data fusion approach is used. The visible light hyperspectral dataset and the short-wave near-infrared spectral dataset, after mean normalization preprocessing, are stitched together using a software algorithm to form a multi-feature fused dataset. This fused dataset provides richer information than individual spectral components. Data fusion, also known as multi-source information fusion, is a process of processing and integrating information from multiple sensors or data sources to enrich the data and obtain more useful or accurate information. The goal of data fusion is to combine the advantages of multiple data sources while reducing information uncertainty caused by measurement errors, noise, and incompleteness; it is a multi-level processing procedure. The specific steps of data fusion are as follows:
[0101] There are two one-dimensional arrays: one of which is the visible light hyperspectral dataset: V = [v1, v2, ..., v oAnother one-dimensional array is the short-wave near-infrared spectral dataset: NIR = [nir1, nir2, ..., nir] q In the two arrays above, o and q represent the number of bands in the visible hyperspectral and short-wave near-infrared spectra, respectively, and v o This represents visible light hyperspectral data for a specific band within the visible light hyperspectral spectrum. (nir) q This represents shortwave near-infrared spectral data for a specific band within the shortwave near-infrared spectrum.
[0102] In this method, data fusion can also be represented as the concatenation of the two one-dimensional arrays above, which combines the spectral image data from the two parts into a new contiguous array F:
[0103] F = [v1, v2, ..., v o ,nir1,nir2,...,nir q ]
[0104] Then, the array after data fusion, i.e. the data fusion dataset, is used for subsequent chicken freshness classification modeling.
[0105] To address the characteristics of hyperspectral image data, an improved residual network was employed, incorporating a series of design optimizations to enhance performance. First, a one-dimensional convolutional layer was introduced, which is particularly effective for processing one-dimensional hyperspectral image data. This one-dimensional convolutional layer specifically extracts features related to spatial correlations in the data, enabling the network to better analyze and learn the relevant features of chicken freshness in hyperspectral image data.
[0106] The residual block design incorporates 1×1 convolutional layers, whose primary function is to adjust the number of channels and stride in the network. This design allows for efficient information transfer between different layers while controlling network complexity and computational requirements. 1×1 convolutional layers are widely used in convolutional neural networks because they can perform feature integration without significantly increasing computational burden.
[0107] In addition, the residual block integrates batch normalization and the ReLU activation function. Batch normalization helps the network remain stable during training, speeds up convergence, and reduces sensitivity to initial weights. The ReLU activation function alleviates the vanishing gradient problem, enabling the network to maintain an effective gradient flow even at deeper layers, thereby improving learning efficiency.
[0108] Specifically, the improved residual network used for chicken freshness classification in this method mainly consists of the following network structure:
[0109] Input layer: Hyperspectral image data is input into the network. This data is acquired by a visible hyperspectral imager and a short-wave near-infrared imager and preprocessed to represent the spectral characteristics of chicken samples.
[0110] Initial Convolutional Layer: The input hyperspectral image data first flows through a convolutional layer with 64 filters, each 5×5 in size, with a stride of 2 and padding of 2. The purpose of this convolutional layer is to extract primary features from the chicken sample while simultaneously reducing the dimensionality of the data for further processing.
[0111] Batch normalization layer and ReLU activation function: After the initial convolutional layer, a batch normalization layer is set to adjust the distribution of activation values, thereby reducing the impact of internal covariate shifts. Next is the ReLU activation function, which introduces necessary non-linearity to the network, helping to enhance the network's ability to classify chicken freshness.
[0112] Max pooling layer: A max pooling layer is used to further process the feature map, with a 3×3 kernel size, a stride of 2, and padding of 1. This max pooling layer helps reduce the feature dimensionality and highlights important features, and is particularly effective for important spectral features in hyperspectral image data.
[0113] Residual Blocks: The core of a residual network consists of multiple residual blocks, each containing two convolutional layers with the same output dimension and skip connections to directly add the input to the output. When a change in dimension is needed, a 1×1 convolution with a stride of 2 is used to achieve dimension matching. These residual blocks help maintain gradient stability during training, mitigating the vanishing or exploding gradient problem, thus ensuring effective training of deep networks.
[0114] The basic idea of residual blocks is to learn the residual mapping F(x) = H(x) - x between the input and output, where H(x) is the desired mapping and x is the input of the block.
[0115] The formula for the residual block can be expressed as:
[0116] Y = F(Z, {w i})+G(Z)
[0117] In the formula, Z is the input, {w i} is the weight set of the convolutional layer, F(Z,{w i}) is the residual mapping learned through weights, and Y is the final output. G(Z) is a transformation function used when using a 1×1 convolution kernel to ensure that the dimension of Z is consistent with that of F(Z,{w}). i The dimensions match.
[0118] Adaptive Average Pooling Layer: After processing through multiple residual blocks, the feature maps are passed through an adaptive average pooling layer, reducing the spatial size of each feature map to 1×1. This step transforms the feature map into a fixed-size vector for use in subsequent fully connected layers.
[0119] Fully connected layer and Dropout layer: After the feature map is converted into a fixed-size vector, it is fed into a fully connected layer. The number of output nodes of this layer is determined by the number of chicken freshness categories (fresh, slightly fresh, spoiled). To reduce the risk of overfitting, a Dropout layer is set before the fully connected layer. The Dropout layer randomly discards a portion of neurons to increase the generalization ability of the chicken freshness classification model.
[0120] In summary, this improved residual network combines the spatial feature extraction capability of one-dimensional convolutional layers with the depth information transfer mechanism of residual blocks, making the network more efficient and accurate in processing hyperspectral image data. Moreover, it has demonstrated excellent performance in practical applications, especially in the classification task of hyperspectral image data for chicken freshness.
[0121] Finally, the specific steps for freshness modeling and analysis are as follows:
[0122] The visible light hyperspectral image dataset and the short-wave near-infrared spectral dataset, which have undergone mean normalization preprocessing, are input into the improved residual network;
[0123] The feature band dataset, composed of feature bands selected by a competitive adaptive reweighted sampling algorithm, is input into the improved residual network.
[0124] The data fusion dataset, which is organized and spliced using data fusion technology, is input into the improved residual network;
[0125] The performance and efficiency of the model are evaluated by comparing the accuracy on the test set and the time spent building the model after the above dataset is input into the improved residual network for modeling. By comparing the two indicators of accuracy and time, the result with the highest accuracy on the test set and the shortest model building time is selected as the non-destructive classification result of chicken freshness.
[0126] Through the above steps, the method of the present invention can not only achieve rapid and accurate classification of chicken freshness, but also optimize the existing chicken freshness detection process, significantly improving the efficiency and effectiveness of chicken freshness detection.
[0127] To facilitate understanding of the implementation of the technical solution, we will use specific data for demonstration. The specific process is as follows:
[0128] First, using a scalpel, chicken breast samples were precisely cut from the chicken carcass to ensure that several 30 mm × 30 mm × 10 mm (length × width × height) samples were obtained from each chicken. The collected chicken breast samples were then stored in a 4°C incubator, and their total volatile basic nitrogen (TVB-N) values were periodically measured. Based on freshness classification standards, the samples were categorized as fresh, slightly stale, or spoiled.
[0129] Next, visible light hyperspectral and short-wave near-infrared spectral image data of the samples were collected. Since the visible light near-infrared hyperspectral and short-wave near-infrared spectral data share the same imaging platform, see... Figure 1 As shown, therefore, after acquiring visible hyperspectral and short-wave near-infrared spectral image data, it is necessary to change the corresponding lens and adjust the platform parameters to adapt to the corresponding spectral range. Furthermore, before acquiring hyperspectral image data, the system should be warmed up and black-and-white correction performed to ensure data accuracy. After acquiring hyperspectral images and extracting regions of interest, the spectral data preprocessing unit performs spectral preprocessing using mean normalization to obtain the visible hyperspectral image dataset and the short-wave near-infrared spectral dataset.
[0130] After preprocessing, a competitive adaptive reweighted sampling algorithm is used to select feature wavelengths, and the selected feature bands and the corresponding preprocessed hyperspectral image data are used to form a feature band dataset.
[0131] After selecting the characteristic bands, the above visible hyperspectral and shortwave near-infrared spectral image data are stitched together by software algorithms through data fusion to form a multi-feature data fusion dataset, which can provide richer information than individual spectral parts.
[0132] In the field of deep learning, confusion matrices are commonly used to visualize model performance, and evaluation metrics can be calculated from the confusion matrix. This method primarily uses two metrics to evaluate the performance of the detection and classification model: the accuracy on the test set after modeling with an improved residual network across multiple datasets, and the time required for modeling.
[0133] The accuracy rate is calculated as follows:
[0134]
[0135] Given an instance and a classifier, an instance that is positive and is classified as positive is counted as a true positive (TP); if it is classified as negative, it is counted as a false negative (FN). An instance that is negative and is classified as negative is counted as a true negative (TN); if it is classified as positive, it is counted as a true negative (FP).
[0136] The data from the above dataset is input into the trained improved residual network. The network output shows that... Figures 2 to 5 As shown, by improving the residual network for training and modeling, the accuracy of the visible light hyperspectral dataset and the short-wave near-infrared spectral dataset after mean normalization preprocessing on the test set were 97.18% and 98.31%, respectively. The accuracy of the feature band dataset composed of feature bands selected using the competitive adaptive reweighted sampling algorithm on the test set was 98.87%, and the accuracy of the data fusion dataset composed of feature bands selected using data fusion technology was 99.31%. Meanwhile, due to the difference in data volume among the three datasets, the data fusion dataset took the longest to model, while the feature band dataset took the shortest. Therefore, in practical applications, if extremely high-precision freshness classification is required, data fusion technology can be applied. If both efficiency and accuracy are considered, the best approach is to select the feature bands using the competitive adaptive reweighted sampling algorithm and build a classification model using the feature band dataset. In other words, the model that best meets the actual application requirements should be selected based on the application scenario to achieve the best freshness classification effect.
[0137] The above-described embodiments are merely preferred embodiments of the present invention and are not intended to limit the scope of the present invention. Therefore, any changes made in accordance with the shape and principle of the present invention should be covered within the protection scope of the present invention.
Claims
1. A non-destructive method for detecting the freshness of chicken, characterized in that, Includes the following steps: S1: Collect hyperspectral image data of the chicken sample to be tested, wherein the hyperspectral image data includes visible hyperspectral data and short-wave near-infrared spectral data; S2: The acquired hyperspectral image data is preprocessed by mean normalization to form a visible hyperspectral dataset and a short-wave near-infrared spectral dataset. These two datasets together constitute the preprocessed hyperspectral image data. The mean normalization preprocessing is performed by subtracting the average value of each feature value and making the overall data distribution centered at zero, thereby eliminating the influence of different dimensions and numerical ranges. S3: The competitive adaptive reweighted sampling algorithm is used to extract feature wavelengths from the preprocessed hyperspectral image data to screen out feature bands closely related to chicken freshness, and feature band datasets are formed by selecting feature bands and corresponding hyperspectral image data. S4: Perform data fusion on the preprocessed visible light hyperspectral dataset and short-wave near-infrared spectral dataset to form a data fusion dataset; S5: The preprocessed visible light hyperspectral dataset, shortwave near-infrared spectral dataset, feature band dataset, and data fusion dataset are input into a pre-trained chicken freshness classification model. This chicken freshness classification model is an improved residual network. The output of the improved residual network includes the accuracy of modeling on the test set and the model building time required. By comparing these two metrics, the result with the highest accuracy and the shortest model building time on the test set is selected as the lossless classification result for chicken freshness. The improved residual network introduces a one-dimensional convolutional layer for hyperspectral image data processing and optimizes the design of the residual blocks, making the residual blocks contain 1×1 convolutional layers for adjusting the number of channels and stride. At the same time, the residual blocks also contain batch normalization and ReLU activation functions, which enhance the network's ability to process hyperspectral image data and improve the information flow and learning efficiency of the network in the deep structure.
2. The non-destructive testing method for chicken freshness according to claim 1, characterized in that, The specific steps for step S1 are as follows: S11: Before acquiring hyperspectral image data, start the visible hyperspectral instrument and the short-wave near-infrared spectrometer and warm up for 30 minutes. S12: Visible hyperspectral images are acquired using a visible hyperspectral instrument with a spectral resolution of 5.5 nm and a spectral wavelength range of 397-1003 nm; S13: Acquire short-wave near-infrared spectral images using a short-wave near-infrared spectrometer with a spectral resolution of 8 nm and a wavelength range of 935-1720 nm; S14: Select the region of interest in the visible hyperspectral image and the short-wave near-infrared spectral image, acquire the visible hyperspectral data and the short-wave near-infrared spectral data, merge all the visible hyperspectral data to form a visible hyperspectral dataset, merge all the short-wave near-infrared spectral data to form a short-wave near-infrared spectral dataset, and the visible hyperspectral dataset and the short-wave near-infrared spectral dataset together constitute the required hyperspectral image data.
3. The non-destructive testing method for chicken freshness according to claim 2, characterized in that, In step S2, the mean normalization preprocessing specifically includes: S21: For each band of the hyperspectral image data, calculate the mean of all samples. Let X be an m×n data matrix, where m represents the number of samples and n represents the number of bands. For the j-th band, calculate the mean of all samples: In the formula, X ij It is the value of the i-th sample in the j-th band. It is the mean of the j-th sample; S22: Subtract the average value of the corresponding band from the value of each sample in each band to obtain the mean-normalized value: In the formula, X norm.ij It is the normalized value of the mean of the i-th sample in the j-th band.
4. The non-destructive testing method for chicken freshness according to claim 3, characterized in that, In step S3, a competitive adaptive reweighted sampling algorithm is used to extract feature wavelengths, specifically including: S31: Monte Carlo model sampling is adopted, the dataset is randomly split with a split ratio of 75%-85%, and a partial least squares model is established, using the percentage of absolute values of regression coefficients as the importance index of variables. S32: Employs an exponential decay function. r s =ae -ks Determine the number of variables to retain in each iteration, where a and k are parameters of the exponential decay function, and r s is the number of variables determined in the s-th iteration; where a and k are determined by the following constraints: r1=P In the formula, r1 is the number of variables determined in the initial iteration, denoted by P, and r N This is the number of variables determined in the Nth iteration, where N is the number of iterations. Then, a and k can be calculated using the following formula: S33: Based on the number of variables determined in step S32, variables are eliminated, and the frequency of occurrence of variables is represented by weights. Then, an analysis and prediction model based on the selected variables is established, and the root mean square error of its cross-validation is calculated. S34: Set the number of iterations. Determine the optimal set of variables based on the minimum root mean square error during the iteration process. This set is the desired characteristic band. After selecting the characteristic bands, the characteristic bands and the data they contain are extracted from the preprocessed hyperspectral image data to form a characteristic band dataset for subsequent modeling and analysis.
5. The non-destructive testing method for chicken freshness according to claim 4, characterized in that, In step S4, the specific operations of data fusion are as follows: Visible hyperspectral dataset and shortwave near-infrared spectral dataset are stitched together using software algorithms to form a multi-feature data fusion dataset, which can provide richer information than individual spectral components. The visible light hyperspectral dataset is a one-dimensional array, represented as: V=[v1,v2,...,v o The shortwave near-infrared spectral dataset is a one-dimensional array, represented as: NIR=[nir1,nir2,...,nir] q ], where o and q represent the number of bands in the visible hyperspectral and short-wave near-infrared spectra, respectively, and v o This represents visible light hyperspectral data for a specific band within the visible light hyperspectral spectrum. (nir) q This represents shortwave near-infrared spectral data for a specific band within the shortwave near-infrared spectrum. Data fusion is represented as the concatenation of two arrays, which places data from two spectral regions into a new contiguous array F: F=[v1,v2,...,v o ,nir1,nir2,...,nir q ] The resulting array, or data fusion dataset, is used for subsequent chicken freshness classification modeling.
6. The non-destructive testing method for chicken freshness according to claim 5, characterized in that, The improved residual network includes: Input layer: Hyperspectral image data is input into the network. This data is acquired by a visible hyperspectral imager and a short-wave near-infrared imager and is preprocessed to represent the spectral characteristics of chicken samples. Initial convolutional layer: The input hyperspectral image data first flows through a convolutional layer with 64 filters, each filter being 5×5 in size, with a stride of 2 and padding of 2. The purpose of this convolutional layer is to extract primary features of the chicken sample while reducing the dimensionality of the data. Batch normalization layer and ReLU activation function: After the initial convolutional layer, a batch normalization layer is set to adjust the distribution of activation values, thereby reducing the influence of internal covariate shift. Then there is the ReLU activation function, which introduces the necessary non-linearity to the network and helps to enhance the network's ability to classify chicken freshness. Max pooling layer: The feature map is further processed using a max pooling layer with a pooling kernel size of 3×3, a stride of 2, and padding of 1. This max pooling layer helps to reduce the feature dimension and highlight important spectral features. Residual blocks: The main body of a residual network consists of multiple residual blocks. Each residual block contains two convolutional layers with the same output dimension and includes skip connections to directly add the input to the output. When the dimension needs to be changed, a 1×1 convolution with a stride of 2 is used to achieve dimension matching. These residual blocks help maintain gradient stability during training, thereby ensuring the effective training of deep networks. The basic idea of residual blocks is to learn the residual mapping F(x) = H(x) - x between the input and output, where H(x) is the desired mapping and x is the input of the block; The formula for the residual block is expressed as: Y=F(Z,{w i })+G(Z) In the formula, Z is the input, {w i } is the weight set of the convolutional layer, F(Z,{w i }) is the residual mapping learned through weights, Y is the final output; G(Z) is a transformation function used to ensure that the dimension of Z is the same as that of F(Z,{w) when using a 1×1 convolution kernel for convolution. i The dimensions match; Adaptive average pooling layer: After processing multiple residual blocks, the feature map is processed by the adaptive average pooling layer, which reduces the spatial size of each feature map to 1×1. The adaptive average pooling layer transforms the feature map into a fixed-size vector for use in subsequent fully connected layers. Fully connected layer and Dropout layer: After the feature map is converted into a fixed-size vector, it is fed into a fully connected layer. The number of output nodes of the fully connected layer is determined by the number of chicken freshness categories, including fresh, slightly fresh, and spoiled. To reduce the risk of overfitting, a Dropout layer is set before the fully connected layer. The Dropout layer randomly discards a portion of neurons to increase the generalization ability of the chicken freshness classification model.
7. The non-destructive testing method for chicken freshness according to claim 6, characterized in that, Specific improvements to the residual network include: Introducing a one-dimensional convolutional layer is beneficial because hyperspectral image data is one-dimensional; therefore, a one-dimensional convolutional layer can adapt to the processing of hyperspectral image data, thereby extracting features more effectively. The design optimizes the residual blocks by including 1×1 convolutional layers and batch normalization layers for adjusting the number of channels, as well as ReLU activation functions, to enhance the expressive power of the chicken freshness classification model and accelerate the training process. The residual blocks also contain identity mapping residual connections to preserve feature information, which helps prevent gradient vanishing and allows for the training of deeper network structures without performance loss.
8. The non-destructive testing method for chicken freshness according to claim 7, characterized in that, In step S5, the specific steps of freshness modeling and analysis are as follows: The visible light hyperspectral image dataset and the short-wave near-infrared spectral dataset, which have undergone mean normalization preprocessing, are input into the improved residual network; The feature band dataset, composed of feature bands selected by a competitive adaptive reweighted sampling algorithm, is input into the improved residual network. The data fusion dataset, which is organized and spliced using data fusion technology, is input into the improved residual network; The performance and efficiency of the model are evaluated by comparing the accuracy on the test set and the time spent building the model after the above dataset is input into the improved residual network for modeling. By comparing the two indicators of accuracy and time, the result with the highest accuracy on the test set and the shortest model building time is selected as the non-destructive classification result of chicken freshness.
Citation Information
Patent Citations
Method for detecting lignification grade of chicken breast based on hyperspectral imaging technology
CN116754502A