A near-infrared nonlinear discrimination method for fruit sorting
Through a near-infrared nonlinear discrimination method for fruit sorting, combined with data fusion, Monte Carlo stochastic sampling and BP neural network, the problems of limited and uneven sample size are solved, and the accuracy and reliability of fruit sorting are improved.
Patent Information
- Application Number
- CN202510134160.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-07
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2045-02-07
AI Technical Summary
In fruit sorting, it is difficult for the prior art to effectively utilize nonlinear modeling methods when the number of samples is limited, and the sample imbalance problem affects the accuracy and generalization ability of the sorting model.
The near-infrared nonlinear discrimination method for fruit sorting is adopted, and the pre-processed spectral data is mixed with the moving smoothing spectral data through data fusion technology. Combined with the Monte Carlo random sampling method and the reverse BP neural network, the sample weight coefficient is constructed using the probability density and classification error rate of the sample data set to construct the sample weight coefficient and construct a nonlinear discriminant model.
It improves the accuracy and reliability of fruit sorting, reduces the influence of factors such as uneven spectral collection locations and sample chemical values on the discriminant model, and enhances the generalization ability of the model.
Smart Images

Figure CN119577663B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of artificial intelligence technology, and in particular to a near-infrared nonlinear discrimination method for fruit sorting. Background Art
[0002] Near infrared spectroscopy technology can achieve non-destructive testing of the internal quality of fruits by utilizing the differences in the optical absorption and scattering of different wavelengths by the internal components of different fruits. Specifically, near infrared spectroscopy technology can detect the sugar content, acidity and other indicators of fruits, and can even identify internal defects of fruits to a certain extent. This allows for a quick and accurate assessment of the quality of the fruit without destroying its appearance.
[0003] The sweetness, acidity and certain lesions of fruits can be quickly detected in real time and sorted according to the results. This helps to price and sell fruits more accurately based on their intrinsic quality. However, as a complex natural product, the chemical composition and physical properties of fruits vary among different sample individuals. These sample-related factors such as size, color, peel thickness, origin, variety, etc. will bring challenges to the robustness of spectral prediction models.
[0004] The analysis and modeling of near-infrared spectral data is a complex process that requires professional knowledge and technology. Different fruit varieties and quality indicators may require different prediction models, and the establishment and optimization of models require a large amount of experimental data and experience accumulation. In order to obtain accurate and reliable sorting results, a near-infrared spectral classification and discrimination model combined with fruit characteristics is crucial.
[0005] Xu Wenli et al. (Spectroscopy and Spectral Analysis, 2012, 32 (11): 3002-3005) collected near-infrared spectral data from different parts of navel oranges to analyze soluble solids and evaluated the sugar content prediction performance at different measurement parts. Qin Kai et al. (Spectroscopy and Spectral Analysis 2021, 41 (11): 3405-3410) studied the effects of four transport orientations on near-infrared spectral detection of apple core rot, established a discriminant model using PLSDA, and obtained an effective posture for online detection of apple core rot. However, in practical applications, under the requirement of high production efficiency, it is difficult to measure multiple parts simultaneously by measuring only the spectral data of a single part, and it is inevitable to overcome the influence of different collection positions and fruit postures.
[0006] The relationship between fruit detection indicators and spectral data is not a simple linear relationship, but a complex nonlinear relationship. In order to describe this relationship more accurately, a nonlinear modeling method is needed. Neural networks have powerful nonlinear mapping capabilities and can learn and approximate complex functional relationships. By training the neural network model, feature information related to fruit detection indicators can be extracted from spectral data, and a nonlinear prediction model between the two can be established. Nonlinear modeling methods often require a large number of training samples to fully learn and mine the laws and features in the data.
[0007] However, in practical applications, due to various limitations, it is often difficult to obtain enough sample data. Therefore, how to effectively use nonlinear modeling methods for fruit sorting when the number of samples is limited has become an important challenge we face. In addition, during the online fruit sorting process, the collected samples often have an imbalance problem, that is, the number of fruit samples of certain quality grades is large, while the number of samples of other grades is relatively small. This sample imbalance will have an adverse effect on the accuracy and generalization ability of the sorting model. Summary of the invention
[0008] Based on the technical problems existing in the background technology, the present invention proposes a near-infrared nonlinear discrimination method for fruit sorting, which improves the accuracy and reliability of fruit sorting.
[0009] The present invention proposes a near-infrared nonlinear discrimination method for fruit sorting, which inputs the spectral data of the fruit into a trained classification discrimination model to output the classification result of the fruit;
[0010] The training process of the classification and discrimination model is as follows:
[0011] Obtain and preprocess the spectral dataset of fruits, perform moving smoothing on the preprocessed spectral dataset, mix the preprocessed spectral dataset with the spectral dataset after moving smoothing as a sample dataset, determine the optimal clustering number of the sample dataset through the R² statistic, and set classification labels for the spectral data in the sample dataset based on the optimal clustering number;
[0012] The sample data set is randomly sampled using the Monte Carlo method to divide it into a training set and a first test set, the discriminant model is trained based on the training set, the classification results of the random sampling are obtained, and the classification error rate of each sample is counted;
[0013] The sample weight coefficient of the final discriminant model is constructed based on the probability density value corresponding to the chemical value of each sample and the classification error rate of each sample. The sample weight coefficient is used to weight the samples of the trained discriminant model to construct a nonlinear discriminant model.
[0014] The Monte Carlo method is used to randomly sample the sample data set and divide it into a calibration set and a second test set. The calibration set is used as input. The nonlinear discriminant model obtains the predicted output value based on the input sample data and the sample weight coefficient. The loss value is calculated based on the predicted output value and the true value to optimize the trainable parameters of the classification discriminant model.
[0015] Furthermore, in determining the optimal number of clusters for a sample data set using the R² statistic, specifically:
[0016] Calculate the sum of squared errors of the sample data set under different clustering values K;
[0017] Plot the sum of squared errors versus the number of clusters;
[0018] Based on the fact that the curve graph tends to be flat, forming a shape similar to an "elbow", the number of clusters corresponding to the "elbow point" is taken as the optimal number of clusters for the sample data set.
[0019] Furthermore, the discriminant model adopts a multi-layer BP neural network. In each layer of the neural network, the output of the previous layer of the neural network is multiplied by the current weight coefficient, and the output value is obtained through the activation function; the last layer of neurons obtains the predicted output value.
[0020] Furthermore, when a two-layer BP neural network is used, the sample weight coefficient determination process of the nonlinear discriminant model is as follows:
[0021] The Monte Carlo method is used to divide the training set and test set multiple times, and the classification error rate of each sample in the training set is calculated. , construct sample weights based on error rate ;
[0022] Calculate the sample probability density corresponding to each sample in each sample chemical value , construct sample weights based on sample probability density ;
[0023] Weight the samples and As the weight coefficient of the first layer of BP neural network, and as a non-trainable parameter during the training process;
[0024] The weight coefficient of the second layer BP neural network is determined based on prior knowledge and used as a trainable parameter during the training process.
[0025] Furthermore, the process of obtaining the preprocessed spectral dataset is as follows:
[0026] Acquire spectral data to construct a dataset;
[0027] The correlation coefficient and Manhattan distance between each pair of samples in the data set are calculated to remove abnormal spectral data and obtain the preprocessed spectral data set.
[0028] Furthermore, the Manhattan distance for:
[0029] ;
[0030] in, for Middle Spectral data of wavelengths, for Middle Spectral data of wavelengths, and There are two samples corresponding to Spectral data at wavelength points.
[0031] Furthermore, the construction process of the training set and test set is as follows:
[0032] Determine the ratio of training set and test set;
[0033] Using the Monte Carlo method, a number between 0 and 1 is randomly generated for each spectral data in the sample data set through random sampling, and the spectral data less than the preset threshold is assigned to the test set; the spectral data greater than or equal to the preset threshold is assigned to the training set;
[0034] Repeat the random sampling process multiple times, and recalculate the statistics of the training set and test set after each random sampling;
[0035] The discriminant model is trained and evaluated based on the obtained multiple sets of training sets and test sets.
[0036] Furthermore, after calculating the loss value based on the predicted output value and the true value, the loss value is used as the error value to calculate the error signal of each layer of the neural network in the nonlinear discriminant model layer by layer, and the weights and bias items of each layer of the neural network are adjusted according to the error signal and the gradient descent strategy.
[0037] Furthermore, after calculating the loss value based on the predicted output value and the true value, determine whether the loss value reaches the preset range or whether the number of iterations reaches the upper limit. If so, stop training; otherwise, enter the back propagation stage: use the loss value as the error value to propagate back layer by layer to calculate the error signal of each layer of the BP neural network in the classification discrimination model.
[0038] Furthermore, in calculating the loss value based on the predicted output value and the true value, the loss value is calculated by a mean square error function.
[0039] The advantages of the near-infrared nonlinear discrimination method for fruit sorting provided by the present invention are as follows: the near-infrared nonlinear discrimination method for fruit sorting provided in the structure of the present invention adopts data fusion technology to mix the pre-processed spectral data with the spectral data after moving smoothing as a sample data set, so as to effectively use the nonlinear modeling method for fruit sorting under the condition of limited sample quantity, and combines the Monte Carlo random sampling method and the reverse BP neural network to construct the sample weight coefficient by using the probability density and classification error rate of the sample data set, solve the problem of sample imbalance, and improve the generalization ability of the training discrimination model. In fruit sorting, the influence of factors such as the spectral collection position and the uneven chemical value of the sample on the discrimination model is reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 It is a schematic diagram of the process of the present invention;
[0041] Figure 2 Schematic diagram of screening spectral data sets by correlation coefficient and Manhattan distance, (a1) is a schematic diagram of correlation coefficient of spectral data sets, (b1) is a schematic diagram of Manhattan distance of spectral data sets;
[0042] Figure 3 Schematic diagram for determining the optimal number of clusters. (a2) is the R² statistic for determining the optimal number of clusters for a sample data set, and (b2) is the elbow method for determining the optimal number of clusters for a sample data set.
[0043] Figure 4 Schematic diagram of prediction accuracy verification, (a3) is a schematic diagram of the prediction accuracy of spectral data of one channel before smoothing (data1), after smoothing (data2) and smooth data enhancement (data3), (b3) is a schematic diagram of the prediction accuracy of spectral data of another channel before smoothing (data1), after smoothing (data2) and smooth data enhancement (data3), where smooth data enhancement is a sample data set obtained by mixing the data set before smoothing and the data set after smoothing;
[0044] Figure 5 Schematic diagram of multiple prediction results before smoothing (data1), after smoothing (data2) and smooth data enhancement (data3), (a4) is a schematic diagram of accuracy, (b4) is a schematic diagram of Matthews Correlation Coefficient, (c4) is a schematic diagram of Area Under the Curve, and (d4) is a schematic diagram of F1 Score. DETAILED DESCRIPTION
[0045] Below, the technical solution of the present invention is described in detail through specific embodiments. Many specific details are set forth in the following description to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways different from those described herein, and those skilled in the art can make similar improvements without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific implementation disclosed below.
[0046] like Figures 1 to 5 As shown, the present invention proposes a near-infrared nonlinear discrimination method for fruit sorting, which inputs the spectral data of the fruit into a trained discrimination model to output the classification result of the fruit;
[0047] The training process of the classification and discrimination model is as follows:
[0048] Step 1: Obtain and preprocess the spectral data set of fruits, perform moving smoothing on the preprocessed spectral data set, mix the preprocessed spectral data set with the spectral data set after moving smoothing as a sample data set, determine the optimal clustering number of the sample data set through the R² statistic, and set classification labels for the spectral data in the sample data set based on the optimal clustering number;
[0049] The spectral data set is screened by correlation coefficient and Manhattan distance: spectral data is obtained to construct a data set; the correlation coefficient and Manhattan distance between two samples in the data set are calculated to remove abnormal samples and obtain the preprocessed spectral data set.
[0050] Among them, the correlation coefficient is an important statistical indicator used to quantify the degree of linear correlation between two or more variables. It provides a mathematical method to measure the strength and direction of the relationship between variables. The value range of the correlation coefficient is usually between -1 and 1. When the correlation coefficient is 1, it means that the two variables are completely positively correlated, that is, when one variable increases, the other variable must also increase; when the correlation coefficient is -1, it means that the two variables are completely negatively correlated, that is, when one variable increases, the other variable must decrease. If the correlation coefficient is 0, it means that there is no linear correlation between the two variables:
[0051] Manhattan distance, also known as city block distance, is a method for calculating the distance between two points in multidimensional space. Unlike Euclidean distance, Manhattan distance does not consider the straight-line distance between two points when calculating, but the sum of their absolute differences in each dimension. Manhattan distance is also robust to outliers and noise in the data. In some cases, when there are some outliers or noise in the data, using Euclidean distance may lead to large errors, while Manhattan distance is less sensitive to these outliers and noise because it only considers the absolute differences in each dimension.
[0052] set up , The two samples correspond to The spectral data at wavelength points, and its correlation coefficient for:
[0053] ;
[0054] in, for The covariance between for The variance of .
[0055] Manhattan distance for:
[0056] ;
[0057] in, for Middle Spectral data of wavelengths, for Middle Spectral data at each wavelength.
[0058] Outliers are common in online spectra. To improve the quality of data, this embodiment removes outliers by combining correlation coefficient and Manhattan distance to obtain a preprocessed spectral data set.
[0059] After obtaining the preprocessed spectral data set, it is necessary to add classification labels to the data. The specific method is: determine the optimal number of clusters of the sample data set through the R² statistic, and set classification labels for the spectral data in the sample data set based on the optimal number of clusters.
[0060] In this embodiment, the R² statistic is used in cluster analysis to help determine the optimal number of clusters. In cluster analysis, determining the appropriate number of clusters is a key issue because it directly affects the interpretability and effectiveness of the clustering results. By calculating the R² statistic under different cluster numbers, the ability of the model corresponding to each cluster number to interpret the data can be measured. A higher R² value means that the number of clusters can better capture the structure and characteristics in the spectral data, and thus may be closer to the actual clustering situation. Therefore, by comparing the R² statistics under different cluster numbers, a cluster number that can fully reveal the data structure without over-subdividing can be found, thereby determining the optimal number of clusters. This application of the R² statistic provides a quantitative and objective method for cluster analysis to determine the optimal number of clusters, which helps to improve the accuracy and reliability of clustering results.
[0061] The R² statistic is: ,in is the residual sum of squares, is the total sum of squares.
[0062] The Elbow Method is a commonly used visualization method in cluster analysis to determine the optimal number of clusters. The core idea of this method is to find an "elbow point" to determine the optimal number of clusters by plotting the relationship between the number of clusters and the sum of squared clustering errors (SSE).
[0063] Specifically, as the number of clusters increases, the degree of aggregation of each cluster will increase, so that the sum of squared clustering errors will gradually decrease. However, when the number of clusters reaches a certain value, the improvement brought by increasing the number of clusters will become very small, which is reflected in the graph as the curve begins to flatten out, forming a shape similar to an "elbow". The number of clusters corresponding to this "elbow point" is usually considered to be the optimal number of clusters, because it can maintain the clustering effect while avoiding the increased complexity caused by over-division.
[0064] In determining the optimal number of clusters for a spectral dataset based on the R² statistic, the main steps include (1) to (3):
[0065] (1) Calculate the sum of squared errors (SSE) of the spectral dataset under different clustering values K: Starting from K = 1, gradually increase the K value. Each time the K value is increased, re-run the K-means clustering algorithm and calculate the current SSE.
[0066] (2) Draw a graph of the relationship between SSE and K value: Draw the SSE corresponding to different K values on the graph to form a curve.
[0067] (3) Based on the fact that the curve tends to be flat, forming a shape similar to an "elbow", the number of clusters corresponding to the "elbow point" is taken as the optimal number of clusters: observe the changing trend of the curve and find the point where the SSE decreases slowly, that is, the "elbow". The K value at this point is usually considered to be the optimal number of clusters in the data set.
[0068] Through the elbow method, we can intuitively observe the clustering effect under different cluster numbers and find a balance point so that the clustering results can reveal the inherent structure of the data without being too trivial. This method is simple and easy to use, and does not require complex calculations and parameter adjustments, so it has been widely used in practice. Given the low quality of online data, the R² statistic and the elbow method are combined to find the optimal cluster number.
[0069] like Figure 4As shown, (a3) and (b3) are schematic diagrams of the prediction accuracy of the spectral data of two channels before smoothing (data1), after smoothing (data2) and smoothed data enhancement (data3), wherein the data set before smoothing (data1) is the preprocessed spectral data set, the data set after smoothing (data2) is the spectral data set after moving smoothing, and the smoothed data enhancement (data3) is a sample data set obtained by mixing the preprocessed spectral data set with the spectral data set after moving smoothing. It can be seen from the drawings of (a3) and (b3) that this embodiment significantly improves the prediction accuracy of the discriminant model by mixing the data before smoothing and the data after smoothing as the sample data set.
[0070] Step 2: Use the Monte Carlo method to randomly sample the sample data set to divide it into a training set and a first test set, train the discriminant model based on the training set, obtain the classification results of the random sampling and calculate the classification error rate of each sample;
[0071] After obtaining the sample data set, this embodiment is often difficult to obtain enough sample data due to various factors. Therefore, this embodiment uses the Monte Carlo method to enrich the sample data, so as to effectively use the nonlinear modeling method to sort fruits when the number of samples is limited, specifically: determine the ratio of the training set and the first test set; use the Monte Carlo method to randomly generate a number between 0 and 1 for each spectral data in the sample data set through random sampling, and assign the spectral data less than the preset threshold to the first test set; assign the spectral data greater than or equal to the preset threshold to the training set; in order to ensure the representativeness of the training set and the first test set, repeat the random sampling process for many times, and recalculate the statistical data of the training set and the first test set after each random sampling, such as the mean, variance, etc.
[0072] Evaluation results: After repeated sampling, the stability and reliability of the discriminant model can be evaluated based on the results of multiple training sets and the first test set. This method is particularly suitable for small data sets because it can make full use of limited data through repeated sampling.
[0073] Step 3: construct the sample weight coefficient of the final discriminant model based on the probability density value corresponding to the chemical value of each sample and the classification error rate of each sample, and use the sample weight coefficient to weight the samples of the trained discriminant model to construct a nonlinear discriminant model;
[0074] In this embodiment, the chemical value of the sample (the sugar content value is used as an example in this embodiment) and the spectral data are used to establish the model, and the sugar content value is obtained by testing with other standard instruments and methods; the discriminant model uses a multi-layer BP neural network, which is usually composed of an input layer, one or more hidden layers and an output layer; in each layer of the neural network, the output of the previous layer of the neural network is multiplied by the current weight coefficient, and the output value is obtained through the activation function; the last layer of neurons obtains the predicted output value. That is, in this embodiment, since the nonlinear discriminant model is obtained by sample weighting, the nonlinear discriminant model is consistent with the discriminant model in terms of initial structure.
[0075] The weight coefficient of the classification discriminant model is not only used to calculate the output of the classification discriminant model, but also used to adjust the classification discriminant model to optimize performance. The weight coefficient can be set according to the probability density of the data or other relevant factors to reflect the influence of different data points on the overall data distribution.
[0076] When the discriminant model uses a two-layer BP neural network, that is, the nonlinear discriminant model is also a two-layer BP neural network, the weight coefficient determination process of the discriminant model is as follows: After dividing the training set and the first test set multiple times using the Monte Carlo method, the classification error rate of each sample in the training set is calculated. , construct sample weights based on error rate , the samples with larger classification error rate should play a smaller role in the establishment of the discriminant model to avoid causing greater errors; calculate the sample probability density corresponding to each sample in the sugar content value , construct sample weights based on sample probability density , weighted processing is performed on the sample data set. In order to make samples of different densities play an equally important role, the sample with a larger probability density should have a smaller weight, and vice versa. and As the weight coefficient of the first layer of BP neural network, and as a non-trainable parameter during the training process; the weight coefficient of the second layer of BP neural network is determined based on prior knowledge, and as a trainable parameter during the training process.
[0077] In addition, in this embodiment, the sample weights can also be separately As the weight coefficient of the first layer of BP neural network, the sample weight can also be used separately As the weight coefficients of the first layer of BP neural network, these two methods also improve the classification accuracy of the discriminant model.
[0078] In order to comprehensively evaluate the prediction and classification results of the discriminant model, the relationship between multiple indicators is considered, and accuracy, Matthews correlation coefficient, area under the curve, and f1 score are selected as evaluation indicators, such as Figure 5As shown, it can be clearly concluded that when the smooth data enhancement (data3) is used as the sample data set in this embodiment, each evaluation index is relatively excellent.
[0079] Step 4: Use the Monte Carlo method to randomly sample the sample data set and divide it into a calibration set and a second test set; use the calibration set as input, and the nonlinear discriminant model obtains the predicted output value based on the input sample data and the current weight coefficient. The loss value is calculated based on the predicted output value and the true value, and the loss value is used as the error value to pass back layer by layer to calculate the error signal of each layer of the neural network. According to the error signal and the gradient descent strategy, the weights and bias items of each layer of the neural network are adjusted.
[0080] Among them, the process of randomly sampling the sample data set using the Monte Carlo method to divide it into a calibration set and a second test set is consistent with the process of randomly sampling the sample data set using the Monte Carlo method to divide it into a training set and a first test set, which will not be repeated here.
[0081] It can be understood that both the first test set and the second test set are used to test the discriminant models at different training stages to ensure that the classification discriminant models at different training stages meet the required performance requirements.
[0082] Based on the sample weight coefficient, the discriminant model trained in step 2 is weighted to obtain a nonlinear discriminant model. The nonlinear discriminant model calculates the predicted output value based on the input sample and the initialized weight value, and adjusts the weight coefficient of the second layer BP neural network by comparing the loss value between the predicted output value and the true value. If the loss value is not within the preset range, the back propagation process is started, the error is transmitted back layer by layer, and distributed to each layer of the BP neural network, so as to obtain the error signal of each layer of the BP neural network. These error signals are used as the basis for correcting the weight coefficient of the second layer BP neural network.
[0083] Initialization of classification and discrimination model: set the number of BP neural networks in the input layer, hidden layer and output layer, initialize weight coefficients and bias items, set parameters such as learning rate and number of iterations.
[0084] Forward propagation: Calculate the output value of each layer of BP neural network based on the input sample and the current weight value. Specifically, for each layer of BP neural network, its input value (i.e., the weighted output of the previous layer of BP neural network) is multiplied by the weight, and the output value is obtained through the activation function.
[0085] Calculate loss: Compare the predicted output value of the BP neural network with the true value and calculate the loss value. The loss function usually uses the mean square error or other appropriate functions.
[0086] Determine whether the stopping condition is met: if the loss value reaches the preset range or the number of iterations reaches the upper limit, stop training; otherwise, enter the back propagation stage.
[0087] Back propagation: The error is propagated back layer by layer to calculate the error signal of each layer of BP neural network. According to the error signal and gradient descent strategy, the weights and bias items of each layer of neural network are adjusted.
[0088] Iterative update: Repeat the process of forward propagation, loss calculation, backpropagation, and weight update until the stopping condition is met.
[0089] Through the above steps, the multi-layer BP neural network can continuously learn and optimize its weights and structure to approach the desired output (actual value). In practical applications, it is also necessary to consider issues such as data preprocessing, network structure optimization, and activation function selection to achieve better performance.
[0090] Through steps one to three, the different measurement positions and uneven sample distribution in the prior art affect the accuracy and reliability of fruit sorting. The discriminant model construction method proposed in this embodiment is simple. The data fusion technology is used to mix the pre-processed spectral data with the spectral data after moving smoothing as a sample data set, which effectively uses the nonlinear modeling method for fruit sorting when the number of samples is limited. The Monte Carlo random sampling method and the reverse BP neural network are combined to construct the sample weight coefficient using the probability density and classification error rate of the sample data set to solve the imbalance problem of samples and improve the generalization ability of the training classification discriminant model. In fruit sorting, the influence of factors such as the spectral collection position and the uneven chemical value of the sample on the discriminant model is reduced.
[0091] In summary, fruit sorting is a key link in the agricultural product processing chain, and its technological innovation is particularly important. The traditional manual sorting method is not only inefficient and costly, but also difficult to ensure the accuracy and consistency of sorting. In recent years, near-infrared non-destructive testing technology has shown great potential in fruit quality detection and sorting. However, there are various influencing factors in online sorting of near-infrared, which leads to low sorting accuracy. Since the online sorting system is affected by factors such as the detection position of the fruit, the size of the spot, and the integration time, the quality of the sample data is not high. At the same time, due to the high cost of measuring chemical values, the number of sample data is also limited. In view of the actual situation that the number of online sorting samples is insufficient and the quality is not high, this embodiment proposes an online sorting method based on data enhancement. First, cluster analysis is performed on the pre-processed spectrum, and the optimal number of clusters is determined by combining the R² statistic and the elbow method. Then the pre-processed spectral data set and the spectral data after moving smoothing are mixed into a sample data set, and the Monte Carlo random sampling method is used to divide the training set and the first test set. The sample weight coefficient was further constructed by combining the probability density and classification error rate of the training set samples, and the discriminant model constructed by the calibration set was constructed by a two-layer neural network. The results of multiple runs showed that for the online sorting of navel oranges, the classification results based on the probability density and classification error rate weighting method were greatly improved, and the classification accuracy rate exceeded 92%.
[0092] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can make equivalent replacements or changes according to the technical scheme and inventive concept of the present invention within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.
Claims
1. A near-infrared nonlinear discrimination method for fruit sorting, characterized in that: Input the spectral data of the fruit into the trained classification and discrimination model to output the classification result of the fruit; The training process of the classification and discrimination model is as follows: Obtain and preprocess the spectral dataset of fruits, perform moving smoothing on the preprocessed spectral dataset, mix the preprocessed spectral dataset with the spectral dataset after moving smoothing as a sample dataset, determine the optimal clustering number of the sample dataset through the R² statistic, and set classification labels for the spectral data in the sample dataset based on the optimal clustering number; The sample data set is randomly sampled using the Monte Carlo method to divide it into a training set and a first test set, the discriminant model is trained based on the training set, the classification results of the random sampling are obtained, and the classification error rate of each sample is counted; The sample weight coefficient of the final discriminant model is constructed based on the probability density value corresponding to the chemical value of each sample and the classification error rate of each sample, and the sample weight coefficient is used to weight the samples of the trained discriminant model to construct a nonlinear discriminant model; The Monte Carlo method is used to randomly sample the sample data set and divide it into a calibration set and a second test set. The calibration set is used as input. The nonlinear discriminant model obtains the predicted output value based on the input sample data and the sample weight coefficient. The loss value is calculated based on the predicted output value and the true value to optimize the trainable parameters of the classification discriminant model.
2. The near-infrared nonlinear discrimination method for fruit sorting according to claim 1, characterized in that: In determining the optimal number of clusters for a sample data set using the R² statistic, specifically: Calculate the sum of squared errors of the sample data set under different clustering values K; Plot the sum of squared errors versus the number of clusters; Based on the fact that the curve graph tends to be flat, forming a shape similar to an "elbow", the number of clusters corresponding to the "elbow point" is taken as the optimal number of clusters for the sample data set.
3. The near-infrared nonlinear discrimination method for fruit sorting according to claim 1, characterized in that: The discriminant model uses a multi-layer BP neural network. In each layer of the neural network, the output of the previous layer of the neural network is multiplied by the current weight coefficient, and the output value is obtained through the activation function; the last layer of neurons obtains the predicted output value.
4. The near-infrared nonlinear discrimination method for fruit sorting according to claim 1, characterized in that: When the discriminant model adopts a two-layer BP neural network, the sample weight coefficient determination process of the nonlinear discriminant model is as follows: The Monte Carlo method is used to divide the training set and the test set multiple times, and the classification error rate of each sample in the training set is calculated. , construct sample weights based on error rate ; Calculate the sample probability density corresponding to each sample in each sample chemical value , construct sample weights based on sample probability density ; Weight the samples and As the weight coefficient of the first layer of BP neural network, and as a non-trainable parameter during the training process; The weight coefficient of the second layer BP neural network is determined based on prior knowledge and used as a trainable parameter during the training process.
5. The near-infrared nonlinear discrimination method for fruit sorting according to claim 1, characterized in that: The process of obtaining the preprocessed spectral dataset is as follows: Acquire spectral data to construct a dataset; The correlation coefficient and Manhattan distance between each pair of samples in the data set are calculated to remove abnormal spectral data and obtain the preprocessed spectral data set.
6. The near-infrared nonlinear discrimination method for fruit sorting according to claim 5, characterized in that: Manhattan distance for: ; in, for Middle Spectral data of wavelengths, for Middle Spectral data of wavelengths, and There are two samples corresponding to Spectral data at wavelength points.
7. The near-infrared nonlinear discrimination method for fruit sorting according to claim 1, characterized in that: The construction process of the training set and test set is as follows: Determine the ratio of training set and test set; Using the Monte Carlo method, a number between 0 and 1 is randomly generated for each spectral data in the sample data set through random sampling, and the spectral data less than the preset threshold is assigned to the test set; Assign spectral data greater than or equal to a preset threshold to a training set; Repeat the random sampling process multiple times, and recalculate the statistics of the training set and test set after each random sampling; The discriminant model is trained and evaluated based on the obtained multiple sets of training sets and test sets.
8. The near-infrared nonlinear discrimination method for fruit sorting according to claim 4, characterized in that: After calculating the loss value based on the predicted output value and the true value, the loss value is used as the error value to calculate the error signal of each layer of the neural network in the nonlinear discriminant model layer by layer. According to the error signal and the gradient descent strategy, the weights and bias items of each layer of the neural network are adjusted.
9. The near-infrared nonlinear discrimination method for fruit sorting according to claim 4, characterized in that: After calculating the loss value based on the predicted output value and the true value, determine whether the loss value reaches the preset range or whether the number of iterations reaches the upper limit. If so, stop training; otherwise, enter the back propagation stage: use the loss value as the error value to pass back layer by layer to calculate the error signal of each layer of the BP neural network in the classification discrimination model.
10. The near-infrared nonlinear discrimination method for fruit sorting according to claim 7, characterized in that: In calculating the loss value based on the predicted output value and the true value, the loss value is calculated by the mean square error function.
Citation Information
Patent Citations
Hyperspectral image based in-vivo tissue optical parameter measuring device and method
CN110946553A
Near-infrared spectrum rapid evaluation method for rice taste quality
CN111007040A