A Litchi Sugar Content Detection Method Based on Machine Learning
By combining rotating roller multi-angle cameras and lossless near-infrared spectral imaging technology, artificial intelligence can be explained, and error and redundancy problems in lychee sugar detection are solved, achieving efficient and accurate lychee sugar detection.
Patent Information
- Application Number
- CN202510275996.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-10
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2045-03-10
AI Technical Summary
The existing technology has detection errors caused by factors such as light, occlusion, and angle in the detection of litchi sugar. Near-infrared detection is affected by the thickness and moisture content of the epidermis. X-ray imaging equipment is expensive and has radiation damage. Multi-source and multi-scale data redundancy increases the computing burden, which is an unexplainable problem of traditional machine learning.
The rotating roller multi-angle camera is used to capture the appearance information of the lychee, combine the weight sensor to obtain more physical data, use lossless near-infrared spectral imaging technology to screen important wavelengths, and use interpretable artificial intelligence technology to optimize model design, reduce redundant information, improve detection accuracy and computing efficiency.
It reduces detection errors, reduces equipment costs, improves the accuracy and calculation efficiency of lychee sugar detection, avoids radiation damage, and simplifies the model training process.
Smart Images

Figure CN119780031B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of sugar detection, and specifically refers to a litchi sugar detection method based on machine learning. Background Art
[0002] As an important cash 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 of detecting litchi sugar using computer vision.
[0003] In existing similar solutions, for example, CN113192090B, a peach sorting method and device based on machine learning. This solution addresses the technical problems of low accuracy and efficiency in the existing peach sorting methods. By collecting peach images, classifying the size and shape of peaches, using a near-infrared sensor, establishing a relationship model between the size of the optical signal and the sugar content using near-infrared diffuse reflection technology, predicting the sugar content of peaches, and combining the analysis results of size, color, and sugar content to control peach sorting, it achieves the technical effect of non-contact detection of peaches and effectively reduces losses during the sorting process. However, firstly, the existing technology uses object detection algorithms for size and color, and images are usually affected by factors such as light, occlusion, and angle. Moreover, the side of the peach close to the conveyor belt cannot usually be captured by the camera, resulting in detection errors. Secondly, near-infrared detection may be affected by factors such as the thickness of the peach skin and water content, leading to deviations in sugar content measurement. Relying only on the 820nm wavelength for detection may not be sufficient to distinguish the sugar content changes of different varieties of peaches.
[0004] In addition, for example, CN112697984B, a method for non-destructive detection of fruit defects and a fruit grading method based on neural networks. This solution addresses the technical problems of inaccurate detection and grading of fruit defects in the existing technology. By integrating appearance images, sliced images, sliced chemical detection data, and defect information, corresponding to X-ray images, training a non-destructive fruit defect detection model, and outputting grading results, it achieves the technical effect of accurately detecting internal and external defects of fruits and comprehensively evaluating fruit quality. However, there are technical problems such as although X-ray imaging has strong penetrability, it will cause certain radiation damage to fruits, affecting their quality and safety. Moreover, X-ray imaging equipment is expensive and has high maintenance costs, restricting the popularity of X-ray imaging equipment in production lines. In addition, multi-source and multi-scale data have redundant information, increasing the burden of data processing and model training. Traditional machine learning is a black-box model and cannot directly explain which spectral features affect sugar content prediction. Summary of the Invention
[0005] In view of the above situation, to overcome the defects of the prior art, the present invention provides a litchi sugar content detection method based on machine learning. In the prior art, when using object detection algorithms for size and color, images are usually affected by factors such as illumination, occlusion, and angle. Moreover, usually, 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 the thickness of the litchi skin and moisture content, resulting in deviations in sugar content measurement. Relying only on the 820nm wavelength for detection may not be sufficient to distinguish the sugar content changes of different varieties of litchi. For the technical problems, this solution first uses a rotating drum to make the litchi automatically roll before passing through the detection area. Cameras are installed 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 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 to improve the accuracy of sugar content measurement. In the prior art, although X-ray imaging has strong penetrability, it will cause certain radiation damage to fruits, affecting their quality and safety. Moreover, X-ray imaging equipment is expensive and has high maintenance costs, limiting the popularity of X-ray imaging equipment in production lines. In addition, there is redundant information in multi-source multi-scale data, increasing the burden of data processing and model training. Traditional machine learning is a black box model and cannot directly explain which spectral features affect sugar content prediction. For the technical problems, this solution uses non-destructive, fast, and low-cost near-infrared spectroscopy imaging technology. According to the importance of wavelengths for sugar content detection results, near-infrared wavelengths are screened to remove redundant information and extract features contributing to detection and grading, greatly reducing the computational resources and time consumption of model training. An interpretable artificial intelligence technology is used to optimize the design of the regression model, reduce the data dimension, and improve the computational efficiency.
[0006] The technical solution adopted by the present invention is as follows: A litchi sugar content detection method based on machine learning provided by the present invention includes the following steps:
[0007] Step S1: Complete information collection. Specifically, a rotating drum is used, and the rotating drum is fixedly arranged on the top of the conveyor belt for transporting litchi. The rotating drum rolls and flips the litchi. Cameras are installed 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 and collect the original images of the litchi. A weight sensor is used to obtain the weight data of the litchi;
[0008] Step S2: Prior knowledge learning, which is used to capture the spatial structure of the litchi shape. Specifically, a litchi shape dataset is collected, a litchi model is predefined, the key points of the litchi model are determined, and the prior knowledge of the litchi model is extracted from the litchi shape dataset through a graph convolutional network. The prior knowledge specifically refers to the litchi shape features. The formula for extracting the prior knowledge of the key points of the litchi model is as follows:
[0009] ;
[0010] 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 result of applying the Chebyshev polynomial to ; represents the order of graph convolution, represents the index of the order subscript, represents the learnable parameters of the graph convolutional network;
[0011] Step S3: Feature fusion, which is used to increase the correlation between prior knowledge and image features. Specifically, extract the image features, use the multi-head cross-attention mechanism to fuse the prior knowledge and the image features, and compensate for the data loss in the occluded area of the litchi;
[0012] Step S4: Predict the shape of the occluded area of the litchi based on the prior knowledge, the image features, and the litchi weight data, and update the litchi model;
[0013] Step S5: Use a Fourier transform near-infrared spectrometer to scan and record the reflection spectrum of the litchi, and use a white reference plate for spectral calibration during scanning;
[0014] Step S6: Preprocessing, specifically, correcting scattering and baseline drift to obtain spectral feature data;
[0015] Step S7: Interpretability analysis, which is used to improve the interpretability of sugar detection. Build a regression model, adopt interpretable artificial intelligence technology, analyze the wavelength range of the Fourier transform near-infrared spectrometer used for collection, determine the wavelength range that plays a key role in sugar detection by calculating the importance of the wavelength for the sugar detection result, and screen the spectral feature data according to the wavelength range. The formula used is as follows:
[0016] ;
[0017] In the formula, represents the wavelength represents the importance of the for the sugar detection result, represents the total wavelength set of the spectral feature data, represents a subset of represents the sugar prediction value when the regression model predicts only using ; represents on the basis of add the wavelength extra, the sugar prediction value after retraining the regression model, represents in and and Traverse the wavelength under the condition that Calculate the cumulative sum, represents the number of elements in the set, represents the factorial;
[0018] Step S8: Model output. Specifically, the regression model analyzes the filtered spectral feature data and the updated litchi model, and outputs the litchi sugar prediction value.
[0019] Further, in step S3, the feature fusion specifically includes the following steps:
[0020] Step S31: Image feature extraction, which is used to extract the features of litchi. Specifically, an image feature extractor is used to obtain image features from the original litchi image, and the image features and the prior knowledge are respectively subjected to point-by-point convolution processing to obtain the query vector, key vector, and value vector of the image features and the prior knowledge;
[0021] Calculate the similarity between the query vector and the key vector of the image features, and use the similarity between the query vector and the key vector of the image features as the attention weight A. The attention weight A represents the degree of attention of each pixel in the image features to each pixel in the prior knowledge, and add the result of weighted summation of the attention weight A and the value vector of the image features to the prior knowledge;
[0022] Step S32: Image occlusion compensation, which 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 features, and add the result of weighted summation of the attention weight B and the value vector of the prior knowledge to the image features.
[0023] Further, in step S6, the preprocessing specifically includes the following steps:
[0024] Step S61: Pseudo-absorption spectrum conversion, which converts the reflection spectrum into a pseudo-absorption spectrum. The formula used is as follows:
[0025] ;
[0026] In the formula, represents the pseudo-absorption spectrum, and the pseudo-absorption spectrum is used to represent the pseudo-absorption value at the wavelength , represents the reflectance value at the wavelength , is a constant, ;
[0027] Step S62: Standardize the normal variable. Specifically, calculate the mean and standard deviation of the pseudo-absorption spectrum. After subtracting the mean value of each point of the pseudo-absorption spectrum, divide it by the standard deviation to obtain the standard normal transformation spectrum;
[0028] Step S63: Highlight the local changes in the spectrum. Specifically, use a first-order Savitzky-Golay (S-G) filter to process the pseudo-absorption spectrum. Fit a polynomial through a sliding window and calculate the first derivative;
[0029] Step S64: Continuously remove the transformation, which is used to highlight the shape and position of the absorption peak in the pseudo-absorption spectrum and remove the baseline drift. Specifically, define a window width greater than or equal to the absorption peak in the pseudo-absorption spectrum. For any point in the pseudo-absorption spectrum, calculate the average value of the neighbor points within half of the window width around this point. Take the calculated average value as the continuous spectrum value of this point to obtain the continuous spectrum of the pseudo-absorption spectrum. Divide the pseudo-absorption spectrum by the continuous spectrum to obtain the preprocessed spectrum;
[0030] Step S65: Identify the position of the absorption peak in the pseudo-absorption spectrum. Specifically, use a second-order S-G filter to process the preprocessed spectrum to obtain the second derivative of the preprocessed spectrum;
[0031] Step S66: Record the reflection spectrum, pseudo-absorption spectrum, standard normal transformation spectrum, first derivative, preprocessed spectrum, and second derivative as spectral feature data.
[0032] The present invention provides a method for detecting the sugar content of litchi based on machine learning. The beneficial effects obtained by the present invention using the above scheme are as follows:
[0033] (1) Aiming at the technical problems existing in the prior art that when using a target detection algorithm for size and color, the image is usually affected by factors such as illumination, occlusion, and angle, and there is usually a situation where 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 the thickness of the litchi skin and moisture content, resulting in deviations in sugar content measurement. Relying only on the 820 nm wavelength for detection may not be sufficient to distinguish the sugar content changes of different varieties of litchi. In this solution, first, a rotating drum is used to make the litchi automatically roll before passing through the detection area. Cameras are installed at different angles in 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 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 to improve the accuracy of sugar measurement;
[0034] (2)In view of the technical problems existing in the prior art that although X-ray imaging has strong penetrability, it will cause certain radiation damage to fruits, affecting their quality and safety, and the 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, there is redundant information in multi-source and multi-scale data, increasing 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. This solution adopts non-destructive, fast and low-cost near-infrared spectral imaging technology, screens near-infrared wavelengths according to the importance of wavelengths for sugar detection results, removes redundant information, extracts features contributing to detection and grading, greatly reducing the computational resources and time consumption for model training. It adopts interpretable artificial intelligence technology to optimize the regression model design, reduce the data dimension and improve the computational efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 FIG. is a schematic flow chart of a litchi sugar content detection method based on machine learning provided by the present invention;
[0036] Figure 2 FIG. is a schematic diagram of step S3;
[0037] Figure 3 FIG. is a schematic diagram of step S6.
[0038] The drawings are used to provide a further understanding of the present invention, and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention, but do not constitute a limitation to the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0039] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0040] In the description of the present invention, it should be understood that the terms "upper", "lower", "front", "rear", "left", "right", "top", "bottom", "inner", "outer", etc. indicating the orientation or positional relationship are based on the orientation or positional relationship shown in the 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 orientation, be constructed and operated in a specific orientation, and therefore should not be construed as a limitation to the present invention.
[0041] Example 1. Refer to Figures 1 to 3 , a litchi sugar content detection method based on machine learning provided by the present invention, the method includes the following steps:
[0042] Step S1: Complete information collection. Specifically, use a rotating drum, fix the rotating drum at the top of the conveyor belt for transporting lychees. The rotating drum rolls and flips the lychees. Install cameras at different angles on the front and rear sections of the rotating drum and the left and right sides of the conveyor belt to capture the shape of the lychees, collect the original images of the lychees, and use a weight sensor to obtain the weight data of the lychees.
[0043] Step S2: Prior knowledge learning, which is used to capture the spatial structure of the lychee shape. Specifically, collect a lychee shape dataset, pre-define a lychee model, determine the key points of the lychee model, and extract the prior knowledge of the lychee model from the lychee shape dataset through a graph convolutional network. The prior knowledge specifically refers to the lychee shape features. The formula for extracting the prior knowledge of the key points of the lychee model is as follows:
[0044] ;
[0045] In the formula, represents the prior knowledge extracted by the graph convolutional network, represents the key points of the lychee model, represents the normalized graph Laplacian matrix, represents the result of applying the Chebyshev polynomial to ; represents the order of the graph convolution, represents the index of the order subscript, represents the learnable parameters of the graph convolutional network.
[0046] Step S3: Feature fusion, which is used to increase the correlation between the prior knowledge and the image features. Specifically, extract the image features, and use the multi-head cross-attention mechanism to fuse the prior knowledge and the image features to compensate for the data loss in the occluded area of the lychees.
[0047] Step S4: Predict the shape of the occluded area of the lychee according to the prior knowledge, the image features, and the weight data of the lychee, and update the lychee model.
[0048] Step S5: Use a Fourier transform near-infrared spectrometer to scan and record the reflection spectrum of the lychee, and use a white reference plate for spectral calibration during scanning.
[0049] Step S6: Preprocessing. Specifically, correct the scattering and baseline drift to obtain spectral feature data.
[0050] Step S7: Interpretability analysis, which is used to improve the interpretability of sugar detection. A regression model is constructed, and interpretable artificial intelligence technology is adopted to analyze the wavelength range of the Fourier transform near-infrared spectrometer used for collection. By calculating the importance of the wavelength for the sugar detection result, the wavelength range that plays a key role in sugar detection is determined. According to the wavelength range, spectral feature data is screened. The formula used is as follows:
[0051] ;
[0052] In the formula, represents the wavelength the importance for the sugar detection result, represents the total wavelength set of the spectral feature data, represents a subset of represents when the regression model uses only for prediction, the sugar prediction value, represents on the basis of and additionally adding the wavelength after retraining the regression model, the sugar prediction value, represents at and and under the condition of traversing the wavelength to find the cumulative sum, represents the number of elements in the set, represents the factorial;
[0053] Step S8: Model output. Specifically, the regression model analyzes the screened spectral feature data and the updated litchi model, and outputs the litchi sugar prediction value.
[0054] Example 2. Refer to Figure 1 and Figure 2 This example is based on the above example. In step S3, the feature fusion specifically includes the following steps:
[0055] Step S31: Image feature extraction, which is used to extract the features of litchi. Specifically, a feature extractor is used to obtain image features from the original litchi image, and point-by-point convolution processing is performed on the image features and the prior knowledge respectively to obtain the query vector, key vector, and value vector of the image features and the prior knowledge;
[0056] Calculate the similarity between the query vector and the key vector of the image features, and use the similarity between the query vector and the key vector of the image features as the attention weight A. The attention weight A represents the degree of attention of each pixel in the image features to each pixel in the prior knowledge. Add the result of weighted summation of the attention weight A and the value vector of the image features to the prior knowledge;
[0057] Step S32: Image occlusion compensation, which 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 features. Add the result of weighted summation of the attention weight B and the value vector of the prior knowledge to the image features.
[0058] Embodiment 3, refer to Figures 1 to 3 , this embodiment is based on the above embodiment. In step S6, the preprocessing specifically includes the following steps:
[0059] Step S61: Pseudo-absorption spectrum conversion, which converts the reflection spectrum into a pseudo-absorption spectrum. The formula used is as follows:
[0060] ;
[0061] In the formula, represents the pseudo-absorption spectrum, and the pseudo-absorption spectrum is used to represent the pseudo-absorption value at the wavelength , represents the reflectance value at the wavelength , is a constant, ;
[0062] Step S62: Standardize the normal variable. Specifically, calculate the mean and standard deviation of the pseudo-absorption spectrum, subtract the mean value of each point of the pseudo-absorption spectrum, and then divide by the standard deviation to obtain the standard normal transformation spectrum;
[0063] Step S63: Highlight the local changes in the spectrum. Specifically, use a first-order S-G filter to process the pseudo-absorption spectrum, fit a polynomial through a sliding window, and calculate the first derivative;
[0064] Step S64: Continuous removal transformation, which is used to highlight the shape and position of the absorption peak in the pseudo-absorption spectrum and remove the baseline drift. Specifically, define a window width greater than or equal to the absorption peak in the pseudo-absorption spectrum. For any point in the pseudo-absorption spectrum, calculate the average value of the neighbor points within half of the window width around this point, and use the calculated average value as the continuous spectrum value of this point to obtain the continuous spectrum of the pseudo-absorption spectrum. Divide the pseudo-absorption spectrum by the continuous spectrum to obtain the preprocessing spectrum;
[0065] Step S65: Identify the positions of the absorption peaks in the pseudo-absorption spectrum. Specifically, use a second-order Savitzky-Golay (S-G) filter to process the preprocessed spectrum to obtain the second derivative of the preprocessed spectrum.
[0066] Step S66: Denote the reflection spectrum, pseudo-absorption spectrum, standard normal variate (SNV) spectrum, first derivative, preprocessed spectrum, and second derivative as spectral feature data.
[0067] Example 4, refer to Figures 1 to 3 , based on the above example, in step S7, the regression model uses a non-linear regression model based on decision trees.
[0068] Example 5, refer to Figures 1 to 3 , based on the above example, this example only differs from the above example in the selection of the regression model. The regression model uses a partial least squares regression model.
[0069] Example 6, refer to Figures 1 to 3 , based on the above example, in step S7, for determining the wavelength range that plays a key role in sugar detection, the key wavelengths of the spectral feature data retained after screening are 570–630 nm, 670–730 nm, 920–960 nm, 1150–1200 nm, and 2470–2500 nm.
[0070] Example 7, refer to Figures 1 to 3 , based on the above example, in step S7, the represents the total wavelength set of the spectral feature data. Specifically, F = {350, 351,..., 2500}.
[0071] Example 8, refer to Figures 1 to 3 , based on the above example, in step S7, the represents a subset of, specifically, S = {400, 600, 900}.
[0072] Example 9, refer to Figures 1 to 3 , based on the above example, in step S5, the Fourier transform near-infrared spectrometer collects the reflection spectrum of litchi in the wavelength range of 350–2500 nm.
[0073] Example 10, refer to Figures 1 to 3 , based on the above example, in step S7, the interpretability analysis is specifically to analyze the wavelength range of the Fourier transform near-infrared spectrometer used for collection. By calculating the importance of the wavelengths for the sugar detection results, determine the wavelength range that plays a key role in sugar detection. The experimental table is shown as follows:
[0074]
[0075] According to the experimental table, key wavelengths were screened. By calculating the importance of each wavelength, the wavelength ranges that play a key role in sugar detection were screened out, and the conclusion was drawn that the key wavelength ranges are 570–630 nm, 670–730 nm, 920–960 nm, 1150–1200 nm, and 2470–2500 nm; the most important wavelengths are 1600 - 1700 nm and 1800 - 1900 nm (with high contribution); the wavelengths with low contribution are 350 - 570 nm, 850 - 900 nm, 900 - 920 nm, 1100 - 1150 nm, 1300 - 1400 nm, and 2100 - 2200 nm (mainly affecting moisture and not significantly affecting sugar detection).
[0076] Finally, only the wavelengths of 570–630 nm, 670–730 nm, 920–960 nm, 1150–1200 nm, and 2470–2500 nm that incorporate the key wavelengths were used for sugar detection, which can reduce the computational burden and improve the prediction accuracy.
[0077] Example XI, refer to Figures 1 to 3 , this example is based on Example IV. In step S8, the screened spectral feature data and the updated litchi model are used as the data set. 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 non - linear regression model based on the decision tree. The non - linear regression model based on the decision tree is abbreviated as the decision tree regression model. The parameters of the decision tree regression model are initialized. 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 reduction in impurity required for node splitting, and the splitting strategy parameter. The root mean square error is used as the loss function for the litchi sugar prediction problem. The random forest algorithm is used to train the decision tree regression model to minimize the loss function and update the parameters of the decision tree regression model 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.
[0078] It should be noted that in this document, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements but also includes other elements not expressly listed, or elements inherent to such process, method, article or device.
[0079] Although the embodiments of the present invention have been shown and described, it will be understood by those of ordinary skill in the art that various changes, modifications, substitutions and variations can be made to these embodiments without departing from the principles and spirit of the present invention, and the scope of the present invention is defined by the appended claims and their equivalents.
[0080] The above describes the present invention and its embodiments. Such a description is not restrictive. What is shown in the drawings is only one of the embodiments of the present invention, and the actual structure is not limited thereto. In general, if those of ordinary skill in the art are inspired by it and, without departing from the gist of the present invention, design similar structural modes and embodiments without creative efforts, they should all fall within the protection scope of the present invention.
Claims
1. A litchi sugar detection method based on machine learning, characterized in that: The method includes the following steps: Step S1: Complete information collection. Specifically, use a rotating drum, fix the rotating drum at the top of the conveyor belt for transporting lychees, install cameras at different angles on the front and rear sections of the rotating drum and the left and right sides of the conveyor belt to capture the shape of lychees, collect the original images of lychees, and use a weight sensor to obtain the weight data of lychees; Step S2: Prior knowledge learning, which is used to capture the spatial structure of the lychee shape. Specifically, collect a lychee shape dataset, pre-define a lychee model, determine the key points of the lychee model, and extract the prior knowledge of the lychee model from the lychee shape dataset through a graph convolutional network. The prior knowledge specifically refers to the lychee shape characteristics; Step S3: Feature fusion. Specifically, extract image features, and use a multi-head cross-attention mechanism to fuse the prior knowledge with the image features to compensate for the data loss in the occluded area of the lychee; Step S4: Predict the shape of the occluded area of the lychee based on the prior knowledge, image features, and the weight data of the lychee, and update the lychee model; Step S5: Use a Fourier transform near-infrared spectrometer to scan and record the reflection spectrum of the lychee, and use a white reference plate for spectral calibration during scanning; Step S6: Preprocessing. Specifically, correct scattering and baseline drift to obtain spectral feature data; Step S7: Interpretability analysis, which is used to improve the interpretability of sugar detection. Build a regression model, use interpretable artificial intelligence technology to analyze the wavelength range of the Fourier transform near-infrared spectrometer used for collection, determine the wavelength range that plays a key role in sugar detection by calculating the importance of the wavelength to the sugar detection result, and screen the spectral feature data according to the wavelength range. The formula used is as follows: ; In the formula, represents the wavelength and its importance to the sugar detection result, represents the total wavelength set of the spectral feature data, represents a subset of represents the predicted sugar value when the regression model makes a prediction using only ; represents that, on the basis of , the wavelength is additionally added, and it is the predicted sugar value after retraining the regression model; represents that, under the conditions of , and , and , the wavelengths are traversed to find the cumulative sum; represents the number of elements in the set; represents the factorial; Step S8: Model output. Specifically, the regression model analyzes the screened spectral feature data and the updated lychee model, and outputs the predicted value of the lychee sugar content.
2. The method for detecting lychee sugar content based on machine learning according to claim 1, characterized in that: In step S3, the feature fusion specifically includes the following steps: Step S31: Image feature extraction. Specifically, use a feature extractor to obtain image features from the original lychee image, perform point-by-point convolution processing on the image features and the prior knowledge respectively, and obtain the query vector, key vector, and value vector of the image features and the prior knowledge respectively; Calculate the similarity between the query vector and the key vector of the image features, use the similarity between the query vector and the key vector of the image features as the attention weight A, and add the result of weighted summation of the attention weight A and the value vector of the image features to the prior knowledge; Step S32: Image occlusion compensation, which is used to compensate for the features of the occluded area of the lychee. 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 weighted summation of the attention weight B and the value vector of the prior knowledge to the image features.
3. The method for detecting lychee sugar content based on machine learning according to claim 2, characterized in that: In step S6, the preprocessing specifically includes the following steps: Step S61: Pseudo-absorption spectrum conversion, converting the reflection spectrum into a pseudo-absorption spectrum; Step S62: Standardized normal variable to obtain the standard normal transformation spectrum; Step S63: Highlight the local changes in the spectrum. Specifically, use a first-order Savitzky-Golay (S-G) filter to process the pseudo-absorption spectrum, fit a polynomial through a sliding window, and calculate the first derivative; Step S64: Continuum removal, which is used to highlight the shape and position of the absorption peaks in the pseudo-absorption spectrum and remove baseline drift. Specifically, define a window width greater than or equal to the absorption peaks in the pseudo-absorption spectrum. For any point in the pseudo-absorption spectrum, calculate the average value of the neighboring points within half of the window width around this point. Take the calculated average value as the continuum spectrum value of this point to obtain the continuum spectrum of the pseudo-absorption spectrum. Divide the pseudo-absorption spectrum by the continuum spectrum to obtain the preprocessed spectrum; Step S65: Identify the positions of the absorption peaks in the pseudo-absorption spectrum. Specifically, use a second-order S-G filter to process the preprocessed spectrum to obtain the second derivative of the preprocessed spectrum; Step S66: Record the reflection spectrum, pseudo-absorption spectrum, standard normal transformation spectrum, first derivative, preprocessed spectrum, and second derivative as spectral feature data.
Citation Information
Patent Citations
Rapid nondestructive testing process for strawberry sugar
CN113340823A
KR20230172908A