Litchi sugar detection method based on machine learning
By using a rotating roller and a multi-angle camera to obtain the appearance information of lychee, combined with weight sensors and lossless near-infrared spectral imaging technology, the problems of detection error and redundant information in the prior art are solved, and the sugar detection effect with high accuracy and interpretability is achieved.
Patent Information
- Application Number
- CN202510275996.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-10
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2045-03-10
AI Technical Summary
The existing technology has errors in lychee sugar detection. It is affected by factors such as light, occlusion, and angle. Near-infrared detection may be affected by factors such as lychee skin thickness and moisture content. Traditional machine learning models cannot explain the impact of spectral characteristics on sugar prediction.
The rotating roller and multi-angle camera are used to capture the appearance information of lychees, and the weight sensor is used to obtain physical information to reduce errors. Using lossless near-infrared spectral imaging technology, important wavelengths are screened, redundant information is removed, and key features are extracted. Use interpretable artificial intelligence technology to optimize model design, reduce data dimensions, and improve computing efficiency.
It improves the accuracy of lychee sugar detection, reduces the computing resources and time consumption of model training, and enhances the interpretability of detection.
Smart Images

Figure CN119780031A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of sugar content detection, and specifically to a litchi sugar content detection method based on machine learning. Background Art
[0002] As an important economic crop, the quality of litchi is closely related to its sugar content. The litchi sugar detection method based on machine learning refers to a method for detecting litchi sugar using computer vision.
[0003] Among the existing approximate solutions, for example, CN113192090B is a method and device for sorting peaches based on machine learning. This solution aims at the technical problem that the accuracy and efficiency of the existing peach sorting method are low. By collecting peach images, the size and shape of the peaches are classified. Through a near-infrared sensor, a relationship model between the size of the light signal and the sugar content is established by using near-infrared diffuse reflection technology to predict the sugar content of the peaches. In combination with the analysis results of size, shape, color and sugar content, the peach sorting is controlled, and non-contact detection of peaches is achieved, which effectively reduces the loss in the sorting process. However, firstly, the prior art uses a target detection algorithm for size and color, and the image is usually affected by factors such as illumination, occlusion, and angle, and usually there is a side of the peach close to the conveyor belt that cannot be collected by the camera, resulting in detection errors. Secondly, near-infrared detection may be affected by factors such as peach skin thickness and water content, resulting in sugar content measurement deviation. Only relying on 820nm wavelength for detection may not be enough to distinguish the sugar content changes of peaches of different varieties.
[0004] In addition, for example, CN112697984B discloses a fruit defect nondestructive detection method and a fruit grading method based on a neural network. This solution aims to solve the technical problem that the existing technology is not accurate enough in fruit defect detection and grading. By integrating the appearance image, slice image, slice chemical detection data and defect information, corresponding to the X-ray image, training the fruit defect nondestructive detection model, and outputting the grading result, the technical effect of accurately detecting internal and external defects of the fruit and comprehensively evaluating the fruit quality is achieved. However, although X-ray imaging has strong penetration, it will cause certain radiation damage to the fruit, affecting its quality and safety. In addition, X-ray imaging equipment is expensive and has high maintenance costs, which limits the popularity of X-ray imaging equipment in production lines. In addition, multi-source and multi-scale data have redundant information, which increases the burden of data processing and model training. Traditional machine learning is a black box model and cannot directly explain which spectral features affect the sugar content prediction. Summary of the invention
[0005] In view of the above situation, in order to overcome the defects of the prior art, the present invention provides a lychee sugar detection method based on machine learning. In view of the existing problems in the prior art, the target detection algorithm is used for size and color. The image is usually affected by factors such as lighting, occlusion, and angle, and usually the side of the lychee close to the conveyor belt cannot be collected by the camera, resulting in detection errors. Secondly, near-infrared detection may be affected by factors such as the thickness of the lychee skin and the moisture content, resulting in sugar content measurement deviations. Only relying on the 820nm wavelength for detection may not be sufficient to distinguish the sugar content changes of different varieties of lychees. This solution first uses a rotating drum to allow the lychees to roll automatically before passing through the detection area, and installs cameras at different angles on the front and rear sections of the rotating drum and on the left and right sides of the conveyor belt to capture the appearance information of the lychees from multiple angles, reduce the errors caused by single-angle shooting, and use a weight sensor to obtain more accurate information of the lychees. Multi-physical information improves the accuracy of sugar measurement; in view of the existing technology, although X-ray imaging has strong penetration, it will cause certain radiation damage to fruits, affecting their quality and safety, and X-ray imaging equipment is expensive and has high maintenance costs, which limits the popularity of X-ray imaging equipment on production lines. In addition, multi-source and multi-scale data have redundant information, which increases the burden of data processing and model training. Traditional machine learning is a black box model and cannot directly explain which spectral features affect the technical problem of sugar content prediction. This solution adopts non-destructive, fast and low-cost near-infrared spectral imaging technology, and selects near-infrared wavelengths according to their importance to sugar detection results, removes redundant information, and extracts features that contribute to detection and grading, which greatly reduces the computing resources and time consumption of model training. It uses explainable artificial intelligence technology to optimize regression model design, reduce data dimensions, and improve computing efficiency.
[0006] The technical solution adopted by the present invention is as follows: The present invention provides a method for detecting sugar content in litchi based on machine learning, the method comprising the following steps:
[0007] Step S1: complete information collection, specifically, using a rotating drum, fixing the rotating drum on the top of the conveyor belt for conveying litchi, the rotating drum rolls and flips the litchi, installing cameras at different angles on the front and rear sections of the rotating drum and on the left and right sides of the conveyor belt to capture the shape of the litchi, collect the original image of the litchi, and use a weight sensor to obtain the weight data of the litchi;
[0008] Step S2: Prior knowledge learning is used to capture the spatial structure of litchi morphology. Specifically, a litchi morphology dataset is collected, a litchi model is predefined, and the key points of the litchi model are determined. The prior knowledge of the litchi model is extracted from the litchi morphology dataset through a graph convolutional network. The prior knowledge specifically refers to the litchi morphological features. The formula for extracting the prior knowledge of the key points of the litchi model is as follows: ;
[0009] In the formula, Represents the prior knowledge extracted by the graph convolutional network, represents the key points of the Litchi model, represents the normalized graph Laplacian matrix, Represents the use of Chebyshev polynomials acting on As a result, represents the order of graph convolution, represents the order subscript index, Represents the learnable parameters of the graph convolutional network;
[0010] Step S3: feature fusion, used to increase the correlation between prior knowledge and image features, specifically, extracting image features, using a multi-head cross attention mechanism to fuse prior knowledge with image features, and compensating for data loss in litchi occluded areas;
[0011] Step S4: predicting the shape of the obscured area of the litchi according to prior knowledge, image features and the litchi weight data, and updating the litchi model;
[0012] Step S5: using a Fourier transform near-infrared spectrometer to scan and record the reflectance spectrum of the litchi, and using a white reference plate to perform spectrum correction during scanning;
[0013] Step S6: preprocessing, specifically, correcting scattering and baseline drift to obtain spectral feature data;
[0014] Step S7: Interpretability analysis is used to improve the interpretability of sugar detection. A regression model is constructed. Interpretable artificial intelligence technology is used to analyze the wavelength range of the Fourier transform near-infrared spectrometer used for acquisition. The importance of wavelength to sugar detection results is calculated to determine the wavelength range that plays a key role in sugar detection. According to the wavelength range, spectral feature data is screened. The formula used is as follows: ;
[0015] In the formula, Indicates wavelength Importance of sugar test results, represents the total wavelength set of the spectral feature data, express A subset of Indicates that the regression model is only used Sugar content prediction value when making predictions, Indicated in On the basis of , the sugar content prediction value after retraining the regression model, Indicated in ,and ,and Under the condition of traversing wavelength Find the cumulative sum, Indicates the number of elements in a collection. represents factorial;
[0016] Step S8: Model output, specifically, the regression model analyzes the screened spectral feature data and the updated litchi model, and outputs a predicted litchi sugar value.
[0017] Furthermore, in step S3, the feature fusion specifically includes the following steps:
[0018] Step S31: image feature extraction, for extracting features of litchi, specifically, using a feature extractor to obtain image features from the original litchi image, performing point-by-point convolution processing on the image features and the prior knowledge, respectively, to obtain query vectors, key vectors, and value vectors of the image features and the prior knowledge;
[0019] Calculate the similarity between the query vector and the key vector of the image feature, use the similarity between the query vector and the key vector of the image feature as the attention weight A, where the attention weight A represents the degree of attention of each pixel in the image feature to each pixel in the prior knowledge, and add the result of the weighted summation of the attention weight A and the value vector of the image feature to the prior knowledge;
[0020] Step S32: Image occlusion compensation is used to compensate for the features of the occluded area of the litchi, calculate the similarity between the query vector and the key vector of the prior knowledge, and use the similarity between the query vector and the key vector of the prior knowledge as the attention weight B. The attention weight B represents the degree of attention of each pixel in the prior knowledge to each pixel in the image feature, and the result of the weighted summation of the attention weight B and the value vector of the prior knowledge is added to the image feature.
[0021] Further, in step S6, the preprocessing specifically includes the following steps:
[0022] Step S61: Pseudo-absorption spectrum conversion, converting the reflection spectrum into a pseudo-absorption spectrum, the formula used is as follows: ;
[0023] In the formula, Represents pseudo-absorption spectrum, which is used to represent the wavelength The pseudo-absorption value at Indicated in wavelength The reflectivity value at is a constant, ;
[0024] Step S62: standardizing the normal variable, specifically, calculating the mean value and standard deviation of the pseudo absorption spectrum, subtracting the mean value from the value of each point of the pseudo absorption spectrum, and then dividing it by the standard deviation to obtain a standard normal transformation spectrum;
[0025] Step S63: highlighting the local changes of the spectrum, specifically, using a first-order SG filter to process the pseudo-absorption spectrum, fitting a polynomial through a sliding window, and calculating the first-order derivative;
[0026] Step S64: continuously removing the conversion, which is used to highlight the shape and position of the absorption peak in the pseudo absorption spectrum and remove the baseline drift, specifically, defining a window width greater than or equal to the absorption peak in the pseudo absorption spectrum, for any point in the pseudo absorption spectrum, calculating the average value of the neighboring points within half of the window width around the point, using the calculated average value as the continuous spectrum value of the point, obtaining the continuous spectrum of the pseudo absorption spectrum, dividing the pseudo absorption spectrum by the continuous spectrum, and obtaining the preprocessed spectrum;
[0027] Step S65: identifying the position of the absorption peak in the pseudo absorption spectrum, specifically, using a second-order SG filter to process the preprocessed spectrum to obtain a second-order derivative of the preprocessed spectrum;
[0028] Step S66: Record the reflection spectrum, pseudo-absorption spectrum, standard normal transformation spectrum, first-order derivative, pre-processed spectrum and second-order derivative as spectral feature data.
[0029] The present invention provides a method for detecting sugar content in litchi based on machine learning. The beneficial effects achieved by the present invention using the above scheme are as follows:
[0030] (1) In view of the technical problems that the existing technology uses target detection algorithms to detect size and color, images are usually affected by factors such as lighting, occlusion, and angle, and the side of the litchi close to the conveyor belt cannot be captured by the camera, resulting in detection errors. Secondly, near-infrared detection may be affected by factors such as litchi skin thickness and moisture content, resulting in sugar content measurement deviations. Detection based only on 820nm wavelength may not be sufficient to distinguish the sugar content changes of different varieties of litchi. This solution first uses a rotating drum to allow litchi to roll automatically before passing through the detection area, and installs cameras at different angles on the front and rear sections of the rotating drum and on the left and right sides of the conveyor belt to capture the appearance information of litchi from multiple angles, reducing the errors caused by single-angle shooting. A weight sensor is used to obtain more physical information of the litchi and improve the accuracy of sugar measurement.
[0031] (2) In view of the existing technology, although X-ray imaging has strong penetration, it will cause certain radiation damage to fruits, affecting their quality and safety. In addition, X-ray imaging equipment is expensive and has high maintenance costs, which limits the popularity of X-ray imaging equipment on production lines. In addition, multi-source and multi-scale data contain redundant information, which increases the burden of data processing and model training. Traditional machine learning is a black box model and cannot directly explain which spectral features affect the prediction of sugar content. This scheme adopts non-destructive, fast and low-cost near-infrared spectral imaging technology. It selects near-infrared wavelengths according to their importance to sugar detection results, removes redundant information, and extracts features that contribute to detection and grading, which greatly reduces the computing resources and time consumption of model training. It uses explainable artificial intelligence technology to optimize the regression model design, reduce data dimensions, and improve computing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 A schematic diagram of a process for detecting sugar content in litchi based on machine learning provided by the present invention;
[0033] Figure 2 is a schematic diagram of step S3;
[0034] Figure 3 is a schematic diagram of step S6.
[0035] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention. DETAILED DESCRIPTION
[0036] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments; based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0037] In the description of the present invention, it should be understood that terms such as “upper”, “lower”, “front”, “back”, “left”, “right”, “top”, “bottom”, “inside” and “outside” indicating directions or positional relationships are based on the directions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific direction, be constructed and operated in a specific direction, and therefore should not be understood as limiting the present invention.
[0038] Example 1, see Figures 1 to 3 The present invention provides a method for detecting sugar content in litchi based on machine learning, the method comprising the following steps:
[0039] Step S1: complete information collection, specifically, using a rotating drum, fixing the rotating drum on the top of the conveyor belt for conveying litchi, the rotating drum rolls and flips the litchi, installing cameras at different angles on the front and rear sections of the rotating drum and on the left and right sides of the conveyor belt to capture the shape of the litchi, collect the original image of the litchi, and use a weight sensor to obtain the weight data of the litchi;
[0040] Step S2: Prior knowledge learning is used to capture the spatial structure of litchi morphology. Specifically, a litchi morphology dataset is collected, a litchi model is predefined, and the key points of the litchi model are determined. The prior knowledge of the litchi model is extracted from the litchi morphology dataset through a graph convolutional network. The prior knowledge specifically refers to the litchi morphological features. The formula for extracting the prior knowledge of the key points of the litchi model is as follows: ;
[0041] In the formula, Represents the prior knowledge extracted by the graph convolutional network, represents the key points of the Litchi model, represents the normalized graph Laplacian matrix, Represents the use of Chebyshev polynomials acting on As a result, represents the order of graph convolution, represents the order subscript index, Represents the learnable parameters of the graph convolutional network;
[0042] Step S3: feature fusion, used to increase the correlation between prior knowledge and image features, specifically, extracting image features, using a multi-head cross attention mechanism to fuse prior knowledge with image features, and compensating for data loss in litchi occluded areas;
[0043] Step S4: predicting the shape of the obscured area of the litchi according to prior knowledge, image features and the litchi weight data, and updating the litchi model;
[0044] Step S5: using a Fourier transform near-infrared spectrometer to scan and record the reflectance spectrum of the litchi, and using a white reference plate to perform spectrum correction during scanning;
[0045] Step S6: preprocessing, specifically, correcting scattering and baseline drift to obtain spectral feature data;
[0046] Step S7: Interpretability analysis is used to improve the interpretability of sugar detection. A regression model is constructed. Interpretable artificial intelligence technology is used to analyze the wavelength range of the Fourier transform near-infrared spectrometer used for acquisition. The importance of wavelength to sugar detection results is calculated to determine the wavelength range that plays a key role in sugar detection. According to the wavelength range, spectral feature data is screened. The formula used is as follows: ;
[0047] In the formula, Indicates wavelength Importance of sugar test results, represents the total wavelength set of the spectral feature data, express A subset of Indicates that the regression model is only used Sugar content prediction value when making predictions, Indicated in On the basis of , the sugar content prediction value after retraining the regression model, Indicated in ,and ,and Under the condition of traversing wavelength Find the cumulative sum, Indicates the number of elements in a collection. represents factorial;
[0048] Step S8: Model output, specifically, the regression model analyzes the screened spectral feature data and the updated litchi model, and outputs a predicted litchi sugar value.
[0049] Example 2, see Figure 1 and Figure 2 This embodiment is based on the above embodiment. In step S3, the feature fusion specifically includes the following steps:
[0050] Step S31: image feature extraction, for extracting features of litchi, specifically, using a feature extractor to obtain image features from the original litchi image, performing point-by-point convolution processing on the image features and the prior knowledge, respectively, to obtain query vectors, key vectors, and value vectors of the image features and the prior knowledge;
[0051] Calculate the similarity between the query vector and the key vector of the image feature, use the similarity between the query vector and the key vector of the image feature as the attention weight A, where the attention weight A represents the degree of attention of each pixel in the image feature to each pixel in the prior knowledge, and add the result of the weighted summation of the attention weight A and the value vector of the image feature to the prior knowledge;
[0052] Step S32: Image occlusion compensation is used to compensate for the features of the occluded area of the litchi, calculate the similarity between the query vector and the key vector of the prior knowledge, and use the similarity between the query vector and the key vector of the prior knowledge as the attention weight B. The attention weight B represents the degree of attention of each pixel in the prior knowledge to each pixel in the image feature, and the result of the weighted summation of the attention weight B and the value vector of the prior knowledge is added to the image feature.
[0053] Example 3, see Figures 1 to 3 This embodiment is based on the above embodiment. In step S6, the preprocessing specifically includes the following steps:
[0054] Step S61: Pseudo-absorption spectrum conversion, converting the reflection spectrum into a pseudo-absorption spectrum, the formula used is as follows: ;
[0055] In the formula, Represents pseudo-absorption spectrum, which is used to represent the wavelength The pseudo-absorption value at Indicated in wavelength The reflectivity value at is a constant, ;
[0056] Step S62: standardizing the normal variable, specifically, calculating the mean value and standard deviation of the pseudo absorption spectrum, subtracting the mean value from the value of each point of the pseudo absorption spectrum, and then dividing it by the standard deviation to obtain a standard normal transformation spectrum;
[0057] Step S63: highlighting the local changes of the spectrum, specifically, using a first-order SG filter to process the pseudo-absorption spectrum, fitting a polynomial through a sliding window, and calculating the first-order derivative;
[0058] Step S64: continuously removing the conversion, which is used to highlight the shape and position of the absorption peak in the pseudo absorption spectrum and remove the baseline drift, specifically, defining a window width greater than or equal to the absorption peak in the pseudo absorption spectrum, for any point in the pseudo absorption spectrum, calculating the average value of the neighboring points within half of the window width around the point, using the calculated average value as the continuous spectrum value of the point, obtaining the continuous spectrum of the pseudo absorption spectrum, dividing the pseudo absorption spectrum by the continuous spectrum, and obtaining the preprocessed spectrum;
[0059] Step S65: identifying the position of the absorption peak in the pseudo absorption spectrum, specifically, using a second-order SG filter to process the preprocessed spectrum to obtain a second-order derivative of the preprocessed spectrum;
[0060] Step S66: Record the reflection spectrum, pseudo-absorption spectrum, standard normal transformation spectrum, first-order derivative, pre-processed spectrum and second-order derivative as spectral feature data.
[0061] Example 4, see Figures 1 to 3 This embodiment is based on the above embodiment. In step S7, the regression model uses a nonlinear regression model based on a decision tree.
[0062] Example 5, see Figures 1 to 3 This embodiment is based on the above embodiment. This embodiment is different from the above embodiment only in the selection of the regression model. The regression model uses the partial least squares regression model.
[0063] Example 6, see Figures 1 to 3 This embodiment is based on the above embodiment. In step S7, the wavelength range that plays a key role in sugar detection is determined. The key wavelengths of the spectral feature data retained after screening are 570-630nm, 670-730nm, 920-960nm, 1150-1200nm and 2470-2500nm.
[0064] Embodiment 7, see Figures 1 to 3 This embodiment is based on the above embodiment. In step S7, the Represents the total wavelength set of the spectral feature data, specifically, F={350, 351, ..., 2500}.
[0065] Embodiment 8, see Figures 1 to 3 This embodiment is based on the above embodiment. In step S7, the express A subset of , specifically, S={400,600,900}.
[0066] Embodiment 9, see Figures 1 to 3 This embodiment is based on the above embodiment. In step S5, the Fourier transform near-infrared spectrometer collects the reflectance spectrum of litchi in the wavelength range of 350-2500nm.
[0067] Embodiment 10, see Figures 1 to 3 This embodiment is based on the above embodiment. In step S7, the interpretability analysis is specifically to analyze the wavelength range of the Fourier transform near-infrared spectrometer used for acquisition, and to determine the wavelength range that plays a key role in sugar detection by calculating the importance of the wavelength to the sugar detection result. The experimental table is shown below:
[0068] According to the experimental table, the key wavelengths were screened, and the wavelength ranges that played a key role in sugar detection were screened out by calculating the importance of each wavelength. It was concluded that the key wavelength ranges were: 570–630nm, 670–730nm, 920–960nm, 1150–1200nm and 2470–2500nm; the most important wavelengths were: 1600-1700nm and 1800-1900nm (high contribution); low contribution wavelengths were: 350-570nm, 850-900nm, 900-920nm, 1100-1150nm, 1300-1400nm and 2100-2200nm (mainly affecting moisture, and not significantly affecting sugar detection);
[0069] Ultimately, using only the included key wavelengths of 570–630nm, 670–730nm, 920–960nm, 1150–1200nm, and 2470–2500nm for sugar detection can reduce the computational burden and improve prediction accuracy.
[0070] Example 11, see Figures 1 to 3 This embodiment is based on the fourth embodiment. In step S8, the screened spectral feature data and the updated litchi model are used as a data set, and the data set is divided into a training set and a test set. The training set accounts for 70% of the data set, and the test set accounts for 30% of the data set. The training set is used as the input data of the nonlinear regression model based on the decision tree. The nonlinear regression model based on the decision tree is abbreviated as a decision tree regression model. The parameters of the decision tree regression model are initialized, and the parameters include the number of trees, the maximum depth, the minimum number of samples required for node splitting, the minimum number of samples required for leaf nodes, the maximum number of leaf nodes, the minimum impurity reduction required for node splitting, and the splitting strategy parameters. The root mean square error is used as the loss function of the litchi sugar prediction problem. The random forest algorithm is used to train the decision tree regression model, minimize the loss function, and update the decision tree regression model parameters until the loss function converges. The performance of the decision tree regression model is evaluated on the test set, and the trained decision tree regression model is used to predict the sugar content of the litchi to be detected, and the predicted value of the litchi sugar content is output.
[0071] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.
[0072] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
[0073] The present invention and its embodiments are described above, and such description is not restrictive. The drawings show only one embodiment of the present invention, and the actual structure is not limited thereto. In short, if ordinary technicians in the field are inspired by it, without departing from the purpose of the invention, they can design a structure and embodiment similar to the technical solution without creativity, which should belong to the protection scope of the present invention.
Claims
1. A method for detecting sugar content in litchi based on machine learning, characterized in that: The method comprises the following steps: Step S1: complete information collection, specifically, using a rotating drum, fixing the rotating drum on the top of the conveyor belt for conveying litchi, installing cameras at different angles on the front and rear sections of the rotating drum and on the left and right sides of the conveyor belt, capturing the shape of litchi, collecting the original image of litchi, and using a weight sensor to obtain litchi weight data; Step S2: prior knowledge learning is used to capture the spatial structure of litchi morphology, specifically, collecting litchi morphology data sets, predefining litchi models, determining key points of litchi models, and extracting prior knowledge of litchi models from litchi morphology data sets through graph convolutional networks, wherein the prior knowledge specifically refers to litchi morphological features; Step S3: feature fusion, specifically, extracting image features, using a multi-head cross attention mechanism to fuse prior knowledge with image features, and compensating for data loss in litchi occluded areas; Step S4: predicting the shape of the obscured area of the litchi according to prior knowledge, image features and the litchi weight data, and updating the litchi model; Step S5: using a Fourier transform near-infrared spectrometer to scan and record the reflectance spectrum of the litchi, and using a white reference plate to perform spectrum correction during scanning; Step S6: preprocessing, specifically, correcting scattering and baseline drift to obtain spectral feature data; Step S7: Interpretability analysis is used to improve the interpretability of sugar detection. A regression model is constructed. Interpretable artificial intelligence technology is used to analyze the wavelength range of the Fourier transform near-infrared spectrometer used for acquisition. The importance of wavelength to sugar detection results is calculated to determine the wavelength range that plays a key role in sugar detection. According to the wavelength range, spectral feature data is screened. The formula used is as follows: ; In the formula, Indicates wavelength Importance of sugar test results, represents the total wavelength set of the spectral feature data, express A subset of Indicates that the regression model is only used Sugar content prediction value when making predictions, Indicated in On the basis of , the sugar content prediction value after retraining the regression model, Indicated in ,and ,and Under the condition of traversing wavelength Find the cumulative sum, Indicates the number of elements in a collection. represents factorial; Step S8: Model output, specifically, the regression model analyzes the screened spectral feature data and the updated litchi model, and outputs a predicted litchi sugar value.
2. A method for detecting sugar content in litchi based on machine learning according to claim 1, characterized in that: In step S3, the feature fusion specifically includes the following steps: Step S31: extracting image features, specifically, using a feature extractor to obtain image features from the original litchi image, performing point-by-point convolution processing on the image features and the prior knowledge, respectively, to obtain a query vector, a key vector, and a value vector of the image features and the prior knowledge; Calculate the similarity between the query vector and the key vector of the image feature, use the similarity between the query vector and the key vector of the image feature as the attention weight A, and add the result of the weighted summation of the attention weight A and the value vector of the image feature to the prior knowledge; Step S32: Image occlusion compensation is used to compensate for the features of the occluded area of the litchi, calculate the similarity between the query vector and the key vector of the prior knowledge, use the similarity between the query vector and the key vector of the prior knowledge as the attention weight B, and add the result of the weighted sum of the attention weight B and the value vector of the prior knowledge to the image features.
3. A method for detecting sugar content in litchi based on machine learning according to claim 2, characterized in that: In step S6, the preprocessing specifically includes the following steps: Step S61: converting the reflection spectrum into a pseudo absorption spectrum; Step S62: standardize the normal variable to obtain a standard normal transformation spectrum; Step S63: highlighting the local changes of the spectrum, specifically, using a first-order SG filter to process the pseudo-absorption spectrum, fitting a polynomial through a sliding window, and calculating the first-order derivative; Step S64: continuously removing the conversion, which is used to highlight the shape and position of the absorption peak in the pseudo absorption spectrum and remove the baseline drift, specifically, defining a window width greater than or equal to the absorption peak in the pseudo absorption spectrum, for any point in the pseudo absorption spectrum, calculating the average value of the neighboring points within half of the window width around the point, using the calculated average value as the continuous spectrum value of the point, obtaining the continuous spectrum of the pseudo absorption spectrum, dividing the pseudo absorption spectrum by the continuous spectrum, and obtaining the preprocessed spectrum; Step S65: identifying the position of the absorption peak in the pseudo absorption spectrum, specifically, using a second-order SG filter to process the preprocessed spectrum to obtain a second-order derivative of the preprocessed spectrum; Step S66: Record the reflection spectrum, pseudo-absorption spectrum, standard normal transformation spectrum, first-order derivative, pre-processed spectrum and second-order derivative as spectral characteristic data.
Citation Information
Patent Citations
Rapid nondestructive testing process for strawberry sugar
CN113340823A
Segmentation to improve chemical analysis
US20230027514A1
KR20230172908A
Cited By
Method, system and device for judging and classifying target maturity of apple picking robot
CN121128456A