Method, device, electronic device and medium for detecting heat-damaged corn kernels
The CycleGAN network model is used to convert heat-damaged corn images into ordinary images, and combined with the IFSNet or UNet network model, the ordinary corn labels are used to train the heat-damaged segmentation model, which solves the problem of low segmentation accuracy of heat-damaged corn and achieves high-precision corn kernel identification. and segmentation.
Patent Information
- Application Number
- CN202410942654.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2044-07-15
AI Technical Summary
Existing technologies are difficult to effectively identify and segment heat-damaged corn kernels, mainly due to the lack of large-scale heat damage semantic segmentation data sets and the unclear features of corn heat-damage images, resulting in low segmentation accuracy.
The CycleGAN network model is used to convert the heat-damaged corn detection pictures into ordinary corn detection pictures, and the pre-trained heat-damaged corn semantic segmentation model is used to perform segmentation through the IFSNet or UNet network model, and the ordinary corn segmentation label map is used for training to achieve the goal without A suitable heat-damaged corn segmentation model is trained under the condition of large-scale heat damage labels.
The segmentation accuracy of heat-damaged corn kernels is improved. Through feature fusion learning and domain transfer technology, high-precision identification and segmentation of corn kernels can be achieved without the need for large-scale heat damage data sets.
Smart Images

Figure CN118506008B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image target detection, and in particular to a method, device, electronic equipment and medium for detecting heat-damaged corn grains. Background Art
[0002] Corn is an important crop, and corn kernels are susceptible to heat damage, which affects yield and quality. In related technologies, a fusion identification method using multispectral imaging data of near-infrared and visible light can identify corn kernels with heat damage, but the data acquisition method of this method is complex and cannot be automated.
[0003] With the development of deep learning, the semantic segmentation model can be used to quickly segment corn kernels. However, most of the data in the semantic segmentation corn dataset are ordinary corn images. There is a lack of large-scale corn heat damage semantic segmentation datasets, which makes it difficult to directly train a semantic segmentation model for heat damaged corn. In addition, the features of corn heat damage images are not obvious, which increases the difficulty of segmenting heat damaged corn and makes it impossible to accurately segment corn heat damage images. Summary of the invention
[0004] Based on this, it is necessary to provide a method, device, electronic equipment and medium for detecting heat-damaged corn kernels that can improve the segmentation accuracy of heat-damaged corn kernels in response to the above-mentioned technical problems.
[0005] A method for detecting heat-damaged corn kernels, comprising:
[0006] Inputting the heat-damaged corn detection picture into a pre-trained CycleGAN network model for processing to obtain a common corn detection picture corresponding to the heat-damaged corn detection picture;
[0007] Input data is determined in the heat-damaged corn detection picture and the ordinary corn detection picture, and the input data is input into a pre-trained heat-damaged corn semantic segmentation model for processing to obtain a heat-damaged corn segmentation map; the heat-damaged corn semantic segmentation model is trained using the ordinary corn segmentation label map as label data.
[0008] In the above scheme, the semantic segmentation model of heat-damaged corn is an IFSNet network model or a UNet network model, wherein the input data of the IFSNet network model is the heat-damaged corn detection picture and the ordinary corn detection picture; the input data of the UNet network model is the ordinary corn detection picture.
[0009] In the above scheme, when the heat-damaged corn semantic segmentation model is an IFSNet network model, the training process of the heat-damaged corn semantic segmentation model includes:
[0010] Inputting the common corn sample picture into the pre-trained CycleGAN network model to generate the heat-damaged corn sample picture;
[0011] The IFSNet network model is trained according to the common corn sample picture, the common corn segmentation label picture corresponding to the common corn sample picture, and the heat-damaged corn sample picture to obtain a first predicted segmentation picture;
[0012] Calculating a first loss function value according to the first predicted segmentation map and the common corn segmentation label map;
[0013] The gradient is returned according to the first loss function value, and the next model training of the IFSNet network model is continued until the training is completed.
[0014] In the above scheme, when the heat-damaged corn semantic segmentation model is a UNet network model, the training process of the heat-damaged corn semantic segmentation model includes:
[0015] The UNet network model is trained according to the common corn sample picture and the common corn segmentation label picture corresponding to the common corn sample picture to obtain a second predicted segmentation picture;
[0016] Calculating a second loss function value according to the second predicted segmentation map and the common corn segmentation label map;
[0017] The gradient is returned according to the second loss function value, and the next model training of the UNet network model is continued until the training is completed.
[0018] In the above scheme, the training process of the CycleGAN network model includes:
[0019] Inputting the common corn sample picture into the first generator to obtain a first conversion picture, and inputting the heat-damaged corn sample picture into the second generator to obtain a second conversion picture;
[0020] Input the common corn sample image and the second conversion image into a first discriminator to obtain a first discrimination result, and input the heat-damaged corn sample image and the first conversion image into a second discriminator to obtain a second discrimination result;
[0021] Inputting the first conversion image to the second generator to obtain a third conversion image, and inputting the second conversion image to the first generator to obtain a fourth conversion image;
[0022] Calculating a third loss function value according to the first discrimination result, the second discrimination result, the first conversion picture, the second conversion picture, the third conversion picture, and the fourth conversion picture;
[0023] Gradients are propagated back according to the third loss function value, and the next model training of the CycleGAN network model is continued until the training is completed.
[0024] In the above scheme, before inputting the heat damaged corn detection picture into the pre-trained CycleGAN network model for processing, the method includes:
[0025] The corn heat damage detection image is scaled to a heat damage corn detection image of a set size and normalized.
[0026] In the above scheme, the step of obtaining the heat-damaged corn segmentation map includes:
[0027] The segmentation map output by the heat-damaged corn semantic segmentation model is restored to the original size of the heat-damaged corn detection image.
[0028] A device for detecting heat-damaged corn kernels, comprising:
[0029] A conversion module is used to input the heat-damaged corn detection picture into a pre-trained CycleGAN network model for processing to obtain a common corn detection picture corresponding to the heat-damaged corn detection picture;
[0030] A segmentation module is used to determine input data in the heat-damaged corn detection picture and the ordinary corn detection picture, and input the input data into a pre-trained heat-damaged corn semantic segmentation model for processing to obtain a heat-damaged corn segmentation map; the heat-damaged corn semantic segmentation model is trained using the ordinary corn segmentation label map as label data.
[0031] An electronic device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the steps of the above-mentioned method for detecting heat-damaged corn kernels are implemented.
[0032] A computer-readable storage medium stores a computer program, which implements the steps of the above-mentioned method for detecting heat-damaged corn kernels when executed by a processor.
[0033] The above-mentioned heat-damaged corn kernel detection method, device, electronic device and medium obtain an ordinary corn detection picture corresponding to the heat-damaged corn detection picture by inputting the heat-damaged corn detection picture into a pre-trained CycleGAN network model for processing, and determine the input data in the ordinary corn detection picture and the heat-damaged corn detection picture, and then input the determined input data into a pre-trained heat-damaged corn semantic segmentation model for processing to obtain a heat-damaged corn segmentation map, wherein this heat-damaged corn segmentation model is trained with the ordinary corn segmentation label map as label data, and can directly train to obtain a heat-damaged corn segmentation model suitable for heat-damaged corn segmentation without making corn heat damage labels, and the heat-damaged corn semantic segmentation model can better extract the features of corn kernels by processing the input data, thereby improving the segmentation accuracy of heat-damaged corn kernels. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 A schematic diagram of a process for detecting heat-damaged corn kernels in one embodiment;
[0035] Figure 2 A schematic diagram of overall model reasoning in the first segmentation method in an embodiment;
[0036] Figure 3 A schematic diagram of overall model reasoning in the second segmentation method in an embodiment;
[0037] Figure 4 A schematic diagram of the training process of an IFSNet network model in one embodiment;
[0038] Figure 5 A schematic diagram of the structure of an IFSNet network model in one embodiment;
[0039] Figure 6 A schematic diagram of the training process of a UNet network model in one embodiment;
[0040] Figure 7 A schematic diagram of the structure of a UNet network model in one embodiment;
[0041] Figure 8 A schematic diagram of the training process of a CycleGAN network model in one embodiment;
[0042] Fig. 9 Schematic diagram of the structure of a CycleGAN network model in one embodiment;
[0043] Fig.10 Schematic diagram of the structure of a generator of a CycleGAN network model in one embodiment;
[0044] Fig.11Schematic diagram of the structure of the discriminator of the CycleGAN network model in one embodiment;
[0045] Fig.12 1 is a structural block diagram of a device for detecting heat-damaged corn kernels in one embodiment. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0047] The implementation details of the technical solution of the embodiment of the present application are described in detail below.
[0048] In one embodiment, Figure 1 As shown, a method for detecting heat-damaged corn kernels is provided, and the method for detecting heat-damaged corn kernels may include the following steps:
[0049] Step S101, inputting the heat-damaged corn detection picture into the pre-trained CycleGAN network model for processing to obtain a common corn detection picture corresponding to the heat-damaged corn detection picture.
[0050] The CycleGAN network model is a deep learning model for image conversion, wherein the CycleGAN network model can convert an input image from one style to another style without paired data. In this embodiment, the input image data is a heat-damaged corn detection image, and the CycleGAN network model converts the heat-damaged corn detection image into a normal corn detection image.
[0051] In actual applications, there are differences in the image features of heat-damaged corn detection images and ordinary corn detection images. In the heat-damaged corn detection images, the heat-damaged corn kernels are darker in appearance and have unclear features. In addition, there are local overexposure and underexposure, which leads to uneven image brightness and further deteriorates the image content and texture. Therefore, it is difficult to directly perform semantic segmentation on the heat-damaged corn detection images.
[0052] Based on this, the heat-damaged corn detection image is converted into an ordinary corn detection image through the CycleGAN network model. The texture details of the ordinary corn detection image are greater than those of the heat-damaged corn detection image, and are more obvious, clear and unified. It can provide richer features for subsequent semantic segmentation, thereby improving the segmentation accuracy in the process of semantic segmentation of the heat-damaged corn detection image.
[0053] In one embodiment, the heat damaged corn detection image is preprocessed, including scaling the size of the heat damaged corn detection image to a set size. This helps ensure that the input image has a uniform size for subsequent processing. Then the heat-damaged corn detection image converted to a set size is normalized to convert the pixel values into a numerical value within a specific range, usually [0, 1] or [-1, 1], so that the model can process the input image.
[0054] Step S102, determining input data in the heat-damaged corn detection picture and the common corn detection picture, and inputting the input data into a pre-trained heat-damaged corn semantic segmentation model for processing to obtain a heat-damaged corn segmentation map.
[0055] The semantic segmentation model of heat-damaged corn is applicable to heat-damaged corn. It can accurately identify and segment each pixel of the heat-damaged corn kernels in the image to achieve pixel-level semantic segmentation.
[0056] In general, the training of the semantic segmentation model of heat-damaged corn requires the use of a large-scale semantic segmentation dataset of heat-damaged corn. However, the appearance of heat-damaged corn kernels is darker and the features are not obvious. For particularly black heat-damaged corn kernels, their boundaries are almost integrated with the background, and it is difficult to obtain a large-scale labeled heat-damaged corn dataset with poor visual perception. Due to the lack of a large-scale semantic segmentation dataset of corn heat damage, it is difficult to directly train the semantic segmentation model of heat-damaged corn. In this embodiment, the semantic segmentation model of heat-damaged corn is obtained by training with ordinary corn segmentation label maps as label data, so there is no need to produce a large-scale heat-damaged corn dataset, wherein the specific training process of the semantic segmentation model of heat-damaged corn will be described through different embodiments.
[0057] In practical applications, there are two ways to achieve the segmentation of heat-damaged corn kernels. The input data processed by the heat-damaged corn semantic segmentation model of each segmentation approach is different. The two segmentation approaches are:
[0058] In the first segmentation method, the heat-damaged corn semantic segmentation model directly segments the heat-damaged corn detection image. Figure 2 As shown, Figure 2The figure shows the overall model reasoning schematic diagram in the first segmentation method. In this segmentation method, the heat-damaged corn detection pictures and the ordinary corn detection pictures are used as input data and input into the heat-damaged corn semantic segmentation model. The heat-damaged corn semantic segmentation model can use the image feature fusion segmentation mechanism to combine the heat-damaged corn detection pictures and the ordinary corn detection pictures. Through feature fusion learning, multi-scale features are extracted at two levels, which can help the model learn useful features from the heat-damaged corn detection pictures and the ordinary corn detection pictures, and then obtain the heat-damaged corn segmentation map with higher segmentation accuracy, solving the problem of heat-damaged corn segmentation difficulties.
[0059] In this segmentation method, although the features of corn kernels in the heat-damaged corn detection images are not obvious, the model can improve the recognition ability of corn kernels by performing feature fusion learning on the heat-damaged corn detection images and ordinary corn detection images, thereby improving the model's segmentation accuracy for heat-damaged corn kernels.
[0060] In the process of model training, by adopting the domain migration method, the training of the heat-damaged corn semantic segmentation model capable of segmenting heat-damaged corn kernels can be completed without the need for a heat-damaged corn dataset. Domain migration aims to solve the machine learning problem of sampling and different probability distributions. Generally speaking, the source domain contains a large amount of labeled data, and the target domain contains a small amount or no labeled data. Through domain migration, a model on the target domain can be trained using known source domain and target domain data. In the process of training the semantic segmentation model, domain migration can migrate ordinary corn data to the heat-damaged corn scenario, so that a heat-damaged corn semantic segmentation model on the heat-damaged domain can be trained through the ordinary corn segmentation label map. Among them, the heat-damaged corn semantic segmentation model here can be an IFSNet network model, and the specific training process of the IFSNet network model will be described in detail through another embodiment.
[0061] In the second segmentation method, the heat-damaged corn semantic segmentation model indirectly segments the heat-damaged corn detection image. Figure 3 As shown, Figure 3The figure shows a schematic diagram of the overall model reasoning in the second segmentation method. In this segmentation method, the common corn detection picture converted based on the heat-damaged corn detection picture can be used as input data and input into the heat-damaged corn semantic segmentation model for processing. At this time, the heat-damaged corn semantic segmentation model is used to segment the common corn detection picture. It should be noted that the common corn detection picture input into the heat-damaged corn semantic segmentation model is obtained based on the conversion of the heat-damaged corn detection picture. Therefore, the heat-damaged corn semantic segmentation model segments the common corn detection picture, which is actually indirectly segmenting the heat-damaged corn detection picture. The segmentation map output by the heat-damaged corn semantic segmentation model is actually the heat-damaged corn segmentation map.
[0062] In this segmentation method, the heat-damaged corn detection image is converted into an ordinary corn detection image, and the heat-damaged corn kernels are segmented based on the ordinary corn detection image. Since the corn kernel features on the ordinary corn detection image are obvious and have more texture information than those on the heat-damaged corn detection image, the model's ability to recognize corn kernels and the accuracy of corn kernel segmentation are increased. In addition, since the direct processing data of the heat-damaged corn semantic segmentation model is the ordinary corn detection image, there is no need to create a large-scale heat-damaged corn dataset during the model training process.
[0063] The heat-damaged corn semantic segmentation model here can be a UNet network model. The UNet network model is a classic fully convolutional neural network, which is commonly used in image segmentation tasks. The specific training process of the UNet network model will be described in detail through another embodiment.
[0064] The heat-damaged corn kernel detection method provided in this embodiment follows the end-to-end concept, that is, only the heat-damaged corn detection picture needs to be input, and the corresponding heat-damaged corn segmentation map can be directly obtained after model inference, thereby improving the segmentation efficiency of heat-damaged corn kernels. Among them, the model inference can be divided into two parts. The first part uses the trained CycleGAN network model to generate ordinary corn detection pictures, and the second part uses the trained heat-damaged corn semantic segmentation model to perform polymorphic fusion on the input data determined in the ordinary corn detection picture and the heat-damaged corn detection picture, and finally obtains the heat-damaged corn segmentation map.
[0065] In one embodiment, the heat-damaged corn semantic model can output a corresponding segmentation map by processing the input data. After obtaining the segmentation map, the segmentation map is reversely scaled to the original size of the heat-damaged corn detection image to obtain a segmentation result of the same size as the heat-damaged corn detection image, i.e., the final heat-damaged corn segmentation map is obtained, thereby maintaining the correspondence and accuracy between the heat-damaged corn segmentation map and the heat-damaged corn detection image.
[0066] The training process of the IFSNet network model is described below through an embodiment.
[0067] like Figure 4 As shown, Figure 4 A schematic diagram of the training process of the IFSNet network model is shown.
[0068] Step S401, inputting the common corn sample image into the pre-trained CycleGAN network model to generate the heat-damaged corn sample image.
[0069] Here, the training data of the IFSNet network model includes common corn sample images, common corn segmentation label images, and heat-damaged corn sample images. Among them, the common corn sample images can be obtained by camera capture, public data sets, image libraries, or searching and downloading from the Internet. These common corn sample images can contain samples of common corn so that the model can learn corns of different shapes and sizes.
[0070] After collecting the common corn sample images, a corresponding common corn segmentation label map is created for each common corn sample image, marking the contour image area of each corn kernel.
[0071] For the heat-damaged corn sample images in the training data, the CycleGAN network model is used to convert the ordinary corn sample images into the heat-damaged domain to obtain the heat-damaged corn sample images.
[0072] In practical applications, the heat-damaged corn sample images can be further divided into training sets and validation sets. The training set is used to train the IFSNet network model, and the validation set is used to evaluate the generalization ability of the IFSNet network model on unseen data.
[0073] Step S402, training the IFSNet network model according to the common corn sample picture, the common corn segmentation label picture corresponding to the common corn sample picture, and the heat-damaged corn sample picture to obtain a first predicted segmentation picture.
[0074] Then, the IFSNet network model was trained using common corn sample images, common corn segmentation label images, and heat-damaged corn sample images.
[0075] The input images of the IFSNet network model include images of normal corn samples and images of heat-damaged corn samples. Figure 5 As shown, Figure 5 The schematic diagram of the IFSNet network model is shown below. Figure 5 , details the processing of ordinary corn sample images and heat-damaged corn sample images by the IFSNet network model.
[0076] The image of the heat-damaged corn sample is first convolved through a convolution layer, and then convolved three times through a multi-size convolution (including three convolution kernels of scales 1×1, 3×3, and 5×5). Each convolution operation can obtain features of different scales. The three features obtained are spliced, and then the spliced features are convolved again before entering the residual module. The residual module includes a convolution layer and a residual connection, and a total of three residual processes are performed to obtain the first output layer.
[0077] The sample image of ordinary corn first passes through a convolution layer, and then enters three consecutive residual modules for three residual processing. Each residual module includes a convolution layer and a residual connection to obtain the second output layer.
[0078] The first output layer and the second output layer are channel-fused, followed by a convolution process, and finally convolution and upsampling to obtain the first predicted segmentation map.
[0079] It should be noted that the structure of the IFSNet network model does not change during the inference stage and the training stage. During the inference stage, the IFSNet network model also processes the input data in the same way as the above data processing process.
[0080] Step S403, calculating a first loss function value according to the first predicted segmentation map and the common corn segmentation label map.
[0081] After obtaining the first predicted segmentation map, it is necessary to calculate the first loss function value based on the first predicted segmentation map and the common corn segmentation label map. The loss function is used to measure the gap between the model prediction output and the true label, that is, the error size of the model prediction. By calculating the loss function value, the performance of the model on the training data can be understood, which helps to evaluate the effect of model learning.
[0082] The loss function here is the binary cross entropy loss function, which is a common loss function for binary classification problems. It is usually used to measure the gap between the output probability distribution of the binary classification model and the true label. The binary cross entropy loss function can be expressed as:
[0083]
[0084] in, is the total number of pixels, is the true label, with a value of 0 or 1. is the probability output by the model, indicating the probability that the pixel belongs to category 1 (indicating the probability of foreground).
[0085] Step S404, performing gradient back propagation according to the first loss function value, and continuing the next model training of the IFSNet network model until the training is completed.
[0086] When the model's prediction is consistent with the true label, the first loss function value is close to 0, indicating that the model prediction is accurate; when the model's prediction is inconsistent with the true label, the first loss function value increases, indicating the degree of error in the model prediction.
[0087] Based on this, after calculating the first loss function value, the gradient is backpropagated according to the first loss function value. Among them, the gradient backpropagation includes backpropagation and parameter update. First, according to the calculated first loss function value, the gradient of the loss function to the model parameters is calculated by the backpropagation algorithm. The gradient represents the rate of change of the loss function at the current parameter value, which is used to update the parameters of the model to reduce the loss. Then, using optimization algorithms such as gradient descent, the parameters of the model are updated according to the gradient of the first loss function value, so that the first loss function value is gradually reduced, thereby gradually optimizing the model to improve performance.
[0088] After the gradient is returned, the next model training starts for the IFSNet network model until the training of the IFSNet network is completed.
[0089] It should be noted that during the training process of the IFSNet network model, the CycleGAN network model does not participate in the training.
[0090] The following is an example of how to train the UNet network model.
[0091] like Figure 6 As shown, Figure 6 A schematic diagram of the training process of the UNet network model is shown.
[0092] Step S601, training the Unet network model according to the common corn sample picture and the common corn segmentation label picture corresponding to the common corn sample picture to obtain a second predicted segmentation picture.
[0093] Here, the UNet network model is trained to enable the UNet network model to segment the common corn pictures. Based on this, the training data of the UNet network model includes common corn sample pictures and common corn segmentation label maps corresponding to the common corn sample pictures. Among them, the common corn sample pictures can be obtained by searching and downloading from camera capture, public data sets, image libraries, or the Internet. These common corn sample pictures can contain samples of common corn so that the model can learn corns of different shapes and sizes. After collecting the common corn sample pictures, a corresponding common corn segmentation label map is created for each common corn sample picture, marking the contour image area of each corn kernel.
[0094] The common corn sample picture and the common corn segmentation label map are input into the UNet network model, so that the UNet network model learns how to accurately segment corn kernels and obtains a second predicted segmentation map. This second predicted segmentation map is learned by the UNet network model based on the input common corn sample picture.
[0095] like Figure 7 As shown, Figure 7 The schematic diagram of the structure of the UNet network model is shown. Figure 7 The UNet network model consists of an encoder (downsampling path) and a decoder (upsampling path), with a jump connection in the middle. The encoder is used to capture the high-level features of the image, and the decoder is used to map these features back to the original resolution image. The jump connection helps to transfer shallow and deep features and improve segmentation accuracy. The UNet network model can effectively capture the global and local information of the image, thereby obtaining the corresponding output results.
[0096] Step S602, calculating the second loss function value according to the second predicted segmentation map and the common corn segmentation label map.
[0097] Next, the second predicted segmentation map is compared with the common corn segmentation label map to calculate the second loss function value. The loss function is used to measure the gap between the model prediction output and the true label, that is, the error size of the model prediction. By calculating the loss function value, we can understand the performance of the model on the training data and help evaluate the effect of model learning.
[0098] The loss function used here is a binary cross entropy loss function, wherein the calculation of the binary cross entropy loss function can refer to the description of the above embodiment.
[0099] Step S603, perform gradient backpropagation according to the second loss function value, and continue the next model training of the UNet network model until the training is completed.
[0100] After calculating the second loss function value, gradient feedback is performed according to the second loss function value. The gradient feedback can update the parameters of the model so that the second loss function value gradually decreases, thereby gradually optimizing the model to improve performance.
[0101] After the gradient is returned, the next model training starts for the UNet network model until the training of the UNet network model is completed. Among them, different conditions can be used to determine whether the UNet network model has completed training. These conditions may include:
[0102] (1) Reaching the maximum number of iterations. Set a predetermined maximum number of iterations. When the model iteration reaches this number, the training ends.
[0103] (2) Convergence of loss function. Monitor the changes in the loss function value on the training set and the validation set. When the loss function value no longer decreases significantly or fluctuates within a certain range, the model can be considered to have converged.
[0104] (3) The performance of the validation set is stable. By monitoring the performance indicators of the model on the validation set (such as accuracy, precision, etc.), when the performance indicators are stable within a certain range, the model training can be considered complete.
[0105] After the gradient is returned, the next model training starts for the UNet network model until the training of the UNet network is completed.
[0106] It should be noted that during the training process of the UNet network model, the CycleGAN network model does not participate in the training.
[0107] The training process of the CycleGAN network model is described below through an embodiment.
[0108] like Figure 8 As shown, Figure 8 A schematic diagram of the training process of the CycleGAN network model is shown.
[0109] Step S801, input the sample picture of ordinary corn into the first generator to obtain the first conversion picture, and input the sample picture of heat-damaged corn into the second generator to obtain the second conversion picture.
[0110] The CycleGAN network model is a cyclic generative adversarial network, such as Fig. 9 As shown, Fig. 9 The figure shows a schematic diagram of the structure of the CycleGAN network model. The CycleGAN network model includes two discriminators with the same structure (the first discriminator DY and the second discriminator DX) and two generators with the same structure (the first generator F and the second generator G).
[0111] The image is input into the generator in the CycleGAN network model. The generator can transfer the style of the image and output the corresponding converted image, where the style transfer is between the normal domain and the thermal damage domain.
[0112] Specifically, the sample images include common corn sample images and heat-damaged corn sample images. The first generator F can realize the conversion from the common domain to the heat-damaged domain. The common corn sample image Y is fed into the first generator F to obtain the first conversion image X1^ of the corresponding heat-damaged domain; the second generator G can realize the conversion from the heat-damaged domain to the common domain. The heat-damaged corn sample image X is fed into the second generator G to obtain the second conversion image Y1^ of the corresponding common domain.
[0113] like Fig.10 As shown, Fig.10 The figure shows the schematic diagram of the generator structure of the CycleGAN network model. The generator can extract and process the features of the image layer by layer, retain important feature information, and finally generate a converted image with the same size as the input image. The training goal of the generator is to generate realistic images that are as close as possible to the real images in the field after conversion.
[0114] The size of the input image of the generator is , where 3 represents the number of channels of the image (usually three channels for RGB images), and Represent the height and width of the image respectively. After the first convolutional layer, the output size is .here represents the number of output channels of the convolutional layer, and the image size remains unchanged. Then, after the second convolutional layer, the output size is ,here represents the number of output channels of the convolutional layer, and It means that the image size is halved after convolution and downsampling. Then after the third convolution layer, the output size is ,here represents the number of output channels of the convolutional layer, and Indicates that the image size is further halved. Next, it is processed by nine consecutive residual blocks, and the input and output sizes of each residual block are , the residual block contains two convolutional layers and a skip connection to retain input features and enhance gradient propagation. After the residual block, the image size remains unchanged. Next, it is processed by two upsampling layers. Each upsampling layer doubles the image size. After the first upsampling layer, the output size is , after the second upsampling layer, the output size is Finally, after a convolutional layer, the output size is , restored to the same size as the input image.
[0115] Step S802: input the common corn sample image and the second conversion image into the first discriminator to obtain a first discrimination result, and input the heat-damaged corn sample image and the first conversion image into the second discriminator to obtain a second discrimination result.
[0116] exist Fig. 9The discriminator includes a first discriminator DY and a second discriminator DX, wherein the second conversion image Y1^ and the common corn sample image Y are respectively sent to the first discriminator DY for processing to determine whether the input image belongs to the common domain; the first conversion image X1^ and the heat-damaged corn sample image X are respectively sent to the second discriminator DX for processing to determine whether the input image belongs to the heat-damaged domain. The first discriminator DY and the second discriminator DX are key components for distinguishing the difference between the generated image and the real image, thereby learning the features and differences between the heat-damaged domain image and the common domain image, so as to better help the generator generate more realistic conversion images.
[0117] like Fig.11 As shown, Fig.11 The figure shows a schematic diagram of the structure of the discriminator, which consists of different convolutional layers and an average pooling layer. The discriminator extracts the features of the image layer by layer and finally outputs the discrimination result, where the discrimination result is a probability value indicating the authenticity of the image (that is, the input image is the original image).
[0118] The size of the input image of the discriminator is , where 3 represents the number of channels of the image (usually three channels for RGB images), and H and W represent the height and width of the image, respectively. After the input image passes through the first convolutional layer, the output size is ,here represents the number of output channels of the convolutional layer, and It means that the image size is halved after convolution and downsampling. Then after the second convolution layer, the output size is ,here represents the number of output channels of the convolutional layer, and indicates that the image size is further halved. Then, after the third convolutional layer, the output size is ,here represents the number of output channels of the convolutional layer, and Indicates that the image size is halved again. Then, after the fourth convolutional layer, the output size is ,here represents the number of output channels of the convolutional layer, and the image size remains unchanged. Then, after the fifth convolutional layer, the output size is , where 1 represents the number of output channels of the convolutional layer, and the image size remains unchanged. Finally, after an average pooling layer, the output feature map is globally averaged and pooled to obtain an output layer with a confidence level of [0, 1]. This output layer represents the probability that the input image is the original image.
[0119] Step S803: input the first conversion image to the second generator to obtain a third conversion image, and input the second conversion image to the first generator to obtain a fourth conversion image.
[0120] Reference Fig. 9 As shown, after generating the first conversion picture X1^, in addition to inputting the first conversion picture X1^ of the thermal damage domain into the second discriminator DX, the first conversion picture X1^ is also input into the second generator G, and the first conversion picture X1^ of the thermal damage domain is converted into the third conversion picture Y2^ of the ordinary domain; similarly, after generating the second conversion picture Y1^, in addition to inputting the second conversion picture Y1^ of the ordinary domain into the first discriminator DY, the second conversion picture Y1^ of the ordinary domain is also input into the first generator F, and the second conversion picture Y1^ of the ordinary domain is converted into the fourth conversion picture X2^ of the thermal damage domain.
[0121] The main purpose of this step is to achieve cycle consistency, which means that the generated image should be as close to the original input image as possible after being reversely transformed by the generator, so that the model is forced to learn to retain and learn the important features of the input image, ensuring better semantic and style consistency between normal domain images and thermal damage domain images.
[0122] Step S804, calculating a third loss function value according to the first discrimination result, the second discrimination result, the first conversion picture, the second conversion picture, the third conversion picture and the fourth conversion picture.
[0123] Reference Fig. 9 As shown in the figure, the third loss value loss is composed of two parts. The first part of the loss is the adversarial loss, and the second part of the loss is the cycle consistency loss.
[0124] The adversarial loss is calculated as follows:
[0125]
[0126]
[0127] In the above formula, The second generator representing the conversion of thermal damage domain images into normal domain images, The first generator representing the conversion of normal domain images into thermal damage domain images, Represents the first discriminator that determines whether the image is in the common domain. The second discriminator represents whether the image is in the thermal damage domain. Here is a picture of heat-damaged corn samples. This is a picture of a common corn sample.
[0128] The calculation formula of cycle consistency loss is as follows:
[0129]
[0130] In the above formula, Here is a picture of heat-damaged corn samples. This is a sample picture of common corn. represents the fourth transition picture; represents the third transition picture, represents the L1 norm.
[0131] Based on this, the calculation formula of the third loss function value is as follows:
[0132]
[0133] Step S805, performing gradient backpropagation according to the third loss function value, and continuing the next model training of the CycleGAN network model until the training is completed.
[0134] After calculating the third loss function value, gradient feedback is performed according to the third loss function value. The gradient feedback can update the parameters of the model so that the third loss function value gradually decreases, thereby gradually optimizing the model to improve performance.
[0135] After the gradient is returned, the next model training of the CycleGAN network model begins until the training of the CycleGAN network model is completed.
[0136] In the above embodiment, the semantic segmentation model of heat-damaged corn is obtained by training with the ordinary corn segmentation label map as label data, so that the model for segmenting heat-damaged corn images can be trained without relying on the heat-damaged corn kernel segmentation label. The corn segmentation detection image is input into the pre-trained CycleGAN network model for processing to obtain the ordinary corn detection image corresponding to the heat-damaged corn detection image, and the input data is determined in the ordinary corn detection image and the heat-damaged corn detection image, and then the input data is input into the semantic segmentation model of heat-damaged corn, so that the model can better extract the features of corn kernels, thereby improving the recognition ability of heat-damaged corn kernels and obtaining a heat-damaged corn segmentation map with high accuracy.
[0137] In one embodiment, a device for detecting heat-damaged corn kernels is provided, referring to Fig.12 As shown, the heat-damaged corn kernel detection device 1200 may include: a conversion module 1201, a segmentation module 1202, a training module 1203, and a preprocessing module 1204.
[0138] The conversion module 1201 is used to input the heat-damaged corn detection picture into the pre-trained CycleGAN network model for processing, and obtain a common corn detection picture corresponding to the heat-damaged corn detection picture;
[0139] The segmentation module 1202 is used to determine input data in the heat-damaged corn detection image and the ordinary corn detection image, and input the input data into a pre-trained heat-damaged corn semantic segmentation model for processing to obtain a heat-damaged corn segmentation map; the heat-damaged corn semantic segmentation model is trained using the ordinary corn segmentation label map as label data.
[0140] In one embodiment, the semantic segmentation model of heat-damaged corn is an IFSNet network model or a UNet network model, wherein the input data of the IFSNet network model are heat-damaged corn detection pictures and ordinary corn detection pictures; the input data of the UNet network model are ordinary corn detection pictures.
[0141] In one embodiment, the heat-damaged corn kernel detection device 1200 further includes a training module 1203. When the heat-damaged corn semantic segmentation model is an IFSNet network model, the training module 1203 is specifically used to: input a common corn sample image into a pre-trained CycleGAN network model to generate a heat-damaged corn sample image;
[0142] The IFSNet network model is trained according to the common corn sample image, the common corn segmentation label image corresponding to the common corn sample image, and the heat-damaged corn sample image to obtain a first predicted segmentation image;
[0143] Calculate a first loss function value according to the first predicted segmentation map and the common corn segmentation label map;
[0144] The gradient is returned according to the value of the first loss function, and the next model training of the IFSNet network model is continued until the training is completed.
[0145] In one embodiment, the heat-damaged corn kernel detection device 1200 further includes a training module 1203. When the heat-damaged corn semantic segmentation model is a UNet network model, the training module 1203 is specifically used to: train the UNet network model according to the common corn sample picture and the common corn segmentation label picture corresponding to the common corn sample picture to obtain a second predicted segmentation picture;
[0146] Calculating a second loss function value according to the second predicted segmentation map and the common corn segmentation label map;
[0147] The gradient is returned according to the value of the second loss function, and the next model training of the UNet network model is continued until the training is completed.
[0148] In one embodiment, the heat-damaged corn kernel detection device 1200 further includes a training module 1203, which is further used to: input the common corn sample image into the first generator to obtain a first conversion image, and input the heat-damaged corn sample image into the second generator to obtain a second conversion image;
[0149] Input the common corn sample picture and the second conversion picture into the first discriminator to obtain a first discrimination result, and input the heat-damaged corn sample picture and the first conversion picture into the second discriminator to obtain a second discrimination result;
[0150] Inputting the first conversion image into the second generator to obtain a third conversion image, and inputting the second conversion image into the first generator to obtain a fourth conversion image;
[0151] Calculate a third loss function value according to the first discrimination result, the second discrimination result, the first conversion picture, the second conversion picture, the third conversion picture, and the fourth conversion picture;
[0152] The gradient is propagated back according to the value of the third loss function, and the next model training of the CycleGAN network model is continued until the training is completed.
[0153] In one embodiment, the heat damaged corn kernel detection device 1200 also includes a preprocessing module 1204, which is used to scale the corn heat damaged corn detection image to a heat damaged corn detection image of a set size and perform normalization processing before inputting the heat damaged corn detection image into a pre-trained CycleGAN network model for processing.
[0154] In one embodiment, the segmentation module 1202 is used to restore the segmentation map output by the heat-damaged corn semantic segmentation model to the original size of the heat-damaged corn detection image.
[0155] The specific definition of the heat-damaged corn grain detection device 1200 can be found in the definition of the heat-damaged corn grain detection method above, which will not be repeated here. Each module in the above-mentioned heat-damaged corn grain detection device 1200 can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0156] In one embodiment, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor implements a method for detecting heat-damaged corn kernels when executing the computer program.
[0157] In one embodiment, a computer storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, a method for detecting heat-damaged corn kernels is implemented.
[0158] It should be noted that the logic and / or steps represented in the flowchart or described in other ways herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or equipment (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or equipment and execute instructions), or in combination with these instruction execution systems, devices or equipment. For the purpose of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or equipment, or in combination with these instruction execution systems, devices or equipment. More specific examples (non-exhaustive list) of computer-readable media include the following: an electrical connection portion with one or more wirings (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and editable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing in other suitable ways if necessary, and then stored in a computer memory.
[0159] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0160] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0161] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of the present invention, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0162] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.
Claims
1. A method for detecting heat-damaged corn kernels, characterized in that: include: Inputting the heat-damaged corn detection picture into a pre-trained CycleGAN network model for processing to obtain a common corn detection picture corresponding to the heat-damaged corn detection picture; Determine input data in the heat-damaged corn detection picture and the common corn detection picture, and input the input data into a pre-trained heat-damaged corn semantic segmentation model for processing to obtain a heat-damaged corn segmentation picture; the heat-damaged corn semantic segmentation model is trained using the common corn segmentation label picture as label data; the heat-damaged corn semantic segmentation model is an IFSNet network model or a UNet network model, wherein the input data of the IFSNet network model are the heat-damaged corn detection picture and the common corn detection picture; the input data of the UNet network model is the common corn detection picture; The IFSNet network model includes a heat-damaged corn detection image processing module, a common corn detection image processing module and an inference module. The heat-damaged corn detection image processing module is sequentially composed of a convolution layer, convolution kernels of three scales, a convolution layer and three consecutive residual modules; the common corn detection image processing module is also composed of a convolution layer and three consecutive residual modules; the inference module is used to perform channel fusion and sequential convolution processing on the first output layer output by the heat-damaged corn detection image processing module and the second output layer output by the common corn detection image processing module, and then perform convolution and upsampling.
2. The method for detecting heat-damaged corn kernels according to claim 1, characterized in that: When the heat-damaged corn semantic segmentation model is an IFSNet network model, the training process of the heat-damaged corn semantic segmentation model includes: Inputting the common corn sample picture into the pre-trained CycleGAN network model to generate the heat-damaged corn sample picture; The IFSNet network model is trained according to the common corn sample picture, the common corn segmentation label picture corresponding to the common corn sample picture, and the heat-damaged corn sample picture to obtain a first predicted segmentation picture; Calculating a first loss function value according to the first predicted segmentation map and the common corn segmentation label map; The gradient is returned according to the first loss function value, and the next model training of the IFSNet network model is continued until the training is completed.
3. The method for detecting heat-damaged corn kernels according to claim 1, characterized in that: When the heat-damaged corn semantic segmentation model is a UNet network model, the training process of the heat-damaged corn semantic segmentation model includes: The UNet network model is trained according to the common corn sample picture and the common corn segmentation label picture corresponding to the common corn sample picture to obtain a second predicted segmentation picture; Calculating a second loss function value according to the second predicted segmentation map and the common corn segmentation label map; The gradient is returned according to the second loss function value, and the next model training of the UNet network model is continued until the training is completed.
4. The method for detecting heat-damaged corn kernels according to claim 1, characterized in that: The training process of the CycleGAN network model includes: Inputting the common corn sample picture into the first generator to obtain a first conversion picture, and inputting the heat-damaged corn sample picture into the second generator to obtain a second conversion picture; Input the common corn sample image and the second conversion image into a first discriminator to obtain a first discrimination result, and input the heat-damaged corn sample image and the first conversion image into a second discriminator to obtain a second discrimination result; Inputting the first conversion image to the second generator to obtain a third conversion image, and inputting the second conversion image to the first generator to obtain a fourth conversion image; Calculating a third loss function value according to the first discrimination result, the second discrimination result, the first conversion picture, the second conversion picture, the third conversion picture, and the fourth conversion picture; Gradients are propagated back according to the third loss function value, and the next model training of the CycleGAN network model is continued until the training is completed.
5. The method for detecting heat-damaged corn kernels according to claim 1, characterized in that: Before inputting the heat damaged corn detection picture into the pre-trained CycleGAN network model for processing, the method includes: The corn heat damage detection image is scaled to a heat damage corn detection image of a set size and normalized.
6. The method for detecting heat-damaged corn kernels according to claim 5, characterized in that: The step of obtaining the heat damaged corn segmentation diagram comprises: The segmentation map output by the heat-damaged corn semantic segmentation model is restored to the original size of the heat-damaged corn detection image.
7. A device for detecting heat-damaged corn kernels, characterized in that: include: A conversion module is used to input the heat-damaged corn detection picture into a pre-trained CycleGAN network model for processing to obtain a common corn detection picture corresponding to the heat-damaged corn detection picture; A segmentation module is used to determine input data in the heat-damaged corn detection picture and the common corn detection picture, and input the input data into a pre-trained heat-damaged corn semantic segmentation model for processing to obtain a heat-damaged corn segmentation picture; the heat-damaged corn semantic segmentation model is trained using the common corn segmentation label picture as label data; the heat-damaged corn semantic segmentation model is an IFSNet network model or a UNet network model, wherein the input data of the IFSNet network model are the heat-damaged corn detection picture and the common corn detection picture; the input data of the UNet network model is the common corn detection picture; The IFSNet network model includes a heat-damaged corn image processing module, a common corn image processing module and an inference module. The heat-damaged corn image processing module is sequentially composed of a convolution layer, convolution kernels of three scales, a convolution layer and three consecutive residual modules; the common corn image processing module is also composed of a convolution layer and three consecutive residual modules; the inference module is used to perform channel fusion and sequential convolution processing on the first output layer output by the heat-damaged corn image processing module and the second output layer output by the common corn image processing module, and then perform convolution and upsampling.
8. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method for detecting heat-damaged corn kernels described in any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that:When the computer program is executed by a processor, the steps of the method for detecting heat-damaged corn kernels described in any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Image segmentation network training method and device, image segmentation method and device and storage medium
CN111199550A
Image processing method and storage medium
CN114387294A
