Farmland weed detection method and system based on machine learning
Through image repair and coding, parallel convolution feature extraction and lightweight convolutional neural network, the problems of low efficiency and information loss in farmland weed detection are solved, the detection accuracy and efficiency are improved, and the computational complexity is reduced.
Patent Information
- Application Number
- CN202411036486.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2044-07-31
AI Technical Summary
Existing farmland weed detection methods are inefficient. Machine learning detection has high data quality requirements. The quality of directly collected image data is poor, resulting in information loss and insufficient detection accuracy. Complex feature engineering design increases computational complexity and affects efficiency.
Image restoration combined with image coding is used for image preprocessing, RGB and depth image channel structures are unified, a parallel convolution feature extractor is used for multi-modal feature extraction, and a lightweight convolutional neural network model is used for detection.
It optimizes image quality and detection efficiency, reduces information loss, improves detection accuracy, and reduces computational complexity and detection speed.
Smart Images

Figure CN118570197B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of smart agriculture, and specifically refers to a farmland weed detection method and system based on machine learning. Background Art
[0002] Farmland weed detection uses machine learning technology to automatically detect farmland weeds by analyzing and processing farmland images. It aims to assist farmers in timely weed removal, improve farmland management efficiency, and promote the intelligent development of agriculture through automated farmland weed detection.
[0003] However, in the existing farmland weed detection process, there are technical problems that the traditional method relying on manual detection is inefficient, while the use of machine learning technology for detection has high requirements for data quality, and the quality of the original image data directly collected is poor and cannot be directly used for information system processing; there is a technical problem that the traditional technology suitable for feature extraction of single image data often simply uses a convolutional network to extract feature maps, and the feature extraction of single image data is prone to inevitably lead to information loss of farmland weed images in the process of extracting and screening features, which leads to insufficient accuracy of weed detection using complex farmland images; there is a technical problem that although complex feature engineering design can improve the overall accuracy of detection, it will also increase the complexity of model calculation, which is not conducive to the overall improvement of detection efficiency. Summary of the invention
[0004] In view of the above situation, in order to overcome the defects of the prior art, the present invention provides a method and system for detecting weeds in farmland based on machine learning. In view of the technical problems that in the existing methods for detecting weeds in farmland, the traditional methods relying on manual detection are inefficient, the detection using machine learning technology has high requirements for data quality, and the quality of the original image data directly collected is poor and cannot be directly used for information system processing, this solution creatively adopts the method of image restoration combined with image coding for image preprocessing, optimizes the image quality and converts the image into a form that can be processed and encoded by the information system, unifies the channel structure of RGB images and depth images, enhances the feature expression of depth images, and optimizes the automation and efficiency of weed detection in farmland; in view of the existing methods for extracting feature extractors of weeds in farmland, the traditional technology for feature extraction of single image data often simply adopts convolutional networks for feature map extraction, and feature extraction of single image data is easily not possible in the process of extracting and screening features. In order to avoid the technical problem of information loss in farmland weed images, which in turn leads to insufficient accuracy of weed detection using complex farmland images, this solution creatively adopts a parallel convolutional feature extractor for multimodal feature extraction, and simultaneously processes farmland RGB images and three-channel depth images through parallel convolution, and performs multimodal feature extraction, thereby optimizing the refinement of feature engineering and reducing information loss; in view of the technical problem that in existing farmland weed detection methods, although complex feature engineering design can improve the overall accuracy of detection, it will also increase the calculation complexity of the model, which is not conducive to the overall improvement of detection efficiency, this solution creatively adopts a lightweight convolutional neural network model for farmland weed detection, optimizes the calculation complexity of the model by only constructing three convolutional layers, and subsequently ensures the accuracy of feature splicing and classification through the setting of multiple global maximum pooling layers and fully connected layers, thereby optimizing the overall calculation speed and detection efficiency of the method without losing detection accuracy.
[0005] The technical solution adopted by the present invention is as follows: The method for detecting weeds in farmland based on machine learning provided by the present invention comprises the following steps:
[0006] Step S1: image preparation;
[0007] Step S2: image preprocessing;
[0008] Step S3: multimodal feature extraction;
[0009] Step S4: farmland weed detection;
[0010] Step S5: generating a farmland weed detection report.
[0011] Furthermore, in step S1, the image preparation is specifically to collect images from the farmland through a camera to obtain the farmland RGB image and the farmland depth image.
[0012] Further, in step S2, the image preprocessing is used to optimize the image quality, specifically by image alignment, image restoration, image encoding and image enhancement, to obtain a three-channel depth image and a farmland enhanced image, including the following steps:
[0013] Step S21: image alignment, which is used to reduce the influence of pixel misalignment. Specifically, the image alignment technology is used to align the farmland depth image with the farmland RGB image through coordinate transformation to ensure that the pixels of the different modal images are in the same position, so as to obtain the farmland depth alignment image;
[0014] Step S22: image restoration, which is used to repair holes in the farmland depth alignment image, specifically, by performing image restoration on the farmland depth alignment image through a hole filling algorithm to obtain a farmland depth restoration image;
[0015] Step S23: image encoding, which is used to encode the farmland deep restoration image into a depth image with three channels, thereby unifying the channel structure of the multimodal image, including the following steps:
[0016] Step S231: Calculate the phase information, specifically, use the depth information in the farmland depth restoration image to calculate the phase information of the farmland depth restoration image, and the calculation formula is:
[0017] ;
[0018] In the formula, is the phase information, d is the depth information, which is used to indicate the distance from the camera to each pixel in the farmland depth restoration image, n is the first natural number, which is used to ensure that the phase information falls within the range of [0, 2π), b is the second natural number, 2πb is the uniqueness range of the camera, and the uniqueness range refers to the range in which the camera can accurately measure the depth information. When the uniqueness range is exceeded, the accuracy of the depth information decreases;
[0019] Step S232: Calculate the height above the ground, which is used to represent the height of each pixel in the farmland deep restoration image relative to the ground. The calculation formula is:
[0020] ;
[0021] Where i is the horizontal coordinate index of the pixel point, j is the vertical coordinate index of the pixel point, Hig(i, j) is the height above the ground of the pixel point with coordinate (i, j) in the farmland deep restoration image, and d max is the maximum depth information of the farmland deep restoration image, and d(i, j) is the depth information of the pixel with coordinates (i, j) in the farmland deep restoration image;
[0022] Step S233: calculating angle information, specifically calculating the angle between the surface normal vector of each pixel point in the farmland deep restoration image and the gravity direction;
[0023] Step S234: performing image encoding on the farmland depth restoration image by calculating phase information, height from the ground, and angle information to obtain a three-channel depth image;
[0024] Step S24: image enhancement, specifically, image enhancement of the farmland RGB image through image denoising, color correction and contrast enhancement to obtain a farmland enhanced image.
[0025] Furthermore, in step S3, the multimodal feature extraction is specifically performed by using a parallel convolutional feature extractor to obtain multimodal features of farmland weeds;
[0026] The parallel convolution feature extractor is used to extract weed multimodal features from the farmland enhanced image and the three-channel depth image, and specifically includes a parallel convolution multi-scale feature processing layer and a multimodal feature fusion layer;
[0027] The parallel convolutional multi-scale feature processing layer is used to capture color texture features and spatial geometric features, and specifically includes two parallel convolutional multi-scale feature processing sub-layers;
[0028] The convolutional multi-scale feature processing sublayer specifically includes a convolutional network layer, a maximum pooling layer, a deconvolution layer and a multi-scale feature splicing layer;
[0029] The multi-scale feature splicing layer is used to splice features of different scales;
[0030] The multimodal feature fusion layer is used to fuse multi-scale multimodal information;
[0031] The multimodal feature extraction comprises the following steps:
[0032] Step S31: construct a parallel convolutional multi-scale feature processing layer, specifically, setting two parallel convolutional multi-scale feature processing sub-layers in the parallel convolutional multi-scale feature processing layer, receiving the farmland enhancement image and the three-channel depth image as input data of different convolutional multi-scale feature processing sub-layers, and calculating through the parallel convolutional multi-scale feature processing layer to obtain multi-scale color texture features and multi-scale spatial geometric features, including the following steps:
[0033] Step S311: constructing a convolutional network layer, specifically setting five convolutional blocks in the convolutional network layer, and calculating the input data through the five convolutional blocks;
[0034] Step S312: construct a maximum pooling layer, and downsample the output result of the first convolution block in the convolutional network layer through the maximum pooling layer to obtain pooled convolution features. The calculation formula is:
[0035] ;
[0036] Where Fea1 is the pooled convolution feature, MaxPooling(·) is the maximum pooling operation for downsampling, and fea1 is the first convolution feature, specifically the output result of the first convolution block in the convolutional network layer;
[0037] Step S313: construct a deconvolution layer, and upsample the output result of the fifth convolution block in the convolution network layer through the deconvolution layer to obtain a deconvolution feature. The calculation formula is:
[0038] ;
[0039] Where Fea5 is the deconvolution feature, Deconv(·) is the deconvolution operation used for upsampling, and fea5 is the fifth convolution feature, specifically the output result of the fifth convolution block in the convolutional network layer;
[0040] Step S314: construct a multi-scale feature concatenation layer, concatenate the pooled convolution feature, the output result of the third convolution block in the convolution network layer, and the deconvolution feature to obtain a multi-scale feature. The calculation formula is:
[0041] ;
[0042] In the formula, Fea multi is a multi-scale feature, Concat(·) is a concatenation operation, and fea3 is the third convolution feature, specifically referring to the output result of the third convolution block in the convolutional network layer;
[0043] Step S315: constructing a convolutional multi-scale feature processing sublayer, specifically by constructing a convolutional network layer, a maximum pooling layer, a deconvolution layer, and a multi-scale feature splicing layer, to obtain a convolutional multi-scale feature processing sublayer;
[0044] Step S316: obtaining a parallel convolutional multi-scale feature processing layer by setting two convolutional multi-scale feature processing sub-layers as a parallel structure;
[0045] Step S317: performing feature processing on the farmland enhanced image and the three-channel depth image through a parallel convolution multi-scale feature processing layer to obtain multi-scale color texture features and multi-scale spatial geometric features;
[0046] Step S32: construct a multimodal feature fusion layer, specifically, splicing the multi-scale color texture features and the multi-scale spatial geometry features through the multimodal feature fusion layer to obtain a multimodal feature fusion result, and the calculation formula is:
[0047] ;
[0048] In the formula, Fea fusion is the result of multimodal feature fusion, Fea one is a multi-scale color and texture feature, Fea two It is a multi-scale spatial geometric feature;
[0049] Step S33: constructing a parallel convolutional feature extractor, specifically by constructing a parallel convolutional multi-scale feature processing layer and a multi-modal feature fusion layer to construct a parallel convolutional feature extractor, thereby obtaining a parallel convolutional feature extractor;
[0050] Step S34: feature extraction, specifically, performing feature extraction on the farmland RGB image and the three-channel depth image through a parallel convolution feature extractor to obtain multimodal features of farmland weeds.
[0051] Further, in step S4, the farmland weed detection is specifically performed by using a lightweight convolutional neural network model to perform farmland weed detection to obtain a farmland weed detection result;
[0052] The lightweight convolutional neural network model includes a lightweight convolution layer, a global maximum pooling layer, a fully connected layer, a feature concatenation layer and a classification output layer;
[0053] The lightweight convolution layer is used to construct three layers of convolution layers to calculate lightweight convolution feature maps;
[0054] The global maximum pooling layer is used to compress the feature map into a single maximum value and reduce the feature dimension after each convolution layer;
[0055] The fully connected layer is used to transmit the output of the global maximum pooling layer and perform full connection of the pooling features, and specifically includes a first fully connected layer, a second fully connected layer and a third fully connected layer;
[0056] The feature concatenation layer is used to concatenate the output features of the fully connected layer;
[0057] The classification output layer is used to output the classification result;
[0058] The farmland weed detection model is constructed, comprising the following steps:
[0059] Step S41: construct a lightweight convolutional layer, specifically construct three convolutional layers in sequence, and perform feature map calculation to obtain a lightweight convolutional feature map. The calculation formula is:
[0060] ;
[0061] In the formula, It is the lightweight convolution feature map corresponding to the lay-th convolution layer, where lay is the convolution layer index, and its value range is {1,2,3}. is the horizontal pixel index of the lightweight convolution feature map, is the vertical pixel index of the lightweight convolution feature map, M is the horizontal pixel feature convolution kernel size, N is the vertical pixel feature convolution kernel size, is the horizontal pixel feature convolution kernel index, is the vertical pixel feature convolution kernel index, I is the original input sample, specifically the multimodal features of farmland weeds, is the lightweight convolution weight corresponding to the lay-th convolution layer, B lay It is the lightweight convolution bias corresponding to the lay-th convolution layer;
[0062] Step S42: construct a global maximum pooling layer, specifically, construct a corresponding global maximum pooling layer after each convolution layer, and perform global maximum pooling processing on the lightweight convolution feature map to obtain pooling feature data. The calculation formula is:
[0063] ;
[0064] In the formula, is the pooled feature data, and max is the maximum value function;
[0065] Step S43: construct a fully connected layer, specifically, construct a fully connected layer after each pooling layer, and activate it using a nonlinear activation function to obtain a first initial fully connected feature, a second initial fully connected feature, and a third initial fully connected feature. The calculation formula is:
[0066] ;
[0067] Wherein, h1 is the first initial fully connected feature, F1 is the first fully connected layer, ReLU(·) is the nonlinear activation function, W1 is the first initial fully connected weight, B1 is the first fully connected bias term, h2 is the second initial fully connected feature, F2 is the second fully connected layer, W2 is the second initial fully connected weight, B2 is the second fully connected bias term, h3 is the third initial fully connected feature, F3 is the third fully connected layer, W3 is the third initial fully connected weight, and B3 is the third fully connected bias term;
[0068] Step S44: construct a feature concatenation layer, specifically, concatenate the first initial fully connected feature and the second initial fully connected feature to obtain a first connection feature, and concatenate the first connection feature and the third initial fully connected feature to obtain a second connection feature, construct two fully connected layers to perform feature processing on the second connection feature, and obtain feature data to be classified. The calculation formula is:
[0069] ;
[0070] In the formula, F C is the feature data to be classified, F5 is the fifth fully connected layer, and F4 is the fourth fully connected layer;
[0071] Step S45: constructing a classification output layer, specifically performing a classification prediction task based on the feature data to be classified, and obtaining a classification prediction output for performing a specific farmland weed detection task;
[0072] Step S46: training the farmland weed detection model, specifically, training the farmland weed detection model by constructing a lightweight convolution layer, a global maximum pooling layer, a fully connected layer, a feature concatenation layer, and a classification output layer to obtain a farmland weed detection model;
[0073] Step S47: generating a farmland weed detection result, specifically, performing farmland weed detection through a farmland weed detection model to obtain a farmland weed detection result.
[0074] Further, in step S5, the farmland weed detection report is generated, specifically, based on the farmland weed detection result, a farmland weed detection report is generated, and farmland weed control suggestions are provided;
[0075] The farmland weed detection report includes weed type, density and distribution.
[0076] The machine learning-based farmland weed detection system provided by the present invention comprises: an image preparation module, an image preprocessing module, a multimodal feature extraction module, a farmland weed detection module and a farmland weed detection report generation module;
[0077] The image preparation module is used for image preparation, and obtains a farmland RGB image and a farmland depth image through image preparation, and sends the farmland RGB image and the farmland depth image to the image preprocessing module;
[0078] The image preprocessing module is used for image preprocessing, and obtains a three-channel depth image and a farmland enhanced image through image preprocessing, and sends the three-channel depth image and the farmland enhanced image to the multimodal feature extraction module;
[0079] The multimodal feature extraction module is used for multimodal feature extraction, obtains multimodal features of farmland weeds through multimodal feature extraction, and sends the multimodal features of farmland weeds to the farmland weed detection module;
[0080] The farmland weed detection module is used for farmland weed detection, obtains farmland weed detection results through farmland weed detection, and sends the farmland weed detection results to the farmland weed detection report generation module;
[0081] The farmland weed detection report generation module is used for generating a farmland weed detection report. According to the farmland weed detection result, the farmland weed detection report is generated and farmland weed control suggestions are provided.
[0082] The beneficial effects achieved by the present invention using the above scheme are as follows:
[0083] (1) In view of the technical problems that the traditional method that relies on manual detection is inefficient, the detection using machine learning technology has high requirements for data quality, and the quality of the original image data directly collected is poor and cannot be directly used for information system processing, this solution creatively uses image restoration combined with image coding to perform image preprocessing, optimizes image quality and converts the image into a form that can be processed and encoded by the information system, unifies the channel structure of RGB images and depth images, enhances the feature expression of depth images, and optimizes the automation and efficiency of farmland weed detection;
[0084] (2) In the existing farmland weed feature extraction methods, the traditional technology is suitable for feature extraction of single image data, which often simply uses convolutional networks to extract feature maps. However, the feature extraction of single image data is prone to inevitably lead to information loss of farmland weed images in the process of extracting and screening features, which in turn leads to the technical problem of insufficient accuracy of weed detection using complex farmland images. This solution creatively uses a parallel convolutional feature extractor for multimodal feature extraction. Through parallel convolution, the farmland RGB image and the three-channel depth image are processed simultaneously, and multimodal feature extraction is performed, which optimizes the precision of feature engineering and reduces information loss.
[0085] (3) In order to address the technical problem that in existing methods for detecting weeds in farmland, complex feature engineering designs can improve the overall accuracy of detection but will also increase the computational complexity of the model, which is not conducive to the overall improvement of detection efficiency, this solution creatively adopts a lightweight convolutional neural network model for farmland weed detection. By constructing only three convolutional layers, the computational complexity of the model is optimized, and multiple global maximum pooling layers and fully connected layers are subsequently set up to ensure the accuracy of feature splicing and classification. This optimizes the overall computational speed and detection efficiency of the method without sacrificing detection accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0086] Figure 1 A schematic diagram of the process of the farmland weed detection method based on machine learning provided by the present invention;
[0087] Figure 2 A schematic diagram of a farmland weed detection system based on machine learning provided by the present invention;
[0088] Figure 3 is a schematic flow chart of step S2;
[0089] Figure 4 is a schematic diagram of the process of step S3;
[0090] Figure 5 It is a schematic diagram of the process of step S4.
[0091] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention. DETAILED DESCRIPTION
[0092] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments; based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0093] In the description of the present invention, it should be understood that terms such as “upper”, “lower”, “front”, “back”, “left”, “right”, “top”, “bottom”, “inside” and “outside” indicating directions or positional relationships are based on the directions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific direction, be constructed and operated in a specific direction, and therefore should not be understood as limiting the present invention.
[0094] Example 1, see Figure 1 The present invention provides a method for detecting weeds in farmland based on machine learning, the method comprising the following steps:
[0095] Step S1: image preparation;
[0096] Step S2: image preprocessing;
[0097] Step S3: multimodal feature extraction;
[0098] Step S4: farmland weed detection;
[0099] Step S5: generating a farmland weed detection report.
[0100] Example 2, see Figure 1 This embodiment is based on the above embodiment. In step S1, the image preparation is specifically to collect images from the farmland through a camera to obtain the farmland RGB image and the farmland depth image.
[0101] Example 3, see Figure 1 and Figure 3 This embodiment is based on the above embodiment. In step S2, the image preprocessing is used to optimize the image quality. Specifically, the image preprocessing is performed through image alignment, image restoration, image encoding and image enhancement to obtain a three-channel depth image and a farmland enhanced image, including the following steps:
[0102] Step S21: image alignment, which is used to reduce the influence of pixel misalignment. Specifically, the image alignment technology is used to align the farmland depth image with the farmland RGB image through coordinate transformation to ensure that the pixels of the different modal images are in the same position, so as to obtain the farmland depth alignment image;
[0103] Step S22: image restoration, which is used to repair holes in the farmland depth alignment image, specifically, by performing image restoration on the farmland depth alignment image through a hole filling algorithm to obtain a farmland depth restoration image;
[0104] Step S23: image encoding, which is used to encode the farmland deep restoration image into a depth image with three channels, thereby unifying the channel structure of the multimodal image, including the following steps:
[0105] Step S231: Calculate the phase information, specifically, use the depth information in the farmland depth restoration image to calculate the phase information of the farmland depth restoration image, and the calculation formula is:
[0106] ;
[0107] In the formula, is the phase information, d is the depth information, which is used to indicate the distance from the camera to each pixel in the farmland depth restoration image, n is the first natural number, which is used to ensure that the phase information falls within the range of [0, 2π), b is the second natural number, 2πb is the uniqueness range of the camera, and the uniqueness range refers to the range in which the camera can accurately measure the depth information. When the uniqueness range is exceeded, the accuracy of the depth information decreases;
[0108] Step S232: Calculate the height above the ground, which is used to represent the height of each pixel in the farmland deep restoration image relative to the ground. The calculation formula is:
[0109] ;
[0110] Where i is the horizontal coordinate index of the pixel point, j is the vertical coordinate index of the pixel point, Hig(i, j) is the height above the ground of the pixel point with coordinate (i, j) in the farmland deep restoration image, and d max is the maximum depth information of the farmland deep restoration image, and d(i, j) is the depth information of the pixel with coordinates (i, j) in the farmland deep restoration image;
[0111] Step S233: calculating angle information, specifically calculating the angle between the surface normal vector of each pixel point in the farmland deep restoration image and the gravity direction;
[0112] Step S234: performing image encoding on the farmland depth restoration image by calculating phase information, height from the ground, and angle information to obtain a three-channel depth image;
[0113] Step S24: image enhancement, specifically, performing image enhancement on the farmland RGB image through image denoising, color correction and contrast enhancement to obtain a farmland enhanced image;
[0114] By performing the above operations, in view of the technical problems in the existing farmland weed detection methods, the traditional methods relying on manual detection are inefficient, the detection using machine learning technology has high requirements for data quality, and the quality of the directly collected original image data is poor and cannot be directly used for information system processing, this solution creatively adopts the method of image restoration combined with image coding for image preprocessing, optimizes the image quality and converts the image into a form that can be processed and encoded by the information system, unifies the channel structure of RGB images and depth images, enhances the feature expression of depth images, and optimizes the automation and efficiency of farmland weed detection.
[0115] Example 4, see Figure 1 and Figure 4 , this embodiment is based on the above embodiment, in step S3, the multimodal feature extraction is specifically performed by using a parallel convolutional feature extractor to extract multimodal features to obtain multimodal features of farmland weeds;
[0116] The parallel convolution feature extractor is used to extract weed multimodal features from the farmland enhanced image and the three-channel depth image, and specifically includes a parallel convolution multi-scale feature processing layer and a multimodal feature fusion layer;
[0117] The parallel convolutional multi-scale feature processing layer is used to capture color texture features and spatial geometric features, and specifically includes two parallel convolutional multi-scale feature processing sub-layers;
[0118] The convolutional multi-scale feature processing sublayer specifically includes a convolutional network layer, a maximum pooling layer, a deconvolution layer and a multi-scale feature splicing layer;
[0119] The multi-scale feature splicing layer is used to splice features of different scales;
[0120] The multimodal feature fusion layer is used to fuse multi-scale multimodal information;
[0121] The multimodal feature extraction comprises the following steps:
[0122] Step S31: construct a parallel convolutional multi-scale feature processing layer, specifically, setting two parallel convolutional multi-scale feature processing sub-layers in the parallel convolutional multi-scale feature processing layer, receiving the farmland enhancement image and the three-channel depth image as input data of different convolutional multi-scale feature processing sub-layers, and calculating through the parallel convolutional multi-scale feature processing layer to obtain multi-scale color texture features and multi-scale spatial geometric features, including the following steps:
[0123] Step S311: constructing a convolutional network layer, specifically setting five convolutional blocks in the convolutional network layer, and calculating the input data through the five convolutional blocks;
[0124] Step S312: construct a maximum pooling layer, and downsample the output result of the first convolution block in the convolutional network layer through the maximum pooling layer to obtain pooled convolution features. The calculation formula is:
[0125] ;
[0126] Where Fea1 is the pooled convolution feature, MaxPooling(·) is the maximum pooling operation for downsampling, and fea1 is the first convolution feature, specifically the output result of the first convolution block in the convolutional network layer;
[0127] Step S313: construct a deconvolution layer, and upsample the output result of the fifth convolution block in the convolution network layer through the deconvolution layer to obtain a deconvolution feature. The calculation formula is:
[0128] ;
[0129] Where Fea5 is the deconvolution feature, Deconv(·) is the deconvolution operation used for upsampling, and fea5 is the fifth convolution feature, specifically the output result of the fifth convolution block in the convolutional network layer;
[0130] Step S314: construct a multi-scale feature concatenation layer, concatenate the pooled convolution feature, the output result of the third convolution block in the convolution network layer, and the deconvolution feature to obtain a multi-scale feature. The calculation formula is:
[0131] ;
[0132] In the formula, Fea multiis a multi-scale feature, Concat(·) is a concatenation operation, and fea3 is the third convolution feature, specifically referring to the output result of the third convolution block in the convolutional network layer;
[0133] Step S315: constructing a convolutional multi-scale feature processing sublayer, specifically by constructing a convolutional network layer, a maximum pooling layer, a deconvolution layer, and a multi-scale feature splicing layer, to obtain a convolutional multi-scale feature processing sublayer;
[0134] Step S316: obtaining a parallel convolutional multi-scale feature processing layer by setting two convolutional multi-scale feature processing sub-layers as a parallel structure;
[0135] Step S317: performing feature processing on the farmland enhanced image and the three-channel depth image through a parallel convolution multi-scale feature processing layer to obtain multi-scale color texture features and multi-scale spatial geometric features;
[0136] Step S32: construct a multimodal feature fusion layer, specifically, splicing the multi-scale color texture features and the multi-scale spatial geometry features through the multimodal feature fusion layer to obtain a multimodal feature fusion result, and the calculation formula is:
[0137] ;
[0138] In the formula, Fea fusion is the result of multimodal feature fusion, Fea one is a multi-scale color and texture feature, Fea two It is a multi-scale spatial geometric feature;
[0139] Step S33: constructing a parallel convolutional feature extractor, specifically by constructing a parallel convolutional multi-scale feature processing layer and a multi-modal feature fusion layer to construct a parallel convolutional feature extractor, thereby obtaining a parallel convolutional feature extractor;
[0140] Step S34: feature extraction, specifically, performing feature extraction on the farmland RGB image and the three-channel depth image through a parallel convolution feature extractor to obtain multimodal features of farmland weeds;
[0141] By performing the above operations, in view of the existing farmland weed feature extraction methods, the traditional technology is suitable for feature extraction of single image data, which often simply uses convolutional networks to extract feature maps. The feature extraction of single image data is prone to inevitably lead to information loss of farmland weed images in the process of extracting and screening features, which in turn leads to the technical problem of insufficient accuracy of weed detection using complex farmland images. This solution creatively uses a parallel convolutional feature extractor for multimodal feature extraction, and simultaneously processes farmland RGB images and three-channel depth images through parallel convolution, and performs multimodal feature extraction, which optimizes the refinement of feature engineering and reduces information loss.
[0142] Example 5, see Figure 1 and Figure 5 , this embodiment is based on the above embodiment, in step S4, the farmland weed detection is specifically to use a lightweight convolutional neural network model to perform farmland weed detection to obtain a farmland weed detection result;
[0143] The lightweight convolutional neural network model includes a lightweight convolution layer, a global maximum pooling layer, a fully connected layer, a feature concatenation layer and a classification output layer;
[0144] The lightweight convolution layer is used to construct three layers of convolution layers to calculate lightweight convolution feature maps;
[0145] The global maximum pooling layer is used to compress the feature map into a single maximum value and reduce the feature dimension after each convolution layer;
[0146] The fully connected layer is used to transmit the output of the global maximum pooling layer and perform full connection of the pooling features, and specifically includes a first fully connected layer, a second fully connected layer and a third fully connected layer;
[0147] The feature concatenation layer is used to concatenate the output features of the fully connected layer;
[0148] The classification output layer is used to output the classification result;
[0149] The farmland weed detection model is constructed, comprising the following steps:
[0150] Step S41: construct a lightweight convolutional layer, specifically construct three convolutional layers in sequence, and perform feature map calculation to obtain a lightweight convolutional feature map. The calculation formula is:
[0151] ;
[0152] In the formula, It is the lightweight convolution feature map corresponding to the lay-th convolution layer, where lay is the convolution layer index, and its value range is {1,2,3}. is the horizontal pixel index of the lightweight convolution feature map, is the vertical pixel index of the lightweight convolution feature map, M is the horizontal pixel feature convolution kernel size, N is the vertical pixel feature convolution kernel size, is the horizontal pixel feature convolution kernel index, is the vertical pixel feature convolution kernel index, I is the original input sample, specifically the multimodal features of farmland weeds, is the lightweight convolution weight corresponding to the lay-th convolution layer, B lay It is the lightweight convolution bias corresponding to the lay-th convolution layer;
[0153] Step S42: construct a global maximum pooling layer, specifically, construct a corresponding global maximum pooling layer after each convolution layer, and perform global maximum pooling processing on the lightweight convolution feature map to obtain pooling feature data. The calculation formula is:
[0154] ;
[0155] In the formula, is the pooled feature data, and max is the maximum value function;
[0156] Step S43: construct a fully connected layer, specifically, construct a fully connected layer after each pooling layer, and activate it using a nonlinear activation function to obtain a first initial fully connected feature, a second initial fully connected feature, and a third initial fully connected feature. The calculation formula is:
[0157] ;
[0158] Wherein, h1 is the first initial fully connected feature, F1 is the first fully connected layer, ReLU(·) is the nonlinear activation function, W1 is the first initial fully connected weight, B1 is the first fully connected bias term, h2 is the second initial fully connected feature, F2 is the second fully connected layer, W2 is the second initial fully connected weight, B2 is the second fully connected bias term, h3 is the third initial fully connected feature, F3 is the third fully connected layer, W3 is the third initial fully connected weight, and B3 is the third fully connected bias term;
[0159] Step S44: construct a feature concatenation layer, specifically, concatenate the first initial fully connected feature and the second initial fully connected feature to obtain a first connection feature, and concatenate the first connection feature and the third initial fully connected feature to obtain a second connection feature, construct two fully connected layers to perform feature processing on the second connection feature, and obtain feature data to be classified. The calculation formula is:
[0160] ;
[0161] In the formula, F C is the feature data to be classified, F5 is the fifth fully connected layer, and F4 is the fourth fully connected layer;
[0162] Step S45: constructing a classification output layer, specifically performing a classification prediction task based on the feature data to be classified, and obtaining a classification prediction output for performing a specific farmland weed detection task;
[0163] Step S46: training the farmland weed detection model, specifically, training the farmland weed detection model by constructing a lightweight convolution layer, a global maximum pooling layer, a fully connected layer, a feature concatenation layer, and a classification output layer to obtain a farmland weed detection model;
[0164] Step S47: generating a farmland weed detection result, specifically, performing farmland weed detection through a farmland weed detection model to obtain a farmland weed detection result;
[0165] By performing the above operations, in order to solve the technical problem that in the existing farmland weed detection methods, although complex feature engineering design can improve the overall accuracy of detection, it will also increase the calculation complexity of the model, which is not conducive to the overall improvement of detection efficiency, this solution creatively adopts a lightweight convolutional neural network model for farmland weed detection, optimizes the calculation complexity of the model by only constructing three convolutional layers, and subsequently ensures the accuracy of feature splicing and classification through the setting of multiple global maximum pooling layers and fully connected layers, thereby optimizing the overall calculation speed and detection efficiency of the method without losing the detection accuracy.
[0166] Example 6, see Figure 1 , this embodiment is based on the above embodiment, in step S5, the farmland weed detection report is generated, specifically, based on the farmland weed detection result, a farmland weed detection report is generated, and farmland weed control suggestions are provided;
[0167] The farmland weed detection report includes weed type, density and distribution.
[0168] Embodiment 7, see Figure 2 , this embodiment is based on the above embodiment, and the farmland weed detection system based on machine learning provided by the present invention includes: an image preparation module, an image preprocessing module, a multimodal feature extraction module, a farmland weed detection module and a farmland weed detection report generation module;
[0169] The image preparation module is used for image preparation, and obtains a farmland RGB image and a farmland depth image through image preparation, and sends the farmland RGB image and the farmland depth image to the image preprocessing module;
[0170] The image preprocessing module is used for image preprocessing, and obtains a three-channel depth image and a farmland enhanced image through image preprocessing, and sends the three-channel depth image and the farmland enhanced image to the multimodal feature extraction module;
[0171] The multimodal feature extraction module is used for multimodal feature extraction, obtains multimodal features of farmland weeds through multimodal feature extraction, and sends the multimodal features of farmland weeds to the farmland weed detection module;
[0172] The farmland weed detection module is used for farmland weed detection, obtains farmland weed detection results through farmland weed detection, and sends the farmland weed detection results to the farmland weed detection report generation module;
[0173] The farmland weed detection report generation module is used for generating a farmland weed detection report. According to the farmland weed detection result, the farmland weed detection report is generated and farmland weed control suggestions are provided.
[0174] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.
[0175] While the embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that many changes, modifications, substitutions and variations can be made to the embodiments without departing from the principles and spirit of the invention.
[0176] The present invention and its embodiments are described above, and such description is not restrictive. The drawings show only one embodiment of the present invention, and the actual structure is not limited thereto. In short, if ordinary technicians in the field are inspired by it, without departing from the purpose of the invention, they can design a structure and embodiment similar to the technical solution without creativity, which should belong to the protection scope of the present invention.
Claims
1. Farmland weed detection method based on machine learning, Features: The method comprises the following steps: Step S1: image preparation; Step S2: image preprocessing, specifically, image preprocessing through image alignment, image restoration, image encoding and image enhancement to obtain a three-channel depth image and a farmland enhanced image, including the following steps: Step S21: image alignment, which is used to reduce the influence of pixel misalignment. Specifically, the image alignment technology is used to align the farmland depth image with the farmland RGB image through coordinate transformation to ensure that the pixels of the different modal images are in the same position, so as to obtain the farmland depth alignment image; Step S22: image restoration, which is used to repair holes in the farmland depth alignment image, specifically, by performing image restoration on the farmland depth alignment image through a hole filling algorithm to obtain a farmland depth restoration image; Step S23: image encoding, which is used to encode the farmland deep restoration image into a depth image with three channels, thereby unifying the channel structure of the multimodal image, including the following steps: Step S231: Calculate the phase information, specifically, use the depth information in the farmland depth restoration image to calculate the phase information of the farmland depth restoration image, and the calculation formula is: ; In the formula, is the phase information, d is the depth information, which is used to indicate the distance from the camera to each pixel in the farmland depth restoration image, n is the first natural number, which is used to ensure that the phase information falls within the range of [0, 2π), b is the second natural number, 2πb is the uniqueness range of the camera, and the uniqueness range refers to the range in which the camera can accurately measure the depth information. When the uniqueness range is exceeded, the accuracy of the depth information decreases; Step S232: Calculate the height above the ground, which is used to represent the height of each pixel in the farmland deep restoration image relative to the ground. The calculation formula is: ; Where i is the horizontal coordinate index of the pixel point, j is the vertical coordinate index of the pixel point, Hig(i, j) is the height above the ground of the pixel point with coordinate (i, j) in the farmland deep restoration image, and d max is the maximum depth information of the farmland deep restoration image, and d(i, j) is the depth information of the pixel with coordinates (i, j) in the farmland deep restoration image; Step S233: calculating angle information, specifically calculating the angle between the surface normal vector of each pixel point in the farmland deep restoration image and the gravity direction; Step S234: performing image encoding on the farmland depth restoration image by calculating phase information, height from the ground, and angle information to obtain a three-channel depth image; Step S24: image enhancement, specifically, performing image enhancement on the farmland RGB image through image denoising, color correction and contrast enhancement to obtain a farmland enhanced image; Step S3: multimodal feature extraction, using a parallel convolutional feature extractor to extract multimodal features to obtain multimodal features of farmland weeds; The parallel convolution feature extractor is used to extract weed features from the farmland enhanced image and the three-channel depth image, and specifically includes a parallel convolution multi-scale feature processing layer and a multi-modal feature fusion layer; The parallel convolutional multi-scale feature processing layer is used to capture color texture features and spatial geometric features, and specifically includes two parallel convolutional multi-scale feature processing sub-layers; The convolutional multi-scale feature processing sublayer specifically includes a convolutional network layer, a maximum pooling layer, a deconvolution layer and a multi-scale feature splicing layer; The multi-scale feature splicing layer is used to splice features of different scales; The multimodal feature fusion layer is used to fuse multi-scale multimodal information; Step S4: farmland weed detection, specifically using a lightweight convolutional neural network model to construct a farmland weed detection model to obtain farmland weed detection results; The lightweight convolutional neural network model includes a lightweight convolution layer, a global maximum pooling layer, a fully connected layer, a feature splicing layer and a classification output layer; The lightweight convolution layer is used to construct three layers of convolution layers to calculate lightweight convolution feature maps; The global maximum pooling layer is used to compress the feature map into a single maximum value and reduce the feature dimension after each convolution layer; The fully connected layer is used to transmit the output of the global maximum pooling layer and perform full connection of the pooling features, and specifically includes a first fully connected layer, a second fully connected layer and a third fully connected layer; The feature concatenation layer is used to concatenate the output features of the fully connected layer; The classification output layer is used to output the classification result; The farmland weed detection model is constructed, comprising the following steps: Step S41: construct a lightweight convolutional layer, specifically construct three convolutional layers in sequence, and perform feature map calculation to obtain a lightweight convolutional feature map. The calculation formula is: ; In the formula, It is the lightweight convolution feature map corresponding to the lay-th convolution layer, where lay is the convolution layer index, and its value range is {1,2,3}. is the horizontal pixel index of the lightweight convolution feature map, is the vertical pixel index of the lightweight convolution feature map, M is the horizontal pixel feature convolution kernel size, N is the vertical pixel feature convolution kernel size, is the horizontal pixel feature convolution kernel index, is the vertical pixel feature convolution kernel index, I is the original input sample, specifically the multimodal features of farmland weeds, is the lightweight convolution weight corresponding to the lay-th convolution layer, B lay It is the lightweight convolution bias corresponding to the lay-th convolution layer; Step S42: construct a global maximum pooling layer, specifically, construct a corresponding global maximum pooling layer after each convolution layer, and perform global maximum pooling processing on the lightweight convolution feature map to obtain pooling feature data. The calculation formula is: ; In the formula, is the pooled feature data, and max is the maximum value function; Step S43: construct a fully connected layer, specifically, construct a fully connected layer after each pooling layer, and activate it using a nonlinear activation function to obtain a first initial fully connected feature, a second initial fully connected feature, and a third initial fully connected feature. The calculation formula is: ; In the formula, h 1 is the first initial fully connected feature, F 1 is the first fully connected layer, ReLU(·) is the nonlinear activation function, W 1 is the first initial fully connected weight, B 1 is the first fully connected bias term, h 2 is the second initial fully connected feature, F 2 is the second fully connected layer, W 2 is the second initial fully connected weight, B 2 is the second fully connected bias term, h 3 is the third initial fully connected feature, F 3 is the third fully connected layer, W 3 is the third initial fully connected weight, B 3 is the third fully connected bias term; Step S44: construct a feature concatenation layer, specifically, concatenate the first initial fully connected feature and the second initial fully connected feature to obtain a first connection feature, and concatenate the first connection feature and the third initial fully connected feature to obtain a second connection feature, construct two fully connected layers to perform feature processing on the second connection feature, and obtain feature data to be classified. The calculation formula is: ; In the formula, F C is the feature data to be classified, F 5 is the fifth fully connected layer, F 4 It is the fourth fully connected layer; Step S45: constructing a classification output layer, specifically performing a classification prediction task based on the feature data to be classified, and obtaining a classification prediction output for performing a specific farmland weed detection task; Step S46: training the farmland weed detection model, specifically, training the farmland weed detection model by constructing a lightweight convolution layer, a global maximum pooling layer, a fully connected layer, a feature concatenation layer, and a classification output layer to obtain a farmland weed detection model; Step S47: generating a farmland weed detection result, specifically, performing farmland weed detection through a farmland weed detection model to obtain a farmland weed detection result; Step S5: generating a farmland weed detection report.
2. The method for detecting weeds in farmland based on machine learning according to claim 1, Features: In step S3, the multimodal feature extraction includes the following steps: Step S31: construct a parallel convolutional multi-scale feature processing layer; Step S32: construct a multimodal feature fusion layer, specifically, splicing the multi-scale color texture features and the multi-scale spatial geometry features through the multimodal feature fusion layer to obtain a multimodal feature fusion result, and the calculation formula is: ; In the formula, Fea fusion is the result of multimodal feature fusion, Fea one is a multi-scale color and texture feature, Fea two It is a multi-scale spatial geometric feature; Step S33: constructing a parallel convolutional feature extractor, specifically by constructing a parallel convolutional multi-scale feature processing layer and a multi-modal feature fusion layer to construct a parallel convolutional feature extractor, thereby obtaining a parallel convolutional feature extractor; Step S34: feature extraction, specifically, performing feature extraction on the farmland RGB image and the three-channel depth image through a parallel convolution feature extractor to obtain multimodal features of farmland weeds.
3. The method for detecting weeds in farmland based on machine learning according to claim 2, Features: In step S31, the parallel convolutional multi-scale feature processing layer is constructed, specifically, two parallel convolutional multi-scale feature processing sub-layers are set in the parallel convolutional multi-scale feature processing layer, the farmland enhancement image and the three-channel depth image are received as input data of different convolutional multi-scale feature processing sub-layers, and multi-scale color texture features and multi-scale spatial geometric features are obtained by calculating through the parallel convolutional multi-scale feature processing layer, including the following steps: Step S311: constructing a convolutional network layer, specifically setting five convolutional blocks in the convolutional network layer, and calculating the input data through the five convolutional blocks; Step S312: construct a maximum pooling layer, and downsample the output result of the first convolution block in the convolutional network layer through the maximum pooling layer to obtain a pooled convolution feature. The calculation formula is: ; In the formula, Fea 1 is the pooled convolution feature, MaxPooling(·) is the maximum pooling operation for downsampling, fea 1 It is the first convolution feature, specifically the output result of the first convolution block in the convolutional network layer; Step S313: construct a deconvolution layer, and upsample the output result of the fifth convolution block in the convolution network layer through the deconvolution layer to obtain a deconvolution feature. The calculation formula is: ; In the formula, Fea 5 is the deconvolution feature, Deconv(·) is the deconvolution operation used for upsampling, fea 5 It is the fifth convolution feature, specifically the output result of the fifth convolution block in the convolutional network layer; Step S314: construct a multi-scale feature concatenation layer, concatenate the pooled convolution feature, the output result of the third convolution block in the convolution network layer, and the deconvolution feature to obtain a multi-scale feature. The calculation formula is: ; In the formula, Fea multi is a multi-scale feature, Concat(·) is a concatenation operation, fea 3 It is the third convolution feature, specifically refers to the output result of the third convolution block in the convolutional network layer; Step S315: constructing a convolutional multi-scale feature processing sublayer, specifically by constructing a convolutional network layer, a maximum pooling layer, a deconvolution layer, and a multi-scale feature splicing layer, to obtain a convolutional multi-scale feature processing sublayer; Step S316: obtaining a parallel convolutional multi-scale feature processing layer by setting two convolutional multi-scale feature processing sub-layers as a parallel structure; Step S317: feature processing is performed on the farmland enhanced image and the three-channel depth image through a parallel convolution multi-scale feature processing layer to obtain multi-scale color texture features and multi-scale spatial geometric features.
4. The method for detecting weeds in farmland based on machine learning according to claim 3, Features: In step S1, the image preparation is specifically to collect images from the farmland through a camera to obtain the farmland RGB image and the farmland depth image; In step S5, the farmland weed detection report is generated, specifically, based on the farmland weed detection result, a farmland weed detection report is generated and farmland weed control suggestions are provided.
5. A farmland weed detection system based on machine learning, used to implement the farmland weed detection method based on machine learning as described in any one of claims 1 to 4, Features: include: Image preparation module, image preprocessing module, multimodal feature extraction module, farmland weed detection module and farmland weed detection report generation module.
6. The farmland weed detection system based on machine learning according to claim 5, Features: The image preparation module is used for image preparation, and obtains a farmland RGB image and a farmland depth image through image preparation, and sends the farmland RGB image and the farmland depth image to the image preprocessing module; The image preprocessing module is used for image preprocessing, and obtains a three-channel depth image and a farmland enhanced image through image preprocessing, and sends the three-channel depth image and the farmland enhanced image to the multimodal feature extraction module; The multimodal feature extraction module is used for multimodal feature extraction, obtains multimodal features of farmland weeds through multimodal feature extraction, and sends the multimodal features of farmland weeds to the farmland weed detection module; The farmland weed detection module is used for farmland weed detection, obtains farmland weed detection results through farmland weed detection, and sends the farmland weed detection results to the farmland weed detection report generation module; The farmland weed detection report generation module is used for generating a farmland weed detection report. According to the farmland weed detection result, the farmland weed detection report is generated and farmland weed control suggestions are provided.
