Rose stem segmentation and measurement method based on knowledge distillation
Through the knowledge-based distillation method, the accuracy and speed of rose stem segmentation are improved by using industrial cameras and attention distillation technology, the problem of low accuracy and time-consuming in the existing technology is solved, and the economic benefits of farmers are increased.
Patent Information
- Application Number
- CN202211693058.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-28
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2042-12-28
AI Technical Summary
The existing rose stem segmentation technology is not accurate and takes a long time, resulting in uneven grading and affecting the economic interests of farmers.
The rose stem segmentation and measurement method based on knowledge distillation is adopted, and images are collected through industrial cameras, attention distillation and channel attention distillation are combined to enhance student network training, and segmentation is performed using a simple structure ResNet18 network, a dual hidden layer fully connected neural network is introduced to improve edge segmentation accuracy, and the stem diameter is measured in the middle part.
It improves the accuracy and speed of the splitting of rose stems, reduces the segmentation reasoning time, and improves sorting output and economic benefits.
Smart Images

Figure CN116152281B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of semantic segmentation and knowledge distillation, and in particular to a rose stem segmentation and measurement method based on knowledge distillation. Background Art
[0002] Grading roses after harvesting ensures high quality and high prices, maximizing farmers' profits. Accurate rose grading generally relies on multiple criteria, such as flower head size, color depth, and stem thickness and length. Stem thickness is a key grading factor. Currently, rose growers sort roses based solely on personal intuition and experience. This results in varying stem thicknesses within the same category, further compounding the unevenness after packaging. This reduces the competitiveness of rose products and harms farmers' economic interests.
[0003] As computer vision technology matures, intelligent sorting becomes possible. Deep convolutional neural networks have achieved great success in many fields, including image classification, target detection, and semantic segmentation, providing an effective approach for rose head segmentation and high-precision stem segmentation. Compared with existing semantic segmentation research, the determination of stem thickness requires higher semantic segmentation accuracy. However, classic semantic segmentation lacks high edge accuracy and exhibits obvious aliasing. To improve the accuracy and robustness of semantic segmentation, it is often necessary to utilize deeper convolutional neural networks to enhance feature extraction capabilities. However, these segmentation networks have complex structures, numerous parameters, and large model sizes, requiring a large amount of inference and computation time. For pipeline sorting, speed equals output and economic efficiency. Therefore, a lightweight and high-precision segmentation model has emerged. The present invention proposes a rose stem segmentation and measurement method based on knowledge distillation. While improving the segmentation accuracy of rose stems, it significantly reduces segmentation inference time, speeds up the sorting speed of the pipeline, increases sorting output, and increases economic efficiency. Summary of the Invention
[0004] The purpose of this invention is to overcome the problems of time-consuming and low precision of existing segmentation technologies. A rose stem segmentation and measurement method based on knowledge distillation is proposed, which can accelerate the segmentation speed and accuracy, thereby obtaining a more accurate rose stem diameter, further improving the grading of roses and increasing farmers' income.
[0005] To achieve the above objectives, the present invention provides a technical solution: a rose stem segmentation and measurement method based on knowledge distillation, comprising the following steps:
[0006] 1) Using an industrial camera to capture images of rose stems on an assembly line at a fixed shooting distance, the captured images are randomly divided into a training set and a test set. The stem and background regions in the rose stem images are manually labeled to determine the stem and background regions, thus creating a rose stem image segmentation dataset.
[0007] 2) Select a large feature extraction network as the basic network of the teacher network. After multi-layer feature fusion of the feature pyramid FPN, input it into the coarse segmentation prediction head and the edge fine segmentation prediction head. Use the dataset constructed in step 1) to train the teacher network to obtain a trained teacher network.
[0008] 3) A feature extraction network with a simple structure and few parameters is selected as the basic network of the student network. The segmentation framework of the student network is the same as that of the teacher network.
[0009] 4) Use key pixel attention distillation and channel attention distillation to strengthen the teacher network's guidance training of the student network. Use the dataset constructed in step 1) to train the student network and obtain a trained student network.
[0010] 5) Using the student network trained in step 4), segment the rose stem image to obtain a rose stem contour image. The contour image is binarized and rotationally corrected. Then, the intercepts of multiple contours are read in the middle of the contour image. The average of these intercepts is taken and multiplied by the pixel precision to measure the rose stem diameter.
[0011] Furthermore, the step 1) includes the following:
[0012] An industrial camera is selected as the image acquisition device. The lens focal length and fixed shooting distance are adjusted and recorded. The captured image resolution is 2048*2048px. The fixed shooting distance and camera parameters can be used to determine the actual physical resolution of a pixel in the captured image. The specific calculation formula is as follows:
[0013]
[0014] Where p refers to the actual physical resolution of a pixel, d refers to the fixed shooting distance, h refers to the length of the camera CDD, f refers to the focal length of the lens, and x refers to the horizontal resolution of the image;
[0015] 5000 clear rose stem images were selected and randomly divided into training set and test set in the ratio of 8:2. The stem outlines in the images were manually marked using the labelme tool to determine the stem area and background area, thus creating a rose stem image segmentation dataset.
[0016] Further, the step 2) includes the following contents:
[0017] The teacher network selects a large feature extraction network with complex network structure, many parameters and good performance. Specifically, ResNet101 is used as the backbone network, and feature pyramid FPN is used for multi-layer feature fusion.
[0018] Rough segmentation prediction head: Classify pixels on the high-density feature P4 output by FPN, directly upsample to the same size as the image using the bilinear interpolation algorithm, and output the coarse prediction segmentation result;
[0019] The edge segmentation prediction head consists of two independent double-hidden layers in a fully connected neural network. It selects pixels with similar probabilities of being predicted as foreground and background from the coarse prediction segmentation results. It is represented as follows:
[0020] |p R -p B |≤0.2
[0021] Where p R is the probability of being predicted as a prospect, p B is the probability of being predicted as background;
[0022] Because the probabilities of these pixels being predicted as foreground and background are close, it means that these pixels are likely to be boundary points. The coarse prediction segmentation results of these points and the feature vectors corresponding to these points on the P3 layer of the FPN output are fused into a feature point map as a sample, and a double-hidden layer fully connected neural network is trained, in which the activation function is ReLU. These points are re-predicted, and the original coarse prediction segmentation results are replaced with the new prediction results as the fine prediction segmentation results. Then, in the fine prediction segmentation results, those pixels with close foreground and background probabilities are selected again. The fine prediction segmentation results of these points and the feature vectors corresponding to these points on the P2 layer of the FPN output are fused into a feature point map as a new sample, and a new double-hidden layer fully connected neural network is trained. These points are re-predicted again, and the fine prediction results are replaced with the new prediction results. Finally, the bilinear interpolation algorithm is used to upsample to the size consistent with the expected output image size, and output as the fine prediction result.
[0023] Construct a loss function. For the pixel binary classification process, use the pixel-by-pixel cross entropy loss function in the rough segmentation prediction, and use sigmoid as the activation function. The specific loss function is as follows:
[0024] L coarse =-[y·log(p)+(1-y)·log(1-p)]
[0025] Where, L coarse Represents the rough segmentation loss, y represents the true label of the sample, the foreground is 1, the background is 0, and p represents the probability that the sample is predicted to be the foreground;
[0026] In edge segmentation prediction, the cross entropy loss function used is as follows:
[0027]
[0028] Where, L fine represents the edge segmentation loss, N represents the number of uncertain points taken, y i Indicates the true label of sample point i, the foreground is 1, the background is 0, and p i is the probability that sample point i is predicted as the foreground;
[0029] The teacher network is trained using the training set until the loss curve stabilizes and no longer decreases. The teacher network with the best performance in the test set is selected as the final teacher network for rose stem segmentation.
[0030] Further, the step 3) includes the following contents:
[0031] In order to ensure the real-time segmentation of rose stems, the student network selected a feature extraction network with a simple structure and few parameters, specifically using ResNet18 as the backbone network;
[0032] The framework is the same as that of the teacher network. After FPN feature fusion, it is input into the coarse segmentation prediction head and the edge fine segmentation prediction head.
[0033] Further, the step 4) includes the following contents:
[0034] In order to enable the student network to better learn the feature extraction ability of the teacher network, key pixel point attention distillation and channel attention distillation are used to strengthen the guidance training of the teacher network on the student network, so that the key pixel point attention feature map and channel attention feature map of the student network are closer in content to the key pixel point attention feature map and channel attention feature map of the teacher network. The key pixel point attention feature map and channel attention feature map are first calculated, and then the key pixel point attention mask feature map and channel attention mask feature map are calculated;
[0035] The calculation formulas for the key pixel attention feature map and channel attention feature map are as follows:
[0036]
[0037]
[0038] Where G S represents the key pixel attention feature map, C represents the total number of channels, and F c represents the feature map of the c-th channel, G CRepresents the channel attention feature map, H and W represent the height and width of the feature map respectively, and F h,w A feature point map representing the pixel at the image coordinate point (h, w);
[0039] The calculation formulas for the key pixel attention mask feature map and the channel attention mask feature map are as follows:
[0040] A S =H·W·softmax(G S / T)
[0041] A C =C softmax(G C / T)
[0042] Where A S Represents the key pixel attention mask feature map, A C represents the channel attention mask feature map, T is the hyperparameter temperature;
[0043] The attention loss function is used to make the student network simulate the key pixel attention feature map and channel attention feature map of the teacher network. The attention loss function formula of the student network is as follows:
[0044]
[0045] Where, L att Indicates loss of attention, Represents the key pixel attention feature maps of the teacher network and the student network respectively, Represent the channel attention feature maps of the teacher network and the student network respectively, Represents the key pixel attention mask feature maps of the teacher network and the student network respectively, Represent the channel attention mask feature maps of the teacher network and the student network respectively, L1 represents the L1 regularization function, L2 represents the L2 regularization function, β1 and β2 are hyperparameters;
[0046] In order to improve the ability of the student network to separate the foreground and background of the stems and better learn the key information of the teacher network, the feature loss formula of the student network is as follows:
[0047]
[0048]
[0049] Where, L feature represents feature loss, R and B represent foreground and background areas respectively, and H R 、W R Respectively represent the height and width of the rectangular frame surrounding the foreground area, Represents the key pixel mask feature point map at the image coordinate point (m,n), represents the attention mask feature map of the c-th channel, Represents the feature point map at the c-th channel image coordinate point (m,n) in the teacher network, Represents the feature point map at the c-th channel image coordinate point (m, n) in the student network, Φ() represents the Convert to The adaptive layer operates with the same dimensions, and α1 and α2 are hyperparameters that balance the loss between foreground and background;
[0050] The knowledge distillation loss function of the student network is:
[0051] L kd =L feature +L att
[0052] Where, L kd represents the knowledge distillation loss;
[0053] The total loss function of student network training is as follows:
[0054] L total =L coarse +L fine +L kd
[0055] Where, L total Expressed as the total loss of the student network;
[0056] Use the training set to train the student network. total When the curve stabilizes and no longer decreases, training is stopped; the network with the best performance on the test set is selected as the final student network for rose stem segmentation.
[0057] Further, the step 5) includes the following steps:
[0058] 5.1) Using the student network obtained in step 4), segment the rose stem image to obtain a binary image of the stem outline;
[0059] 5.2) Find the main axis of the stem region in the binary image and rotate it so that the main axis of the stem is parallel to the vertical direction;
[0060] 5.3) After rotation, find the maximum value of the vertical coordinate Y in the stem profile max With the minimum value Y min , the length range of the contour in the vertical direction is: Y max -Y min, take the middle fifth of the section as the stem diameter sampling interval, introduce five straight lines perpendicular to the main axis at equal intervals in this interval, obtain the intercepts of these five straight lines with the stem outline, and take the average of these five intercepts as the pixel width of the stem outline. Multiply the average by the actual physical resolution of each pixel to get the stem diameter:
[0061] diam=p·avg
[0062] Where diam is the desired rose stem diameter, p represents the actual physical resolution of each pixel, and avg represents the average value of the intercept.
[0063] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0064] 1. The present invention uses a high-precision industrial camera to capture images at a fixed shooting distance to obtain images with more accurate distance information.
[0065] 2. In the knowledge distillation algorithm, the present invention proposes key pixel point attention distillation and channel attention distillation to strengthen the guidance and training of the teacher network on the student network. While the student network maintains consistency with the teacher network in terms of accuracy, the student network has a smaller weight and runs faster, which can speed up the operation of the pipeline and improve the sorting output of roses.
[0066] 3. The present invention introduces two double-hidden-layer fully connected neural networks in the edge fine segmentation prediction head. In the face of fuzzy pixel prediction, it proposes to fuse the feature vectors corresponding to the deep feature coarse prediction segmentation result and the feature map output by FPN into a feature point map, and then uses the double-hidden-layer fully connected neural network training and reclassification method to greatly improve the segmentation accuracy of the rose stem edge.
[0067] 4. When calculating the stem diameter of a rose, the present invention uses the middle 1 / 5 of the segmented image as the sampling interval, which reduces the influence of occlusion by petals or leaves and improves the actual measurement accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] Figure 1 It is a logical flow diagram of the present invention.
[0069] Figure 2 : is a network structure diagram of the present invention; in the figure, MLP1 and MLP2 represent two independent double-hidden layer fully connected neural networks.
[0070] Figure 3This is the result diagram after image acquisition and each step of processing in the present invention; in the figure, a is the original image taken by the camera, b is a screenshot of the rose stem, c is a screenshot of the binary contour image after the rose stem is segmented by the student network, d is a screenshot of the feature vector of the contour image, e is a screenshot of the corrected contour image, f is the sampling interval of the rose stem diameter, where d1, d2, ..., d5 are the corresponding intercepts, and g is the segmentation result image without using the fine segmentation prediction head, which has relatively obvious jagged edges. DETAILED DESCRIPTION
[0071] The present invention will be described in further detail below with reference to the embodiments and drawings, but the embodiments of the present invention are not limited thereto.
[0072] like Figures 1 to 3 As shown, this embodiment provides a rose stem segmentation and measurement method based on knowledge distillation, the details of which are as follows:
[0073] 1) Use an industrial camera to capture images of rose stems on an assembly line at a fixed shooting distance. The captured images are randomly divided into a training set and a test set. The stem and background regions in the rose stem images are manually labeled to determine the stem and background regions, and a rose stem image segmentation dataset is created. The details are as follows:
[0074] A Hikvision industrial camera model MV-CS050-10GC and lens model MVL-MF0828M-35MP were selected as image acquisition devices. The camera CDD is 8.8 mm long and 6.6 mm wide, the lens focal length is 35 mm, and the captured image resolution is 2048*2048 px. The fixed shooting distance means that the lens is placed 100.0 mm above the flower stand on the assembly line. The actual physical resolution of a pixel in the captured image can be determined using the fixed shooting distance and camera parameters. Theoretically, the resolution of each pixel is 0.018 mm. The specific calculation formula is:
[0075]
[0076] Where p refers to the precision value of one pixel, d refers to the distance from the lens to the flower stand on the assembly line, h refers to the length of the camera CDD, f refers to the focal length of the camera, and x refers to the horizontal resolution of the image;
[0077] 5000 clear rose stem images were selected and randomly divided into training set and test set in the ratio of 8:2. The stem outlines in the images were manually marked using the labelme tool to determine the stem area and background area, thus creating a rose stem image segmentation dataset.
[0078] 2) Select a large feature extraction network as the basic network of the teacher network. After multi-layer feature fusion of the feature pyramid FPN, input it into the coarse segmentation prediction head and the edge fine segmentation prediction head. Use the dataset constructed in step 1) to train the teacher network to obtain the trained teacher network. The details are as follows:
[0079] The teacher network selects a large-scale feature extraction network with complex network structure, numerous parameters and good performance, such as ResNet101 as the backbone network, and uses the feature pyramid (FPN) to perform multi-layer feature fusion;
[0080] Rough segmentation prediction head: Classify pixels on the high-density feature P4 output by FPN, directly upsample to the same size as the image using a bilinear algorithm, and output a rough segmentation result;
[0081] The edge segmentation prediction head consists of two independent double-hidden layers in a fully connected neural network. It selects pixels with similar probabilities of being predicted as foreground and background from the coarse prediction segmentation results. It is represented as follows:
[0082] |p R -p B |≤0.2
[0083] Where p R is the probability of being predicted as a prospect, p B is the probability of being predicted as background;
[0084] Because the probabilities of these pixels being predicted as foreground and background are close, it means that these pixels are likely to be boundary points. The coarse prediction segmentation results of these points and the feature vectors corresponding to these points on the P3 layer of the FPN output are fused into a feature point map as a sample, and a double-hidden layer fully connected neural network is trained, in which the activation function is ReLU. These points are re-predicted, and the original coarse prediction segmentation results are replaced with the new prediction results as the fine prediction segmentation results. Then, in the fine prediction segmentation results, those pixels with close foreground and background probabilities are selected again. The fine prediction segmentation results of these points and the feature vectors corresponding to these points on the P2 layer of the FPN output are fused into a feature point map as a new sample, and a new double-hidden layer fully connected neural network is trained. These points are re-predicted again, and the fine prediction results are replaced with the new prediction results. Finally, the bilinear interpolation algorithm is used to upsample to the size consistent with the expected output image size, and output as the fine prediction result.
[0085] Construct a loss function. This example is a pixel-by-pixel binary classification process. In the rough segmentation prediction, the pixel-by-pixel cross entropy loss function is used, and sigmoid is used as the activation function. The specific loss function is as follows:
[0086] L coarse=-[y·log(p)+(1-y)·log(1-p)]
[0087] Where, L coarse Represents the rough segmentation loss, y represents the true label of the sample, the foreground is 1, the background is 0, and p represents the probability that the sample is predicted to be the foreground;
[0088] In edge segmentation prediction, the cross entropy loss function used is as follows:
[0089]
[0090] Where, L fine represents the edge segmentation loss, N represents the number of uncertain points taken, y i Indicates the true label of sample point i, the foreground is 1, the background is 0, and p i is the probability that sample point i is predicted as the foreground;
[0091] The teacher network is trained using the training set until the loss curve stabilizes and no longer decreases. The teacher network with the best performance in the test set is selected as the final teacher network for rose stem segmentation.
[0092] 3) A feature extraction network with a simple structure and few parameters is selected as the basic network of the student network. The segmentation framework of the student network is the same as that of the teacher network, as follows:
[0093] In order to ensure the real-time segmentation of rose stems, the student network selects a feature extraction network with simple structure and few parameters, such as ResNet18, as the backbone network;
[0094] The framework is the same as that of the teacher network. After FPN feature fusion, it is input into the coarse segmentation prediction head and the edge fine segmentation prediction head.
[0095] 4) Use key pixel attention distillation and channel attention distillation to strengthen the teacher network's guidance training of the student network. Use the dataset constructed in step 1) to train the student network and obtain the trained student network. The details are as follows:
[0096] In order to enable the student network to better learn the feature extraction ability of the teacher network, the present invention proposes to use key pixel point attention distillation and channel attention distillation to strengthen the guidance training of the teacher network on the student network, so that the key pixel point attention feature map and channel attention feature map of the student network are closer in content to the key pixel point attention feature map and channel attention feature map of the teacher network. The key pixel point attention feature map and channel attention feature map are first calculated, and then the key pixel point attention mask feature map and channel attention mask feature map are calculated.
[0097] The calculation formulas for the key pixel attention feature map and channel attention feature map are as follows:
[0098]
[0099]
[0100] Where G S represents the key pixel attention feature map, C represents the total number of channels, and F c represents the feature map of the c-th channel, G C Represents the channel attention feature map, H and W represent the height and width of the feature map respectively, and F h,w A feature point map representing the pixel at the image coordinate point (h, w);
[0101] The calculation formulas for the key pixel attention mask feature map and the channel attention mask feature map are as follows:
[0102] A S =H·W·softmax(G S / T)
[0103] A C =C softmax(G C / T)
[0104] Where A S Represents the key pixel attention mask feature map, A C represents the channel attention mask feature map, T is the hyperparameter temperature;
[0105] The attention loss function is used to make the student network simulate the key pixel attention feature map and channel attention feature map of the teacher network. The attention loss function formula of the student network is as follows:
[0106]
[0107] Where, L att Indicates loss of attention, Represents the key pixel attention feature maps of the teacher network and the student network respectively, Represent the channel attention feature maps of the teacher network and the student network respectively, Represents the key pixel attention mask feature maps of the teacher network and the student network respectively, Represent the channel attention mask feature maps of the teacher network and the student network respectively, L1 represents the L1 regularization function, L2 represents the L2 regularization function, β1 and β2 are hyperparameters, specifically 0.6 and 0.4 respectively;
[0108] In order to improve the ability of the student network to separate the foreground and background of the stems and better learn the key information of the teacher network, the feature loss formula of the student network is as follows:
[0109]
[0110]
[0111] Where, L feature represents feature loss, R and B represent foreground and background areas respectively, and H R 、W R Respectively represent the height and width of the rectangular frame surrounding the foreground area, Represents the key pixel mask feature point map at the image coordinate point (m,n), represents the attention mask feature map of the c-th channel, Represents the feature point map at the c-th channel image coordinate point (m,n) in the teacher network, Represents the feature point map at the c-th channel image coordinate point (m, n) in the student network, Φ() represents the Convert to The adaptive layer operates with the same dimensions. α1 and α2 are hyperparameters that balance the loss between foreground and background, and are 0.5 and 0.5 respectively.
[0112] The knowledge distillation loss function of the student network is:
[0113] L kd =L feature +L att
[0114] Where, L kd represents the knowledge distillation loss;
[0115] The total loss function of student network training is as follows:
[0116] L total =L coarse +L fine +L kd
[0117] Where, L total Denoted as the total loss of the student network.
[0118] Use the training set to train the student network. total When the curve stabilizes and no longer decreases, training is stopped; the student network with the best performance in the test set is selected as the final student network for rose stem segmentation.
[0119] 5) Use the student network trained in step 4) to segment the rose stem image to obtain a rose stem contour image. Binarize and rotation-correct the contour image. Then, read the intercepts of multiple contours in the middle of the contour image. Take the average of these intercepts and multiply it by the pixel precision to measure the rose stem diameter, as follows:
[0120] 5.1) Using the student network obtained in step 4), segment the rose stem image to obtain a binary image of the stem outline;
[0121] 5.2) Find the main axis of the stem region in the binary image and rotate it so that the main axis of the stem is parallel to the vertical direction;
[0122] 5.3) After rotation, find the maximum value of the vertical coordinate Y in the stem profile max With the minimum value Y min , the length range of the contour in the vertical direction is: Y max -Y min , take the middle fifth of the stem diameter as the sampling interval, and introduce 5 straight lines perpendicular to the main axis direction at equal intervals in this interval, namely: Get the intercepts of these five straight lines with the stem outline respectively, take the average value avg of these five values as the pixel width of the stem outline, and multiply the average value by the precision p of each pixel to get the diameter of the stem:
[0123] diam=p·avg
[0124] Where diam is the desired rose stem diameter, p represents the actual physical resolution of each pixel, and avg represents the average value of the intercept, in mm.
[0125] Table 1 compares various methods with their corresponding results. As shown in Table 1, the use of key pixel point attention distillation and channel attention distillation to strengthen the guidance training of the teacher network on the student network increases the accuracy by 1.27 percentage points compared with ordinary distillation; when dealing with incorrectly classified points, the introduction of fine prediction segmentation improves the segmentation accuracy by 2.75 percentage points.
[0126] Table 1 Comparison of model results
[0127]
[0128] The above embodiments are preferred implementation modes of the present invention, but the implementation modes of the present invention are not limited to the above embodiments. Any other changes, modifications, substitutions, combinations, and simplifications that do not deviate from the spirit and principles of the present invention should be considered as equivalent replacement methods and are included in the scope of protection of the present invention.
Claims
1. A rose stem segmentation and measurement method based on knowledge distillation, characterized in that: The following steps are involved: 1) Using an industrial camera to capture images of rose stems on an assembly line at a fixed shooting distance, the captured images are randomly divided into a training set and a test set. The stem and background regions in the rose stem images are manually labeled to determine the stem and background regions, thus creating a rose stem image segmentation dataset. 2) Select a large feature extraction network as the basic network of the teacher network. After multi-layer feature fusion of the feature pyramid FPN, input it into the coarse segmentation prediction head and the edge fine segmentation prediction head. Use the dataset constructed in step 1) to train the teacher network to obtain a trained teacher network. Rough segmentation prediction head: Classify pixels on the high-density feature P4 output by FPN, directly upsample to the same size as the image using the bilinear interpolation algorithm, and output the coarse prediction segmentation result; The edge segmentation prediction head consists of two independent double-hidden layers in a fully connected neural network. It selects pixels with similar probabilities of being predicted as foreground and background from the coarse prediction segmentation results. It is represented as follows: |p R -p B |≤0.2 Where p R is the probability of being predicted as a prospect, p B is the probability of being predicted as background; 3) Select the feature extraction network as the base network of the student network, and the segmentation framework of the student network is the same as that of the teacher network; 4) Use key pixel attention distillation and channel attention distillation to strengthen the teacher network's guidance training of the student network. Use the dataset constructed in step 1) to train the student network and obtain a trained student network. 5) Using the student network trained in step 4), segment the rose stem image to obtain a rose stem contour image. The contour image is binarized and rotationally corrected. Then, the intercepts of multiple contours are read in the middle of the contour image. The average of these intercepts is taken and multiplied by the pixel precision to measure the rose stem diameter.
2. The rose stem segmentation and measurement method based on knowledge distillation according to claim 1, characterized in that: The step 1) includes the following contents: An industrial camera is selected as the image acquisition device. The lens focal length and fixed shooting distance are adjusted and recorded. The captured image resolution is 2048*2048px. The fixed shooting distance and camera parameters can be used to determine the actual physical resolution of a pixel in the captured image. The specific calculation formula is as follows: Where p refers to the actual physical resolution of a pixel, d refers to the fixed shooting distance, h refers to the length of the camera CDD, f refers to the focal length of the lens, and x refers to the horizontal resolution of the image; 5000 clear rose stem images were selected and randomly divided into training set and test set in the ratio of 8:
2. The stem outlines in the images were manually marked using the labelme tool to determine the stem area and background area, thus creating a rose stem image segmentation dataset.
3. The rose stem segmentation and measurement method based on knowledge distillation according to claim 2, characterized in that: The step 2) includes the following contents: The teacher network uses ResNet101 as the backbone network and uses feature pyramid FPN for multi-layer feature fusion; The coarse prediction segmentation results of the pixels with similar foreground and background probabilities and the feature vectors corresponding to these pixels on the P3 layer of the FPN output are fused into a feature point map as a sample, and a double-hidden layer fully connected neural network is trained, in which the activation function is ReLU. These pixels are re-predicted and the original coarse prediction segmentation results are replaced with the new prediction results as the fine prediction segmentation results. Then, the pixels with similar foreground and background probabilities are selected from the fine prediction segmentation results. The fine prediction segmentation results of these points and the feature vectors corresponding to these pixels on the P2 layer of the FPN output are fused into a feature point map as a new sample. A new double-hidden layer fully connected neural network is trained, and these pixels are re-predicted again, and the fine prediction results are replaced with the new prediction results. Finally, the bilinear interpolation algorithm is used to upsample to the size consistent with the expected output image size and output as the fine prediction result. Construct a loss function. For the pixel binary classification process, use the pixel-by-pixel cross entropy loss function in the rough segmentation prediction, and use sigmoid as the activation function. The specific loss function is as follows: L coarse =-[y·log(p)+(1-y)·log(1-p)] Where, L coarse Represents the rough segmentation loss, y represents the true label of the sample, the foreground is 1, the background is 0, and p represents the probability that the sample is predicted to be the foreground; In edge segmentation prediction, the cross entropy loss function used is as follows: Where, L fine represents the edge segmentation loss, N represents the number of uncertain points taken, y i Indicates the true label of sample point i, the foreground is 1, the background is 0, and p i is the probability that sample point i is predicted as the foreground; The teacher network is trained using the training set until the loss curve stabilizes and no longer decreases. The teacher network with the best performance in the test set is selected as the final teacher network for rose stem segmentation.
4. The rose stem segmentation and measurement method based on knowledge distillation according to claim 3, characterized in that: The step 3) includes the following contents: To ensure the real-time segmentation of rose stems, the student network uses ResNet18 as the backbone network; The framework is the same as that of the teacher network. After FPN feature fusion, it is input into the coarse segmentation prediction head and the edge fine segmentation prediction head.
5. The rose stem segmentation and measurement method based on knowledge distillation according to claim 4, characterized in that: The step 5) comprises the following steps: 5.1) Using the student network obtained in step 4), segment the rose stem image to obtain a binary image of the stem outline; 5.2) Find the main axis of the stem region in the binary image and rotate it so that the main axis of the stem is parallel to the vertical direction; 5.3) After rotation, find the maximum value of the vertical coordinate Y in the stem profile max With the minimum value Y min , the length range of the contour in the vertical direction is: Y max -Y min , take the middle fifth of the section as the stem diameter sampling interval, introduce five straight lines perpendicular to the main axis at equal intervals in this interval, obtain the intercepts of these five straight lines with the stem outline, and take the average of these five intercepts as the pixel width of the stem outline. Multiply the average by the actual physical resolution of each pixel to get the stem diameter: diam=p·avg Where diam is the desired rose stem diameter, p represents the actual physical resolution of each pixel, and avg represents the average value of the intercept.
Citation Information
Patent Citations
Image data processing method and device, equipment and medium
CN113822314A
Power transmission channel engineering vehicle target detection method and system based on knowledge distillation
CN115131747A