Apple sugar degree detection method and system based on neural network

By improving the genetic algorithm and data preprocessing and dimensionality reduction technology of BP neural network, a six-layer neural network model was built, which solved the problems of long training cycles and difficult parameter adjustment in apple saccharification detection, and achieved rapid convergence and high-precision detection effects.

CN120280023APending Publication Date: 2025-07-08JIANGNAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411041314.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2025-07-08

AI Technical Summary

Technical Problem

The existing BP neural network has a long training cycle and difficult parameter adjustment in apple candy detection, resulting in low detection accuracy and efficiency.

Method used

Genetic algorithm (GA) is used to optimize the network parameters of BP neural network, and improve the cross probability and variation probability of individuals through Sigmoid function. Combined with data preprocessing and dimensionality reduction technology, a six-layer neural network model is built, including a mapping layer, a feature extraction layer and a prediction layer, and trained using ELU function and MSE loss function.

Benefits of technology

The rapid convergence and short training cycle of the apple candy detection model are realized, which improves the detection accuracy and ease of adjustment of network parameters, and improves the overall detection performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120280023A_ABST
    Figure CN120280023A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of nondestructive testing of apple quality, and provides an apple sugar degree detection method and system based on a neural network, and the method comprises the following steps: collecting spectral data of a to-be-detected apple; preprocessing the spectral data to generate preprocessed data; carrying out dimension reduction on the preprocessed data to generate dimension-reduced data; inputting the dimension reduction data into a sugar degree detection model, and obtaining a sugar degree detection value of the to-be-detected apple according to an output result of the sugar degree detection model; the sugar degree detection model is modeled by adopting a BP neural network model; wherein network parameters of the BP neural network model are obtained by adopting a genetic algorithm GA; and the GA algorithm adopts a Sigmoid function to optimize the crossover probability and mutation probability of the individual to obtain an adaptive crossover probability and an adaptive mutation probability, and network parameters of the BP neural network model are updated based on the adaptive crossover probability and the adaptive mutation probability. According to the method, the faster convergence speed and the shorter training period of the sugar degree detection model can be realized, and the network parameters are easier to adjust.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of non-destructive detection of apple quality, and particularly to an apple sugar content detection method and system based on a neural network. Background Art

[0002] Apples are not only one of the fruits with the highest yields in the world, but also the fruit with the largest planting area and the highest yield in China. In the control of apple quality, the automated detection of internal quality is particularly crucial, which focuses on multiple indicators such as sugar content and acidity. Among them, sugar content, as a decisive factor in measuring the quality of apples, is of self-evident importance. Currently, the mainstream non-destructive detection technologies leading the trend of apple quality grading mainly include machine vision and spectral detection technologies.

[0003] Spectral detection technology is a non-destructive detection technology integrating computer technology, sensor technology, artificial intelligence, and data analysis. Spectral data is collected through hardware devices, and the collected data is transmitted back to the computer for analysis and processing to achieve further applications. In this process, the BP neural network plays an important role in the data processing and analysis of spectral detection technology, demonstrating powerful non-linear mapping ability and self-learning ability. However, the existing BP neural network has problems such as slow convergence speed, long training cycle, and difficult parameter adjustment. Summary of the Invention

[0004] Therefore, the technical problem to be solved by the present invention is to overcome the problems of long training cycle and difficult parameter adjustment of the neural network in the prior art, and provide an apple sugar content detection method and system based on a neural network, in which the convergence speed of the sugar content detection model is fast, the training cycle is short, and its network parameters are easy to adjust, so as to improve the detection accuracy and comprehensive performance of apple sugar content detection.

[0005] In a first aspect, to solve the above technical problem, the present invention provides an apple sugar content detection method based on a neural network, including collecting spectral data of the apple to be measured;

[0006] Preprocessing the spectral data to generate preprocessed data;

[0007] Reducing the dimension of the preprocessed data to generate dimension-reduced data;

[0008] Inputting the dimension-reduced data into a sugar content detection model, and obtaining a sugar content detection value of the apple to be measured according to the output result of the sugar content detection model;

[0009] The sugar content detection model is modeled using a BP neural network model;

[0010] Among them, the network parameters of the BP neural network model are obtained using a genetic algorithm GA;

[0011] The GA algorithm uses the Sigmoid function to optimize the crossover probability and mutation probability of individuals, obtains the adaptive crossover probability and adaptive mutation probability, and updates the network parameters of the BP neural network model based on the adaptive crossover probability and the adaptive mutation probability.

[0012] In one embodiment of the present invention, the preprocessed data is obtained using the SG smoothing method.

[0013] In one embodiment of the present invention, the dimensionality-reduced data is obtained by partial least squares (PLS).

[0014] In one embodiment of the present invention, the GA algorithm includes using the elite retention strategy to retain high-quality individuals with high individual fitness values.

[0015] In one embodiment of the present invention, the GA algorithm uses the Sigmoid function to optimize the crossover probability and mutation probability of individuals, including: performing a normalization mapping process on the population fitness values to generate the mapped individual fitness values; substituting the mapped individual fitness values into the Sigmoid function to obtain the adaptive crossover probability; taking the inverse operation of the mapped individual fitness values and then substituting them into the Sigmoid function to obtain the adaptive mutation probability.

[0016] In one embodiment of the present invention, the normalization mapping process includes:

[0017]

[0018] where f A ′ is the mapped individual fitness value, f A is the current individual fitness value, f min and f max respectively represent the minimum and maximum values of the population fitness values, C a is the mapping coefficient, C l is the lower limit of the mapping interval, and ε is an infinitesimal quantity.

[0019] In one embodiment of the present invention, the mapping coefficient takes a value of 10, the lower limit of the mapping interval takes a value of -5, and the mapped individual fitness value is within the interval [-5, 5].

[0020] In one embodiment of the present invention, the BP neural network model includes a neural network structure, and the neural network structure includes:

[0021] A mapping layer for mapping the dimensionality-reduced data into an internal representation form of a neural network to generate mapping data; wherein the mapping layer includes a Linear layer, a BN layer, and an activation function;

[0022] A feature extraction layer for extracting features of the mapping data to generate feature data; wherein the feature extraction layer includes a Linear layer, a BN layer, and an activation function;

[0023] A prediction layer for predicting the sugar content value of the apple to be measured according to the feature data; wherein the prediction layer includes a Linear layer, a BN layer, and an activation function.

[0024] In an embodiment of the present invention, the activation functions in the mapping layer and the feature extraction layer are both ELU functions, and the prediction layer includes an ELU function.

[0025] In a second aspect, to solve the above technical problems, the present invention provides an apple sugar content detection system based on a neural network, including:

[0026] A data acquisition module for acquiring spectral data of the apple to be measured;

[0027] A data preprocessing module for preprocessing the spectral data to generate preprocessed data;

[0028] A data dimensionality reduction module for performing dimensionality reduction processing on the preprocessed data to generate dimensionality-reduced data;

[0029] A sugar content detection module for detecting the sugar content value of the apple to be measured according to the dimensionality-reduced data;

[0030] Wherein, the sugar content detection module includes a sugar content detection model, the dimensionality-reduced data is input into the sugar content detection model, and according to the output result of the sugar content detection model, the sugar content detection value of the apple to be measured is obtained; the sugar content detection model is modeled by using a BP neural network model, the network parameters of the BP neural network model are obtained by using a genetic algorithm GA, the GA algorithm uses a Sigmoid function to optimize the crossover probability and mutation probability of individuals, obtains an adaptive crossover probability and an adaptive mutation probability, and updates the network parameters of the BP neural network model based on the adaptive crossover probability and the adaptive mutation probability.

[0031] The above technical solutions of the present invention have the following beneficial effects compared with the prior art:

[0032] The apple sugar content detection method and system based on neural network according to the present invention improve the crossover probability and mutation probability of individuals by using the Sigmoid function, and map the crossover probability and mutation probability of individuals with different fitness values to two extreme distributions. Specifically, in terms of the crossover probability, for high-quality individuals with high fitness values, their crossover probability is promoted to retain their high-quality genes; on the contrary, for low-quality individuals with low fitness values, their crossover probability is reduced to prevent them from destroying other individuals. In terms of the mutation probability, the mutation probability of high-quality individuals is reduced to prevent the degradation of high-quality genes; for low-quality individuals, their mutation probability is enhanced to improve their optimization ability. This method can not only achieve a faster convergence speed and a shorter training period for the sugar content detection model, but also make the adjustment of network parameters easier. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] In order to make the content of the present invention easier to be clearly understood, the following further details the present invention according to the specific embodiments of the present invention and in combination with the attached drawings, where

[0034] Figure 1 is a flowchart of the apple sugar content detection method based on neural network in the preferred embodiment of the present invention;

[0035] Figure 2 is the original apple spectrogram in the preferred embodiment of the present invention;

[0036] Figure 3 is the spectrogram after cropping the original apple spectrogram in the preferred embodiment of the present invention;

[0037] Figure 4 is the spectrogram preprocessed by the SG smoothing method in the preferred embodiment of the present invention;

[0038] Figure 5 is a block diagram of the neural network structure in the preferred embodiment of the present invention;

[0039] Figure 6 is a flowchart of neural network modeling optimized by the GA algorithm in the preferred embodiment of the present invention;

[0040] Figure 7 is a flowchart of the improved GA algorithm in the preferred embodiment of the present invention;

[0041] Figure 8 is a detection result diagram of the apple sugar content detection system based on neural network in the preferred embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0042] The following further illustrates the present invention in combination with the attached drawings and specific embodiments, so that those skilled in the art can better understand the present invention and be able to implement it, but the embodiments given are not intended to limit the present invention.

[0043] Example 1

[0044] Refer to Figure 1 As shown, a method for detecting the sugar content of apples based on a neural network provided by an embodiment of the present invention includes but is not limited to the following steps:

[0045] S110. Collect spectral data of the apple to be measured;

[0046] S120. Preprocess the spectral data to generate preprocessed data;

[0047] S130. Reduce the dimension of the preprocessed data to generate dimension-reduced data;

[0048] S140. Input the dimension-reduced data into the sugar content detection model, and obtain the sugar content detection value of the apple to be measured according to the output result of the sugar content detection model;

[0049] Among them, the sugar content detection model is modeled using a BP neural network model; the network parameters of the BP neural network model are obtained using a genetic algorithm GA; the GA algorithm uses a Sigmoid function to optimize the crossover probability and mutation probability of individuals, obtains an adaptive crossover probability and an adaptive mutation probability, and updates the network parameters of the BP neural network model based on the adaptive crossover probability and the adaptive mutation probability.

[0050] The performance of the BP neural network depends to a large extent on its initial network parameters, and the GA algorithm can automatically search for and optimize network parameters. By applying the network parameters optimized by the GA algorithm, the possibility of the neural network model converging to the global optimal solution is increased. To further optimize the effect of the GA algorithm in adjusting the BP neural network parameters, a Sigmoid function is used to improve the crossover probability and mutation probability of individuals, and the crossover probability and mutation probability of individuals with different fitness values are mapped to two extreme distributions. Specifically, in terms of the crossover probability, for high-quality individuals with high fitness values, their crossover probability is promoted to retain their high-quality genes; on the contrary, for low-quality individuals with low fitness values, their crossover probability is reduced to prevent them from destroying other individuals. At the same time, an elite retention strategy is used to retain high-quality individuals. In terms of the mutation probability, the mutation probability of high-quality individuals is reduced to prevent the degradation of high-quality genes; for low-quality individuals, their mutation probability is enhanced to improve their optimization ability. This design can not only achieve a faster convergence speed and a shorter training cycle of the sugar content detection model, but also make the adjustment of network parameters easier.

[0051] Specifically, in S110, a spectrometer is used to collect spectral data of the apple to be measured, and the spectrometer can be a Fourier transform near-infrared spectrometer, an acousto-optic tunable spectrometer, or a miniature fiber optic spectrometer. The spectral acquisition range can be set to 640nm - 1050nm to adapt to the analysis of the quality and characteristics of the apple to be measured. In this embodiment, refer toFigure 2 As shown in the figure, spectral data of 1104 apples were collected to construct a data set containing rich information. Due to the large number of samples, 50 representative spectral data were selected from the samples as display samples; of course, according to actual analysis needs, the sample data can be adjusted to balance the comprehensiveness of data display and the convenience of analysis and processing.

[0052] In view of the significant fluctuation of the spectral data above 950nm wavelength, in order to reduce the impact of this part on the test results, this part is cropped. The cropped spectral data is referenced to Figure 3 Specifically, in S120, the clipped spectral data is preprocessed using a data preprocessing method to generate preprocessed data. The data preprocessing method preferably uses the SG smoothing method, which has the advantages of retaining data features, processing non-uniformly spaced data, and retaining edge information. Therefore, in this embodiment, the spectral data processed by the SG smoothing method is clearer and smoother, and the preprocessed data can be referred to Figure 4 .

[0053] Since the preprocessed data generated by the SG smoothing method may still have problems such as high data dimension, feature redundancy or collinearity, these problems will affect the accuracy of model construction. Therefore, dimensionality reduction of the preprocessed data can effectively solve the above problems and improve the accuracy of the model.

[0054] Specifically, in S130, the preprocessed data is reduced in dimension using a data dimensionality reduction method. Dimensionality reduction processing can reduce the number of features in the data while retaining the key information in the data as much as possible, thereby simplifying the subsequent analysis and modeling process. Partial Least Squares (PLS) dimensionality reduction can comprehensively consider the relationship between its own variables and dependent variables, has a high collinearity data processing capability, and can improve the detection accuracy of the present invention. Therefore, in this embodiment, the dimensionality reduction data can be obtained by PLS, and preliminary modeling can be performed by multivariate linear regression (MLR) to determine the number of principal components. The specific steps include:

[0055] PLS reduces the dimension of the preprocessed data (represented as the independent variable matrix X) and maximizes the covariance between it and the apple sugar content data (represented as the dependent variable matrix Y). The reduced dimension data is also called the main factor matrix of PLS.

[0056] The dimension-reduced data is used as the input feature of MLR to build the MLR model;

[0057] The root mean square error (RMSE) evaluation index is selected to evaluate the performance of the MLR model, and the number of principal components when its RMSE curve decline tends to be gentle is selected as the subsequent dimensionality reduction feature number. Among them, the evaluation index can also be the calculated mean square error or R-squared value.

[0058] In view of the fact that the BP neural network can handle complex non-linear relationships and has the abilities of autonomous learning and generalization. Therefore, the BP neural network is selected to model the sugar content detection model.

[0059] Specifically, in S140, the sugar content detection model is modeled by the BP neural network model. In this embodiment, a six-layer neural network structure is built in total, and the built neural network structure can refer to Figure 5 . The network structure includes: a mapping layer for mapping the dimensionality-reduced data to the internal representation form of the neural network to generate mapped data; a feature extraction layer for extracting the features of the mapped data to generate feature data; and a prediction layer for predicting the sugar content value of the apple to be measured according to the feature data. Among them, the mapping layer, the feature extraction layer, and the prediction layer all include a Linear layer, a BN layer, and an activation function. In terms of the selection of the activation function, in view of the fact that the ELU function has significant advantages in alleviating gradient disappearance, accelerating convergence, improving generalization ability, smoothness, robustness to noise, and ease of implementation and calculation. The activation functions in the mapping layer, the feature extraction layer, and the prediction layer can all be selected as the ELU function. Specifically, in the process, after receiving the dimensionality-reduced data, the mapping layer generates mapped data and transmits it to the feature extraction layer. After receiving the mapped data, the feature extraction layer extracts its features to generate feature data and transmits it to the prediction layer. After receiving the feature data, the prediction layer outputs the prediction result and inputs the prediction result into the loss function for training, so as to plan the learning direction of the network. Due to the advantages of the MSE loss function such as ensuring the differentiability of gradient descent, ensuring the convexity property that the local optimal solution is the global optimal solution, and sensitivity to outliers, the loss function in this embodiment is preferably the MSE loss function.

[0060] Among them, in the training process of the BP neural network, the network parameters are obtained by the improved GA algorithm. The network parameters include network weights and thresholds, referring to Figure 6 . The improved GA algorithm includes optimizing the crossover probability and mutation probability of individuals by using the Sigmoid function, referring to Figure 7 .

[0061] The coefficient of determination R of the model is selected in the GA algorithm 2 as the fitness function, and the calculation formula for the fitness value of individual A is as follows:

[0062]

[0063] Among them, x i is the i-th spectral data, and y iis its actual measured value, is the average of the actual measured values of all samples, h A (x i ) is the neural network output of individual A, f A is the fitness value of individual A.

[0064] Since the Sigmoid function has a strong non-linear mapping ability in the interval [-5, 5], the fitness values of the population are normalized and mapped as follows:

[0065]

[0066] where f A ′ is the fitness value of individual A after mapping, f A is the current fitness value of individual A, f min and f max respectively represent the minimum and maximum fitness values in the current population, C a is the mapping coefficient, C l is the lower limit of the mapping interval, and ε is an infinitesimal quantity.

[0067] Select C a = 10, C1 = -5, the fitness values of the population can be mapped to the interval [-5, 5], that is, the fitness values of the individuals after mapping are in the interval [-5, 5], and at this time, the Sigmoid function will have a strong non-linear mapping ability.

[0068] Furthermore, the fitness value of the individual after mapping is substituted into the Sigmoid function to obtain the adaptive crossover probability, and the fitness value of the individual after mapping is inverted and then substituted into the Sigmoid function to obtain the adaptive mutation probability. The calculation formulas are as follows:

[0069]

[0070] f A ″ = -f A ′;

[0071]

[0072] where f A ′ is the fitness value of individual A after mapping, P c (f A ′) is the adaptive crossover probability, f A ″ is the result of inverting the fitness value of individual A after mapping, P m (f A ″) is the adaptive mutation probability.

[0073] Introducing the Sigmoid function into the GA algorithm can effectively solve the problems of long training cycle and difficult parameter adjustment of neural networks. In addition, it enhances the global search ability of the GA algorithm and avoids the problem of falling into local optimal solutions.

[0074] Figure 8 This is the detection result graph of the apple sugar content detection system based on neural network in the preferred embodiment of the present invention. Taking the apple sugar content values detected by the system and the actually measured apple sugar content values as the vertical and horizontal coordinates respectively, a scatter plot is drawn and the line y = x is drawn. Referring to Figure 8 ,the predicted points of the system are concentrated near the line y = x, indicating that the detected values of the system are relatively close to the actually measured values. In addition, the determination coefficient R 2 = 0.9320, which is 0.0081 higher than that of the traditional GA algorithm, indicating that the sugar content detection model in the preferred embodiment of the present invention has a good fitting effect and high detection accuracy.

[0075] Embodiment 2

[0076] The embodiment of the present invention also provides an apple sugar content detection system based on neural network, including: a data acquisition module for acquiring spectral data of the apple to be measured; a data preprocessing module for preprocessing the spectral data to generate preprocessed data; a data dimensionality reduction module for performing dimensionality reduction processing on the preprocessed data to generate dimensionality-reduced data; and a sugar content detection module for detecting the sugar content value of the apple to be measured according to the dimensionality-reduced data.

[0077] Among them, the sugar content detection module includes a sugar content detection model. The dimensionality-reduced data is input into the sugar content detection model, and according to the output result of the sugar content detection model, the sugar content detection value of the apple to be measured is obtained; the sugar content detection model is modeled by using a BP neural network model, and the network parameters of the BP neural network model are obtained by using a genetic algorithm GA. The GA algorithm uses the Sigmoid function to optimize the crossover probability and mutation probability of individuals to obtain an adaptive crossover probability and an adaptive mutation probability, and updates the network parameters of the BP neural network model based on the adaptive crossover probability and the adaptive mutation probability.

[0078] The performance of the BP neural network depends to a large extent on its initial network parameters, and the GA algorithm can automatically search for and optimize the network parameters. By applying the network parameters optimized by the GA algorithm, the possibility of the neural network model converging to the global optimal solution is increased. To further optimize the effect of the GA algorithm in adjusting the parameters of the BP neural network, the Sigmoid function is used to improve the crossover probability and mutation probability of individuals, and the crossover probability and mutation probability of individuals with different fitness values are mapped to two extreme distributions. Specifically, in terms of the crossover probability, for high-quality individuals with high fitness values, their crossover probability is promoted to retain their high-quality genes; on the contrary, for low-quality individuals with low fitness values, their crossover probability is reduced to prevent them from destroying other individuals. At the same time, the elite retention strategy is used to retain high-quality individuals. In terms of the mutation probability, the mutation probability of high-quality individuals is reduced to prevent the degradation of high-quality genes; for low-quality individuals, their mutation probability is increased to improve their optimization ability. This design can not only achieve a faster convergence speed and a shorter training cycle for the sugar content detection model, but also make the adjustment of network parameters easier.

[0079] Specifically, in the data acquisition module, a spectrometer is used to collect the spectral data of the apple to be measured. The spectrometer can be a Fourier transform near-infrared spectrometer, an acousto-optic tunable spectrometer, or a microfiber optic spectrometer. The spectral acquisition range can be set to 640nm - 1050nm to adapt to the analysis of the quality and characteristics of the apple to be measured. In this embodiment, referring to Figure 2 as shown, the spectral data of 1104 apples are collected to construct a dataset containing rich information. Since the number of samples is large, 50 representative spectral data are selected from the samples as display samples; of course, according to the actual analysis requirements, the sample data can be adjusted to balance the comprehensiveness of data display and the convenience of analysis and processing.

[0080] Specifically, in the data preprocessing module, considering that the spectral data shows significant fluctuations above the wavelength of 950nm, to reduce the influence of this part on the detection result, this part is cropped, and the cropped spectral data is referred to Figure 3 . The data preprocessing method is used to preprocess the cropped spectral data to generate preprocessed data. Among them, the data preprocessing method preferably adopts the SG smoothing method. The SG smoothing method has the advantages of retaining data features, processing non-uniformly spaced data, and retaining edge information. Therefore, in this embodiment, the spectral data processed by the SG smoothing method is clearer and smoother, and the preprocessed data can be referred to Figure 4 .

[0081] Since the preprocessed data generated by the SG smoothing method may still have problems such as high data dimension, feature redundancy or collinearity, these problems will affect the accuracy of model construction. Therefore, dimensionality reduction of the preprocessed data can effectively solve the above problems and improve the accuracy of the model.

[0082] Specifically, in the data dimension reduction module, the pre-processed data is reduced in dimension using a data dimension reduction method. Dimension reduction processing can reduce the number of features in the data while retaining the key information in the data as much as possible, thereby simplifying the subsequent analysis and modeling process. The partial least squares (PLS) dimension reduction method can comprehensively consider the relationship between its own variables and dependent variables, has a high collinearity data processing capability, and can improve the detection accuracy of the present invention. Therefore, in this embodiment, the dimension reduction data can be obtained by PLS, and preliminary modeling is performed by multivariate linear regression (MLR) to determine the number of principal components. The specific steps include:

[0083] PLS reduces the dimension of the preprocessed data (represented as the independent variable matrix X) and maximizes the covariance between it and the apple sugar content data (represented as the dependent variable matrix Y). The reduced dimension data is also called the main factor matrix of PLS.

[0084] The dimension-reduced data is used as the input feature of MLR to build the MLR model;

[0085] The root mean square error (RMSE) evaluation index is selected to evaluate the performance of the MLR model, and the number of principal components when the RMSE curve decreases gradually is selected as the feature number for subsequent dimensionality reduction. The evaluation index can also be the calculated mean square error or R square value.

[0086] Since BP neural network can deal with complex nonlinear relationships and has autonomous learning and generalization capabilities, BP neural network is selected to build the sugar content detection model.

[0087] Specifically, in the sugar content detection module, the sugar content detection model is modeled by a BP neural network model. In this embodiment, a six-layer neural network structure is constructed. The constructed neural network structure can be referred to Figure 5. The network structure includes: a mapping layer for mapping the dimensionality-reduced data to the internal representation of the neural network to generate mapped data; a feature extraction layer for extracting the features of the mapped data to generate feature data; and a prediction layer for predicting the sugar content value of the apple to be measured based on the feature data. Among them, the mapping layer, the feature extraction layer, and the prediction layer all include a Linear layer, a BN layer, and an activation function. In terms of the selection of the activation function, considering that the ELU function has significant advantages in alleviating gradient disappearance, accelerating convergence, improving generalization ability, smoothness, robustness to noise, and ease of implementation and calculation, the activation functions in the mapping layer, the feature extraction layer, and the prediction layer can all be selected as the ELU function. Specifically, in the process, the mapping layer receives the dimensionality-reduced data, generates mapped data and transmits it to the feature extraction layer. The feature extraction layer receives the mapped data, extracts its features to generate feature data and transmits it to the prediction layer. The prediction layer receives the feature data, outputs the prediction result, and inputs the prediction result into the loss function for training, so as to plan the learning direction of the network. Since the MSE loss function has advantages such as ensuring the differentiability of gradient descent, the convexity property of ensuring that the local optimal solution is the global optimal solution, and sensitivity to outliers, the loss function in this embodiment is preferably the MSE loss function.

[0088] Among them, in the training process of the BP neural network, the network parameters are obtained by an improved GA algorithm. The network parameters include network weights and thresholds. Refer to Figure 6 . The improved GA algorithm includes optimizing the crossover probability and mutation probability of individuals using the Sigmoid function. Refer to Figure 7 .

[0089] The coefficient of determination R of the selected model in the GA algorithm 2 is used as the fitness function. Then, the calculation formula for the fitness value of individual A is as follows:

[0090]

[0091] Among them, x i is the i-th spectral data, y i is its actual measured value, is the average value of the actual measured values of all samples, h A (x i ) is the output of the neural network of individual A, and f A is the fitness value of individual A.

[0092] Since the Sigmoid function has a strong non-linear mapping ability in the [-5, 5] interval, the population fitness value is normalized and mapped. The normalization mapping method is as follows:

[0093]

[0094] Among them, fA ' is the fitness value of individual A after mapping, f A is the current fitness value of individual A, f min and f max respectively represent the minimum and maximum fitness values in the current population, C a is the mapping coefficient, C l is the lower limit of the mapping interval, and ε is an infinitesimal quantity.

[0095] Select C a = 10, C1 = -5, the population fitness value can be mapped to the interval [-5, 5], that is, the fitness value of the individual after mapping is within the interval [-5, 5]. At this time, using the Sigmoid function will have a strong non-linear mapping ability.

[0096] Furthermore, substitute the fitness value of the individual after mapping into the Sigmoid function to obtain the adaptive crossover probability, and substitute the result of taking the negative of the fitness value of the individual after mapping into the Sigmoid function to obtain the adaptive mutation probability. The calculation formula is as follows:

[0097]

[0098] f A ″ = -f A ′;

[0099]

[0100] Among them, f A ′ is the fitness value of individual A after mapping, P c (f A ′) is the adaptive crossover probability, f A ″ is the result of taking the negative of the fitness value of individual A after mapping, P m (f A ″) is the adaptive mutation probability.

[0101] Introducing the Sigmoid function in the GA algorithm can effectively solve the problems of long neural network training cycle and difficult parameter adjustment. In addition, it also enhances the global search ability of the GA algorithm and avoids the problem of falling into local optimal solutions.

[0102] Figure 8 This is the detection result graph of the apple sugar content detection system based on the neural network in the preferred embodiment of the present invention. The apple sugar content values detected by the system and the actual measured apple sugar content values are used as the vertical and horizontal coordinates respectively, and a scatter plot is drawn and the line y = x is drawn. Refer to Figure 8 , the system prediction points are concentrated near the line y = x, indicating that the system detection value is relatively close to the actual measured value. In addition, the determination coefficient R 2= 0.9320, which is 0.0081 higher than that of the traditional GA algorithm, indicating that the fitting effect of the sugar content detection model in the preferred embodiment of the present invention is better and the detection accuracy is higher.

[0103] Obviously, the above embodiments are merely examples given for clear illustration and are not limitations on the implementation manners. For those of ordinary skill in the art, other different forms of changes or variations can be made based on the above description. It is not necessary and impossible to enumerate all the implementation manners here. And the obvious changes or variations derived therefrom are still within the protection scope of the present invention.

Claims

1. An apple sugar content detection method based on a neural network, characterized in that, Including: Collecting spectral data of the apple to be measured; Preprocessing the spectral data to generate preprocessed data; Reducing the dimension of the preprocessed data to generate dimension-reduced data; Inputting the dimension-reduced data into the sugar content detection model, and obtaining the sugar content detection value of the apple to be measured according to the output result of the sugar content detection model; The sugar content detection model is modeled using a BP neural network model; Among them, the network parameters of the BP neural network model are obtained using a genetic algorithm GA; The GA algorithm uses the Sigmoid function to optimize the crossover probability and mutation probability of individuals, obtains the adaptive crossover probability and adaptive mutation probability, and updates the network parameters of the BP neural network model based on the adaptive crossover probability and the adaptive mutation probability.

2. The apple sugar content detection method based on neural network according to claim 1, characterized in that, The preprocessed data is obtained using the SG smoothing method.

3. The apple sugar content detection method based on a neural network according to claim 1, characterized in that, The dimension-reduced data is obtained by partial least squares (PLS).

4. A method for detecting the sugar content of apples based on a neural network according to claim 1, characterized in that , The GA algorithm includes using the elitist retention strategy to retain high-quality individuals with high individual fitness values.

5. A method for detecting the sugar content of apples based on a neural network according to claim 1, characterized in that, The GA algorithm uses the Sigmoid function to optimize the crossover probability and mutation probability of individuals, including: Performing normalization mapping processing on the population fitness value to generate the mapped individual fitness value; Substituting the mapped individual fitness value into the Sigmoid function to obtain the adaptive crossover probability; Taking the inverse operation on the mapped individual fitness value and then substituting it into the Sigmoid function to obtain the adaptive mutation probability.

6. The method for detecting the sugar content of apples based on a neural network according to claim 5, wherein , The normalization mapping processing includes: Among them, f A ' is the individual fitness value after the mapping, and f A is the current individual fitness value. f min and f max respectively represent the minimum value and the maximum value of the population fitness value. C a is the mapping coefficient, C l is the lower limit of the mapping interval, and ε is an infinitesimal quantity.

7. The method for detecting the sugar content of apples based on a neural network according to claim 6, characterized in that , The mapping coefficient takes a value of 10, the lower limit of the mapping interval takes a value of -5, and the mapped individual fitness value is within the interval [-5, 5].

8. A method for detecting the sugar content of apples based on a neural network according to claim 1, characterized in that, The BP neural network model includes a neural network structure, and the neural network structure includes: A mapping layer, which is used to map the dimension-reduced data into the internal representation form of the neural network to generate mapped data; among them, the mapping layer includes a Linear linear layer, a BN layer, and an activation function; A feature extraction layer, which is used to extract the features of the mapped data to generate feature data; among them, the feature extraction layer includes a Linear linear layer, a BN layer, and an activation function; A prediction layer, which is used to predict the sugar content value of the apple to be measured according to the feature data; among them, the prediction layer includes a Linear linear layer, a BN layer, and an activation function.

9. A method for detecting the sugar content of apples based on a neural network according to claim 8, characterized in that, The activation functions in the mapping layer and the feature extraction layer are both ELU functions, and the prediction layer includes an ELU function.

10. An apple sugar content detection system based on a neural network, characterized in that, Including: A data acquisition module, which is used to collect spectral data of the apple to be measured; A data preprocessing module, which is used to preprocess the spectral data to generate preprocessed data; A data dimension reduction module, which is used to perform dimension reduction processing on the preprocessed data to generate dimension-reduced data; A sugar content detection module, which is used to detect the sugar content value of the apple to be measured according to the dimension-reduced data; Among them, the sugar content detection module includes a sugar content detection model. The dimensionality-reduced data is input into the sugar content detection model, and according to the output result of the sugar content detection model, the sugar content detection value of the apple to be measured is obtained. The sugar content detection model is modeled using a BP neural network model. The network parameters of the BP neural network model are obtained using a genetic algorithm GA. The GA algorithm uses the Sigmoid function to optimize the crossover probability and mutation probability of individuals, obtaining an adaptive crossover probability and an adaptive mutation probability, and updating the network parameters of the BP neural network model based on the adaptive crossover probability and the adaptive mutation probability.