Portable deep learning model lightweight method for rapeseed quality detection
Through the teacher-student model architecture and joint distillation loss, structured pruning and quantization technology, the contradiction between high precision and low calculation volume in portable rapeseed quality inspection is solved, and efficient detection on edge devices is achieved.
Patent Information
- Application Number
- CN202510347529.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-24
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2045-03-24
AI Technical Summary
The existing portable rapeseed quality detection methods are difficult to significantly reduce the calculation amount and parameter amount while maintaining high detection accuracy, resulting in difficulty in deploying and operating on edge devices.
The teacher-student model architecture is adopted, and the knowledge of the teacher model is transferred to the student model through combined distillation loss and structured pruning technology, and the quantitative technology is combined to optimize the parameter quantity and calculation quantity of the student model.
It significantly reduces the computing volume and storage requirements of the model, while maintaining high-precision rapeseed quality detection capabilities, suitable for edge computing devices.
Smart Images

Figure CN120408132A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of agricultural product quality detection, and particularly relates to a method for lightweighting a deep learning model for portable rapeseed quality detection. Background Art
[0002] Traditional methods for detecting crop components mainly rely on chemical analysis techniques. These methods are not only highly destructive but also time-consuming. In contrast, near-infrared spectroscopy technology, as a non-destructive detection means, exhibits extensive application potential in the agricultural field, especially in crop quality and component analysis, due to its fast and non-destructive characteristics. However, traditional near-infrared spectroscopy instruments are usually large in size and fixed, lacking portability, which to a certain extent limits their application in field real-time data acquisition and processing.
[0003] With the progress of technology, more and more portable spectrometers have been proposed in the prior art. These devices can collect spectral data in the field in real time and upload it to the cloud for subsequent processing. In addition, edge computing, as an effective solution, can directly process data at the device end, thereby reducing data transmission latency and improving real-time performance. In the application of edge computing, traditional machine learning models have become a viable option due to their relatively fast calculation speed and efficient operation on edge devices. At the same time, deep learning technology, with its powerful data fitting ability, shows higher accuracy in processing complex pattern recognition and detection tasks and has gradually become a more preferred technology.
[0004] Although the development of portable spectrometers and edge computing technology has made real-time data analysis possible, the prior art still faces many challenges. On the one hand, cloud-based computing solutions have problems such as transmission latency and long data processing time, making it difficult to meet real-time requirements. On the other hand, traditional machine learning models have limited calculation accuracy in complex tasks and are difficult to meet the requirements of high-precision detection. While deep learning models have higher accuracy, they usually have a large number of parameters and high computing requirements, which makes it difficult to deploy and run them on edge devices. Therefore, how to significantly reduce the amount of calculation and the number of parameters while maintaining high detection accuracy has become a key problem faced by the current technology. Summary of the Invention
[0005] The present invention proposes a method for lightweighting a deep learning model for portable rapeseed quality detection, which solves the problem that existing quality detection methods cannot simultaneously meet high detection accuracy and low computational complexity.
[0006] To solve the above technical problems, the present invention provides a method for lightweighting a deep learning model for portable rapeseed quality detection, including the following steps:
[0007] Step S1: Construct a teacher model and a student model, and use the teacher model and the student model to extract local peak features and global time-domain features from the near-infrared spectral data of rapeseed. The teacher model and the student model output predicted values of the oil content of rapeseed.
[0008] Step S2: Construct a joint distillation loss based on the gap between the predicted value output by the student model and the true value, the gap between the predicted values output by the teacher model and the student model, the gap between the local peak features and global time-domain features extracted by the teacher model and the student model, and the gap between the predicted values of each band of the teacher model and the student model.
[0009] Step S3: Transfer the knowledge of the teacher model to the student model through the joint distillation loss, and use the student model after knowledge transfer to predict the oil content of rapeseed.
[0010] Preferably, in step S3, the importance of each channel of the student model after knowledge transfer is sorted, and the channels with relatively lower rankings are pruned according to the set pruning ratio.
[0011] Preferably, calculate the L1 norm of each channel, and sort the importance of each channel according to the magnitude of the L1 norm.
[0012] Preferably, in step S3, after pruning the student model after knowledge transfer, the mean square gap between the predicted values of the student model before and after pruning is used as the transfer loss, and the mean square error between the predicted value output by the pruned student model and the true value is used as the MSE loss. Freeze the parameters of the pruned part, and use the transfer loss, MSE loss, and the gap between the predicted values of each band of the teacher model and the student model before pruning to fine-tune the parameters of the pruned student model.
[0013] Preferably, in step S1, after the teacher model outputs the predicted value of the oil content of rapeseed, optimize the parameters of the teacher model by minimizing the mean square error loss between the true value and the predicted value of the oil content of rapeseed.
[0014] Preferably, the joint distillation loss in step S2 includes a soft label distillation loss, a multi-scale feature distillation loss, and a time-domain distillation loss. The expression of the joint distillation loss is:
[0015] L total =α·L soft +β·L feature +γ·L temporal,smooth ;
[0016] Wherein, L total is the joint distillation loss; L soft is the soft label distillation loss; L feature is the multi-scale feature distillation loss; Ltemporal,smooth is the time-domain distillation loss; α, β, and γ are the weights of the soft-label distillation loss, the multi-scale feature distillation loss, and the time-domain distillation loss, respectively.
[0017] Preferably, in step S2, the difference between the local peak features and the global time-domain features extracted by the teacher model and the student model is used as the multi-scale feature distillation loss, and the expression of the multi-scale feature distillation loss is:
[0018]
[0019] In the formula, L feature is the multi-scale feature distillation loss; N is the number of samples of the near-infrared spectral data of rapeseed; w shallow (i) is the relative intensity between the peak and the noise of the i-th sample data; are the local peak features extracted by the student model and the teacher model, respectively; T shallow 、T deep are temperature parameters; w deep (i) is the average change trend of the i-th sample data; are the global time-domain features extracted by the student model and the teacher model, respectively; represents calculating the L2 norm; are the spectral values of curve i at the t-th point and the (t-1)-th point, respectively; Signal is the peak; Noise is the noise; is the peak value of curve i; is the standard deviation of the baseline region of curve i.
[0020] Preferably, in S2, the difference between the predicted values of each band of the teacher model and the student model is used as the time-domain distillation loss, and the expression of the time-domain distillation loss is:
[0021]
[0022] In the formula, L temporal,smooth is the time-domain distillation loss; t is the band; N is the number of samples of the near-infrared spectral data of rapeseed; are the spectral values of curve i at the t-th point and the (t-1)-th point, respectively; are the predicted values of the student model and the teacher model at band t, respectively; T t is the temperature parameter at band t.
[0023] Preferably, in step S3, when transferring the knowledge of the teacher model to the student model through the joint distillation loss, α, β, and γ are updated in each training cycle:
[0024]
[0025] In the above formula, α(m) and α(m + 1) are the weights of the soft label distillation loss at training epochs m and m + 1 respectively; η is the learning rate; β(m) and β(m + 1) are the weights of the multi-scale feature distillation loss at training epochs m and m + 1 respectively; γ(m) and γ(m + 1) are the weights of the temporal domain distillation loss at training epochs m and m + 1 respectively; represents taking the partial derivative.
[0026] Preferably, in step S3, the parameters of the student model after knowledge transfer are quantized, mapping all the parameters of the student model to a smaller numerical range. The expression for the quantization is:
[0027]
[0028]
[0029] In the formula, W q and X q are the quantized weight parameters and input features respectively; round() is the quantization function; w and x are the original floating-point parameters without quantization processing; Δw and Δx are the quantization scaling factors.
[0030] The advantages of the present invention at least include:
[0031] 1. Not only considering the gap between the predicted value and the true value of the student model, but also introducing the predicted value gap, feature gap between the teacher model and the student model, and the predicted value gap of each band. This multi-dimensional loss function design can more comprehensively constrain the learning process of the student model, avoid overfitting of the student model on some local features, and thus improve the generalization ability of the model;
[0032] 2. Respectively extracting the local peak features and global temporal features in the near-infrared spectrum. The local peak features are related to the chemical components of rapeseed, while the global temporal features are related to the overall trend of the spectrum. This multi-feature fusion method can more comprehensively capture the key information in the near-infrared spectrum data of rapeseed, and thus improve the prediction accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 is a schematic flowchart of the method according to an embodiment of the present invention;
[0034] Figure 2 is a schematic diagram of the near-infrared spectrum curve of rapeseed;
[0035] Figure 3 is a schematic structural diagram of the teacher model according to an embodiment of the present invention;
[0036] Figure 4 is a schematic structural diagram of the student model according to an embodiment of the present invention;
[0037] Figure 5 Schematic flow diagram of multi-scale feature distillation according to an embodiment of the present invention;
[0038] Figure 6 Schematic structural diagram of the convolutional module of the teacher model and the student model according to an embodiment of the present invention;
[0039] Figure 7 Schematic diagram of structured pruning according to an embodiment of the present invention;
[0040] Figure 8 Schematic structural diagram of the system according to an embodiment of the present invention. Detailed implementation manners
[0041] Next, in combination with the accompanying drawings in the embodiments of the present invention, the technical solutions in the embodiments of the present invention are clearly and completely described. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the protection scope of the present invention.
[0042] As Figure 1 shown, an embodiment of the present invention provides a deep learning model lightweight method for portable rapeseed quality detection, including the following steps:
[0043] Step S1: Construct a teacher model and a student model, use the teacher model and the student model to extract local peak features and global time-domain features from the near-infrared spectral data of rapeseed. After the teacher model and the student model perform operations such as convolution and splicing on the extracted features, the predicted value of the oil content of rapeseed is output.
[0044] Specifically, in an embodiment of the present invention, the physical and chemical properties of rapeseed, that is, the oil content, are predicted through the near-infrared spectral curve. The data samples are from commercially available rapeseed at the mature stage, with a total of 681 samples. The spectral data is collected using the Puyan Interconnected Portable Spectrometer NIR-R210 type, and the wavelength range is 900–1700nm. The spectral data is as Figure 2 shown. The corresponding physical and chemical values of each sample are measured by the research center, and finally a complete data set is constructed for subsequent analysis.
[0045] The structure of the teacher network is as Figure 3As shown in the figure, considering the high sensitivity of the peaks in the near-infrared spectral data to the prediction of physical and chemical values, a one-dimensional convolutional neural network 1D-CNN is used as the backbone network of the teacher network to capture the local features of the spectral data through multiple convolutional kernels. At the same time, considering that the time-domain information in the spectral data is equally important, after one convolution of the 1D-CNN, a Transformer module is introduced to model the time-domain features of the spectral data. Finally, the extracted time-domain features are concatenated with the peak features, and the squeeze-and-excitation SE attention mechanism is applied to assign weights to each channel to retain important features for prediction.
[0046] After using the teacher model to predict the oil content of rapeseed, the mean square error MSE between the predicted value and the true value of the teacher model is used as the loss function. At the same time, to avoid overfitting, an L2 regularization term is added to the loss function. The loss function L of the teacher model teacher,total is expressed as:
[0047]
[0048] In the above formula, L teacher,MSE is the mean square error loss of the teacher model; λ is the regularization coefficient; is the L2 regularization term; N is the number of samples of the near-infrared spectral data of rapeseed; y i is the true value; y i ' is the predicted value output by the teacher model.
[0049] By minimizing the loss function L teacher,total , the teacher model is iteratively trained to obtain the optimal parameters of the teacher model.
[0050] Step S2: Construct a joint distillation loss based on the gap between the predicted value and the true value output by the student model, the gap between the predicted values output by the teacher model and the student model, the gap between the local peak features and the global time-domain features extracted by the teacher model and the student model, and the gap between the predicted values of each band of the teacher model and the student model.
[0051] Specifically, the network structure of the student model is as Figure 4 shown. Compared with the network structure of the teacher model, redundant modules and layers are reduced, but the number of layers of the backbone convolutional module remains unchanged. The structure of the backbone convolutional module is as Figure 6 shown. For example, the convolutional kernel size of the teacher network is 1×13, while the convolutional kernel of the student network is adjusted to 1×3, reducing the number of parameters.
[0052] Through the distillation technique, the knowledge in the teacher network is transferred to a smaller student network. The student network learns the multi-scale features extracted by the teacher network, reducing the model complexity while maintaining the prediction accuracy.
[0053] The near-infrared spectrum of rapeseed at the mature stage is a time-domain signal, which contains rich temporal information and the information of characteristic points such as wave peaks and wave valleys. By designing an appropriate loss function, the features of the teacher network can be better extracted, thereby improving the performance of the student network.
[0054] In the embodiment of the present invention, a joint distillation loss is designed for the characteristics of the near-infrared spectrum data of rapeseed, including a soft-label distillation loss, a multi-scale feature distillation loss, and a time-domain distillation loss.
[0055] The soft-label distillation loss includes the gap between the predicted value output by the student model and the true value, and the gap between the predicted values output by the student model and the teacher model. The soft-label distillation loss L soft has the following expression:
[0056] L soft = a·L reg + b·L distill ;
[0057]
[0058] In the above formula, a and b are weight parameters; L reg is the gap loss between the predicted value output by the student model and the true value; L distill is the gap loss between the predicted values output by the student model and the teacher model; are the predicted values output by the student model and the teacher model respectively; y t is the true value.
[0059] The multi-scale feature distillation loss includes two parts: shallow features and deep features. The shallow features are the feature layers after the near-infrared spectrum curve passes through a convolutional module once, that is, the data before entering the Transformer encoding layer model, and the deep features are the feature layers after the splicing of the Transformer encoding layer and 1D-CNN.
[0060] The shallow features, that is, the local wave peak features, focus on the local change trend, such as the local fluctuations and peak-valley components in the spectrum curve. These features help to capture local information. Especially in the prediction of rapeseed oil content, local features are often closely related to the absorption characteristics of different substances.
[0061] The deep features, that is, the global time-domain features, focus on the overall change trend, that is, the global patterns and long-term dependencies spanning multiple bands. The introduction of the Transformer module enables the model to capture the relationships between different regions in the spectrum curve and identify global patterns, such as the comprehensive relationship between rapeseed oil content and multiple spectral bands.
[0062] The difference between the student model and the teacher model at different feature layers is measured by the L2 norm, guiding the student model to effectively learn the feature representation of the teacher model and improving the model performance.
[0063] Assume that at the shallow and deep feature layers, the feature outputs of the teacher model and the student model are respectively and where N represents the number of samples, and d shallow , d deep are the dimensions of the shallow and deep features respectively. Calculate the difference between the student and teacher models on multi-scale features through the L2 norm:
[0064]
[0065] In the formula, L feature is the multi-scale feature distillation loss; w shallow (i) is the relative intensity between the peak and the noise of the i-th sample data. The peak is more significant under high signal-to-noise ratio, indicating that the change of this peak contributes more to the overall prediction task; are the local peak features extracted by the student model and the teacher model respectively; T shallow , T deep are temperature parameters used to control the smoothness of the output; w deep (i) is the average change trend of the i-th sample data. Traverse all bands and calculate the overall change trend of each sample; are the global time-domain features extracted by the student model and the teacher model respectively; represents calculating the L2 norm; are respectively; Signal; Noise; std().
[0066] Aiming at the characteristics of the near-infrared spectral curve, the time-domain distillation loss is introduced. Its purpose is to guide the student model to learn the temporal dependence relationship. The core of the time-domain distillation loss is to make the prediction of the student model not only consistent with the overall prediction of the teacher model, but also as close as possible to the output of the teacher model at each band. For each band of the input spectrum, the predicted value of the student model at band t matches the predicted value of the teacher model. The expression of the time-domain distillation loss is:
[0067]
[0068] In the formula, L temporal,smooth is the time-domain distillation loss; N is the number of samples of the near-infrared spectral data of rapeseed; are the spectral values of curve i at the t-th point and the (t - 1)-th point respectively; are the predicted values of the student model and the teacher model at band t; T t is the temperature parameter at band t.
[0069] T t The role of is to adjust the softening degree during the distillation process, and through temperature adjustment, the matching accuracy of the student model to the output of the teacher model during the learning process. A higher temperature helps the student model learn more fine-grained features, especially when capturing the details of each band; while a lower temperature can prompt the student model to pay more attention to the matching of the overall trend and reduce overlearning of local noise. The selection of the temperature parameter can be optimized through grid search according to the specific experimental results.
[0070] Combining the change trend of the near-infrared spectral curve with the peak characteristics, extracting the time-domain characteristics of the near-infrared spectrum, and designing a joint distillation loss, which includes soft label distillation loss, feature distillation loss, and time-domain distillation loss, to enable the student network to better learn the temporal characteristics of the teacher network and better predict the physical and chemical values of rapeseed. The joint distillation loss L total The expression is:
[0071] L total = α·L[[ID=1⑧]] soft + β·L feature + γ·L temporal,smooth ;
[0072] In the formula, α, β, and γ are the weights of the soft label distillation loss, multi-scale feature distillation loss, and time-domain distillation loss, respectively.
[0073] The adjustment of α, β, and γ is a gradient-based self-regulation process. For each loss term, the change of the gradient or loss value of this term can be monitored. If a certain part of the loss decreases rapidly during training, it means that this part has a greater impact on the training of the student model in the current stage. Therefore, the weight of this part can be appropriately increased. The following update strategy is adopted:
[0074]
[0075] [[ID=۳۷]]
[0076] In the above formula, α(m) and α(m + 1) are the weights of the soft label distillation loss at training epochs m and m + 1, respectively; η is the learning rate, which is used to control the update step size; β(m) and β(m + 1) are the weights of the multi-scale feature distillation loss at training epochs m and m + 1, respectively; γ(m) and γ(m + 1) are the weights of the time-domain distillation loss at training epochs m and m + 1, respectively; denotes taking the partial derivative, is the gradient of each loss term with respect to the hyperparameter, which is used for adaptive adjustment to reach the optimal solution.
[0077] Step S3: Transfer the knowledge of the teacher model to the student model through the joint distillation loss, and use the student model after knowledge transfer to predict the oil content of rapeseed.
[0078] After the distillation process, a large number of redundant modules have been removed from the network structure of the student model, but there is still data redundancy in the channels of some modules. Therefore, in order to reduce the model complexity while maintaining the prediction accuracy as much as possible, the embodiment of the present invention adopts a structured pruning technology based on time-domain information to prune the student model after knowledge transfer. First, evaluate the importance of each channel in the network, and prune the unimportant channels to reduce the computational amount and storage requirements, and restore the model accuracy through fine-tuning training after pruning.
[0079] During the structured pruning process, first evaluate the L1 norm of each channel of the distilled student model. Specifically, calculate the L1 norm of the convolutional channels of each module, and sort each channel according to the magnitude of the L1 norm:
[0080]
[0081] where θ i is the i-th parameter in the network of the student model; C is the number of channels; ||θ||1 represents the L1 norm of the parameter θ.
[0082] Through the L1 norm evaluation, the channels that have little impact on the model output can be identified. As Figure 7 shown, according to the sorting of the L1 norm, select the 10% of the weights and biases with the lowest L1 norm and set them to zero, so as to achieve the pruning operation. After pruning, freeze the network parameters of the pruned part for subsequent fine-tuning training.
[0083] In the fine-tuning training, a loss function design based on transfer learning of time-domain information is adopted. The basic loss function consists of the mean square error MSE loss between the predicted value and the true value. In addition to the MSE loss, a transfer loss is introduced to measure the output difference between the unpruned model and the pruned model. The transfer loss L transfer is calculated as follows:
[0084]
[0085] where y pre-prune,i and y post-prune,i are the predicted values output by the student model before and after pruning, respectively.
[0086] At the same time, in order to better restore the performance of the student model, the time-domain distillation loss of the knowledge distillation part is adopted, and the final training loss function is:
[0087] L student,total= α'L transfer + β'L student,MSE + γ'L temporal,smooth ;
[0088] Wherein, α', β', and γ' are hyperparameters, and the self - adjustment process based on gradients is also used to update α', β', and γ'.
[0089] During the fine - tuning process, the parameters of the pruned part are frozen, and only the remaining network is trained. To prevent overfitting, a smaller learning rate is adopted, and the entire training set is used to train the model. By adjusting the hyperparameters of the remaining network part, an optimal fine - tuned model can be obtained.
[0090] After pruning, the model is evaluated through two key indicators: the model running speed and the prediction accuracy of rapeseed quality. During the pruning process, a step - by - step pruning strategy is adopted. First, 10% pruning is performed, and it is evaluated whether the prediction accuracy of the model meets the usage requirements. If 10% pruning can still maintain a high accuracy, a larger pruning ratio, such as 20%, is attempted until the expected accuracy requirement is reached. After each pruning, fine - tuning training is performed, and the pruning ratio and fine - tuning process are continuously optimized according to the experimental results.
[0091] After fine - tuning the student model, the floating - point model is converted into a low - precision model through quantization technology, further reducing the storage occupancy of the model and accelerating the inference process, making the deep - learning model applicable to edge - computing devices. In the embodiment of the present invention, the student model with 32 - bit floating - point numbers is quantized into 16 - bit floating - point numbers, and the specific steps are as follows:
[0092] For each parameter of the student model, including weights and activation values, scaling and offset are performed to map the parameters to a smaller numerical range:
[0093]
[0094] Wherein, W q , X q are the quantized weight parameters and input features respectively; round() is the quantization function; w and x are the original floating - point parameters without quantization processing; Δw and Δx are the quantization scaling factors.
[0095] The quantized model can perform inference at low precision, significantly reducing the storage occupancy and improving the inference speed.
[0096] A lightweight method for deep learning models for portable rapeseed quality detection proposed in an embodiment of the present invention effectively improves the inference efficiency and storage efficiency of the model while maintaining high accuracy through teacher-student network distillation, structured transfer pruning, and quantization techniques. This method is not only applicable to rapeseed quality prediction but can also be widely applied to other fields of optimizing deep learning models based on near-infrared spectroscopy.
[0097] To evaluate the performance of the model, root mean square error (RMSE) and correlation coefficient (R 2 ) are selected as evaluation metrics to measure the prediction accuracy and fitting effect of the model. And floating point operation count (Flops), number of parameters (Parameters), and computation time are used to evaluate the lightweight degree of the model. Table 1 shows the result comparison between the original student model and the lightweight processed student model.
[0098] Table 1 Model Result Comparison
[0099]
[0100]
[0101] It can be seen from Table 1 that after lightweight processing, the Flops, Parameters, and computation time of the model have all decreased significantly, and at the same time, its prediction accuracy is basically the same as that of the original model.
[0102] As Figure 8 shown, an embodiment of the present invention also provides a lightweight system for deep learning models for portable rapeseed quality detection, including:
[0103] Student model construction module: Design a student model according to the characteristics of the teacher model, reduce the number of model parameters, retain the backbone network, and delete redundant modules.
[0104] Multi-scale feature distillation module: Used to better train the student model. According to the differences between the teacher model and the student model, add distillation loss at multiple scales to make the prediction accuracy of the student model tend to that of the teacher model.
[0105] Structured transfer pruning module: Delete channels with relatively small weight occupancy, and use transfer learning to fine-tune the pruned model to improve the accuracy of the pruned model.
[0106] Quantization module: Reduce the storage volume, reduce the size of the.pt file, and speed up the operation efficiency.
[0107] For the design differences between the student model and the teacher model, the method and system of the embodiments of the present invention adopt a multi-scale feature distillation method based on time domain and wave crest information, enabling the student model to better approximate the prediction accuracy of the teacher model after training. At the same time, the embodiments of the present invention design a time-domain information structured transfer pruning module, which can further accurately delete the channels with smaller weights in the student model, thereby more effectively improving the model running speed. Finally, through quantization processing, the storage requirement of the model is further reduced and the operation of the model is accelerated, ultimately achieving a significant improvement in the operation efficiency of the model on the premise of ensuring the prediction accuracy.
[0108] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above embodiments are described. Only the preferred embodiments of the present invention are expressed. The description is relatively specific and detailed, but it should not be construed as a limitation on the scope of the present invention. As long as there is no contradiction in the combination of these technical features, it should be considered as the scope recorded in this specification.
[0109] It should be noted that for those of ordinary skill in the art, without departing from the concept of the present invention, several modifications and improvements can still be made, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the appended claims.
Claims
1. A lightweight method for a deep learning model of portable rapeseed quality detection, characterized in that, It includes the following steps: Step S1: Construct a teacher model and a student model, and use the teacher model and the student model to extract local peak features and global time-domain features from the near-infrared spectral data of rapeseed. The teacher model and the student model output predicted values of the oil content of rapeseed; Step S2: Construct a joint distillation loss according to the gap between the predicted value output by the student model and the true value, the gap between the predicted values output by the teacher model and the student model, the gap between the local peak features and global time-domain features extracted by the teacher model and the student model, and the gap between the predicted values of each band of the teacher model and the student model; Step S3: Transfer the knowledge of the teacher model to the student model through the joint distillation loss, and use the student model after knowledge transfer to predict the oil content of rapeseed.
2. A lightweight method for a deep learning model for portable rapeseed quality detection according to claim 1, characterized in that: In step S3, the importance of each channel of the student model after knowledge transfer is sorted, and the channels with lower sorting are pruned according to the set pruning ratio.
3. A lightweight method for a deep learning model for portable rapeseed quality detection according to claim 2, characterized in that: Calculate the L1 norm of each channel, and sort the importance of each channel according to the size of the L1 norm.
4. A lightweight method for a deep learning model for portable rapeseed quality detection according to claim 2, characterized in that: In step S3, after pruning the student model after knowledge transfer, take the mean square gap between the predicted values of the student model before and after pruning as the transfer loss, and take the mean square error between the predicted value output by the pruned student model and the true value as the MSE loss. Freeze the parameters of the pruned part, and use the transfer loss, MSE loss, and the gap between the predicted values of each band of the teacher model and the student model before pruning to fine-tune the parameters of the pruned student model.
5. A lightweight method for a deep learning model for portable rapeseed quality detection according to claim 1, characterized in that: In step S1, after the teacher model outputs the predicted value of the oil content of rapeseed, optimize the parameters of the teacher model by minimizing the mean square error loss between the true value and the predicted value of the oil content of rapeseed.
6. A lightweight method for a deep learning model for portable rapeseed quality detection according to claim 1, characterized in that: The joint distillation loss in step S2 includes a soft label distillation loss, a multi-scale feature distillation loss, and a time-domain distillation loss. The expression of the joint distillation loss is: L total = α·L soft + β·L feature + γ·L temporal,smooth ; where L total is the joint distillation loss; L soft is the soft label distillation loss; L feature is the multi-scale feature distillation loss; L temporal,smooth is the time-domain distillation loss; α, β, and γ are the weights of the soft label distillation loss, the multi-scale feature distillation loss, and the time-domain distillation loss, respectively.
7. A lightweight method for a deep learning model for portable rapeseed quality detection according to claim 6, characterized in that: In step S2, take the gap between the local peak features and global time-domain features extracted by the teacher model and the student model as the multi-scale feature distillation loss. The expression of the multi-scale feature distillation loss is: Where, L feature is the multi-scale feature distillation loss; N is the number of samples of the near-infrared spectral data of rapeseed; w shallow (i) is the relative intensity between the peak and the noise of the i-th sample data; are the local peak features extracted by the student model and the teacher model respectively; T shallow 、T deep are temperature parameters; w deep (i) is the average change trend of the i-th sample data; are the global time-domain features extracted by the student model and the teacher model respectively; represents the calculation of the L2 norm; are the spectral values of curve i at the t-th point and the (t-1)-th point respectively; Signal is the wave peak; Noise is the noise; is the peak value of curve i; is the standard deviation of the baseline region of curve i.
8. A lightweight method for a deep learning model for portable rapeseed quality detection according to claim 6, characterized in that: In S2, take the gap between the predicted values of each band of the teacher model and the student model as the time-domain distillation loss. The expression of the time-domain distillation loss is: Where L temporal,smooth is the time-domain distillation loss; t is; N is the number of samples of the near-infrared spectral data of rapeseed; are the predicted values of the student model and the teacher model at band t, respectively; T t is the temperature parameter at band t.
9. A lightweight method for a deep learning model for portable rapeseed quality detection according to claim 6, characterized in that: In step S3, when transferring the knowledge of the teacher model to the student model through the joint distillation loss, update α, β, and γ in each training cycle: In the above formula, α(m) and α(m + 1) are the weights of the soft label distillation loss at training cycles m and m + 1 respectively; η is the learning rate; β(m) and β(m+1) are the weights of the multi-scale feature distillation loss at training epochs m and m+1 respectively; γ(m) and γ(m+1) are the weights of the temporal distillation loss at training epochs m and m+1 respectively; denotes taking the partial derivative.
10. A lightweight method for a deep learning model for portable rapeseed quality detection according to claim 1, characterized in that: In step S3, quantize the parameters of the student model after knowledge transfer, and map all parameters of the student model to a smaller numerical range. The expression of the quantization is: Where, W q and X q are the quantized weight parameter and input feature respectively; round() is the quantization function; w and x are the original floating-point parameters without quantization processing; Δw and Δx are quantization scaling factors.
Citation Information
Patent Citations
Maize seed variety identification method and system based on hyperspectrum incremental updating
CN116071592A
Tobacco near infrared spectrum standardization model and application
CN118050330A
Lightweight image classification neural network architecture system based on knowledge distillation
CN119514594A
KR20240048056A
Cited By
AI model distillation migration edge deployment method of cross-chip architecture
CN121029189A
An AI model distillation migration edge deployment method across a chip architecture
CN121029189B
