Detection method of bag-grown mushrooms based on improved YOLOV4 algorithm
By improving the YOLO v4 algorithm, combined with the residual edge attention mechanism and depth-separable convolution, the problem of low detection accuracy of shiitake mushrooms in bag cultivation environment is solved, and the detection accuracy and resistance to brightness diversity, occlusion, and adhesion interference are improved. Recognition effect, suitable for mechanical picking.
Patent Information
- Application Number
- CN202210009676.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-06
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2042-01-06
AI Technical Summary
The existing technology has low detection accuracy in detecting shiitake mushrooms in a bag cultivation environment, especially when the image brightness is diverse and the shiitake mushrooms are blocking and adhering to each other, and the recognition effect is poor.
Improve the YOLO v4 algorithm, build a network including the backbone network, SPP structure, PANet structure and YOLO_three_head prediction part, increase the prediction feature map transmission path and embed the residual edge attention mechanism module, through depth separable convolution and feature map splicing and fusion, Optimize the training process and loss function to improve detection accuracy.
It improves the accuracy of mushroom detection in bag cultivation environment and the detection effect under the conditions of diversified image brightness, occlusion, and adhesion interference, reduces the amount of algorithm parameters, and is suitable for visual support of mechanical picking.
Smart Images

Figure CN114359387B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of machine vision target detection, and in particular to a machine vision detection method for bag-grown shiitake mushrooms based on an improved YOLO v4 algorithm. Background Art
[0002] At present, machine vision detection of shiitake mushrooms mostly relies on traditional digital image knowledge, and manually designs to extract features such as the color, shape, and thickness of the mushroom cap. This method is greatly affected by light brightness factors, and has poor recognition effects on the adhesion and occlusion of shiitake mushrooms in actual environments. The rise of machine vision target detection in recent years has provided a new method for shiitake mushroom detection. By building a neural network and conducting supervised training on shiitake mushroom images, the network automatically learns features and the accuracy is improved. Compared with traditional detection methods, detection based on the YOLO v4 algorithm can extract more complete recognition features.
[0003] For the detection and recognition of shiitake mushrooms in bag cultivation environments, especially the recognition and detection of small targets at long distances caused by mutual occlusion and adhesion caused by natural growth, the detection effect relying on traditional digital image knowledge cannot meet the needs of practical applications.
[0004] Therefore, how to improve the detection accuracy of shiitake mushrooms in a bag cultivation environment, and how to improve the detection effect under the interference of mutual occlusion and adhesion of shiitake mushrooms is an urgent problem to be solved by technical personnel in this field. Summary of the invention
[0005] In view of this, the present invention provides a machine vision detection method for bag-grown mushrooms based on an improved YOLO v4 algorithm. By improving the YOLO v4 algorithm, the problem that the existing methods have difficulty meeting the actual application requirements in terms of detection accuracy and image brightness diversity is effectively solved.
[0006] In order to achieve the above object, the present invention adopts the following technical solution:
[0007] A machine vision detection method for bag-grown mushrooms based on an improved YOLO v4 algorithm comprises the following steps:
[0008] S1. Build an improved YOLO v4 network: including the backbone network part, SPP structure part, PANet structure part and YOLO_three_head prediction part. Add a predicted feature map transmission path to the PANet structure part. The predicted feature map transmission path is initially connected to the backbone network and is spliced and fused with the feature map in the PANet structure. The attention mechanism module R_cbam with residual edges is embedded in the path.
[0009] S2. Training the improved YOLO v4 network: inputting the training set made of the mushroom pictures taken in the bag cultivation environment and the mushroom position annotation information into the built improved YOLO v4 network to train the weight parameters, and obtaining the trained YOLO v4 network parameters;
[0010] S3. Mushroom image detection: Load the trained parameters and input the mushroom color image into the trained YOLO v4 network to obtain the final feature map and generate a detection frame to automatically locate the mushroom in the image.
[0011] Preferably, in the SPP structure part, the PANet structure part and the YOLO_three_head prediction part, depthwise separable convolution is used.
[0012] Preferably, the predicted feature map transmission path starts at the first CSP-8 structure of the backbone network, and the feature map size at the first CSP-8 structure is twice that at the next CSP-8 structure.
[0013] Preferably, an attention mechanism module R_cbam with a residual edge is added to two input ends and one output end in the predicted feature map transmission path, the first input end receives the feature map generated after passing through the first CSP-8 of the backbone network; the second input end receives the maximum size feature map generated after upsampling (UPsam) and concatenation (concat) to the DBL layer in the PANet of the original algorithm; the output end is spliced and fused with the feature map of the second input end and integrated into PANet.
[0014] Preferably, the residual edge attention mechanism module R_cbam includes two sub-parts, Res_cam and Res_sam, and the two sub-modules are connected in series so that the feature maps pass through successively in sequence, and the dimension of the feature map output by each sub-module is the same as the dimension at the time of input;
[0015] The implementation process of each Res_cam step is as follows:
[0016] S111. The starting feature map of the Res_cam module is reduced in dimension through the maximum pooling layer and the average pooling layer to obtain two sets of features. Figure 1 , the dimensions are all c×1×1;
[0017] S112: The two sets of feature maps are respectively passed through a weight sharing network, and the two sets of feature maps obtained are output. Figure 2 , with a dimension of c×1×1, the two sets of features obtained Figure 2 Add them together to get a feature map with a dimension of c×1×1, and then multiply the feature map with a dimension of c×1×1 by the starting feature map of the Res_cam module to get a feature map with a dimension of c×w×h;
[0018] S113, finally, the starting feature map of the Res_cam module is added to the feature map obtained in step S112 through the residual edge;
[0019] The implementation process of each part of Res_sam is as follows:
[0020] S121, the starting feature map of the Res_sam module is subjected to dimensionality reduction by the maximum pooling layer and the average pooling layer respectively, to obtain two sets of feature maps, both of which have dimensions of 1×w×h, and then concatenated to obtain a feature map of dimension 2×w×h;
[0021] S122, the concatenated feature map is passed through a convolutional dimension reduction layer to reduce the dimension of the feature map with a dimension of 2×w×h to obtain a feature map with a dimension of 1×w×h, and then a sigmoid function is activated and multiplied with the starting feature map of the Res_sam module to obtain a feature map with a dimension of c×w×h;
[0022] S123. Finally, the starting feature map of the Res_sam module is added to the feature map obtained in step S122 through the residual edge.
[0023] Preferably, the total loss function is:
[0024] Loss_object=c1·loss_predict+c2·loss_conf
[0025] Among them, loss_conf is the confidence loss, loss_predict is the prediction box position regression loss, and C1 and C2 are the balance coefficients between the two.
[0026] Preferably, the mushroom pictures are subjected to a gamma_two transformation, and the mushroom pictures before and after the transformation are used as the mushroom picture training set.
[0027] Preferably, the training set obtained after the gamma_two transformation is denoised and trained together with the training set obtained after the gamma_two transformation.
[0028] Preferably, during training, the pre-trained weights of the COCO-Train2017 dataset are first loaded into the backbone network, and then the loaded training parameters are frozen, unfrozen after the Nth epoch, and trained together with the parameters of other modules in the improved YOLO v4 network. After each batch, the loss function is calculated and the parameters are updated in reverse, and the cycle is repeated until the loss function meets the requirements and the training is stopped.
[0029] Compared with the prior art, the present invention has the following beneficial effects:
[0030] The present invention improves the detection accuracy of shiitake mushrooms in a bag cultivation environment by improving the YOLO v4 algorithm, and improves the detection effect under the interference of image brightness diversity, mutual occlusion and adhesion of shiitake mushrooms. At the same time, the number of algorithm parameters is greatly reduced, which is beneficial to equipment deployment and better provides visual algorithm support for mechanical picking. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on the provided drawings without creative work.
[0032] Figure 1 It is a flow chart of the machine vision detection method of bag-grown mushrooms based on the improved YOLO v4 algorithm provided by the present invention;
[0033] Figure 2 is a gamma_two transformation example provided by the present invention;
[0034] Figure 3 It is a schematic diagram of the improved YOLO v4 algorithm provided by the present invention;
[0035] Figure 4 It is a structural diagram of the dimension change of the algorithm feature graph provided by the present invention;
[0036] Figure 5 It is a schematic diagram of the internal structure of Res_cam provided by the present invention;
[0037] Figure 6 It is a schematic diagram of the internal structure of Res_sam provided by the present invention;
[0038] Figure 7 It is a schematic diagram of the decline of the loss function of the training set and the validation set provided by the present invention;
[0039] Figure 8 This is an example of the detection effect of the present invention on occlusion, adhesion, blur and long-distance small targets. DETAILED DESCRIPTION
[0040] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0041] Specifically, the embodiment of the present invention discloses a machine vision detection method for bag-grown mushrooms based on an improved YOLO v4 algorithm. First, the implementation steps of the entire detection method are as follows (see Figure 1 )as follows:
[0042] S1. Build an improved YOLO v4 network: including the backbone network part, SPP structure part, PANet structure part and YOLO_three_head prediction part. Add a prediction feature map transmission path to the PANet structure part. The prediction feature map transmission path starts and connects to the first CSP-8 of the backbone network (see Figure 3 ), and concatenated with the feature map in the PANet structure, and the attention mechanism module R_cbam with residual edges is embedded in the path. Among them, the first CSP-8 of the backbone network is twice the feature map of the next CSP-8 structure. The larger size makes it difficult to lose small target features.
[0043] In the SPP structure part, PANet structure part and YOLO_three_head prediction part, depth-wise separable convolution (DSP) is used;
[0044] An attention mechanism module R_cbam with residual edges is added to the two input ends and one output end of the predicted feature map transmission path. The first input end receives the feature map generated after the first CSP-8 of the backbone network; the second input end receives the maximum size feature map generated after upsampling (UPsam) and concatenation (concat) in the PANet of the original algorithm to the DBL layer; the feature maps of the two input ends pass through two R_cbams respectively, and then perform DBL, UPsam and concat in turn to generate feature maps, and then downsample (Dsam) after DBL to output feature maps. The feature map output after adding R_cbam is used as the output end, which is spliced and fused with the feature map of the second input end and integrated into PANet. The dimension change of the feature map of this algorithm is as follows: Figure 4 ;
[0045] The residual edge attention mechanism module R_cbam consists of two sub-parts, Res_cam and Res_sam. The two sub-modules are connected in series so that the feature maps pass through in sequence, and the dimension of the feature map output by each sub-module is the same as the dimension of the input. The implementation process of each part is as follows:
[0046] Res_cam each implementation process (such as Figure 5 )for:
[0047] S111. The starting feature map of the Res_cam module is reduced in dimension through the maximum pooling layer and the average pooling layer to obtain two sets of features. Figure 1 , the dimensions are all c×1×1;
[0048] S112, get two sets of features from S111 Figure 1 After passing through the weight sharing network, the two sets of features with dimensions of c×1×1 are obtained. Figure 2 , the two sets of features obtained Figure 2 Add them together to get a feature map with a dimension of c×1×1, and then multiply the feature map with a dimension of c×1×1 by the starting feature map of the Res_cam module to get a feature map with a dimension of c×w×h;
[0049] S113, finally, the starting feature map of the Res_cam module is added to the feature map obtained in step S112 through the residual edge;
[0050] Res_sam each implementation process (such as Figure 6 )for:
[0051] S121, the starting feature map of the Res_sam module is subjected to dimensionality reduction by the maximum pooling layer and the average pooling layer respectively, to obtain two sets of feature maps, both of which have dimensions of 1×w×h, and then concatenated to obtain a feature map of dimension 2×w×h;
[0052] S122, after passing through the convolutional dimension reduction layer, the feature map with a dimension of 2×w×h is reduced to obtain a feature map with a dimension of 1×w×h, and then the 1×w×h feature map is activated by the sigmoid function and multiplied with the starting feature map of the Res_sam module to obtain a feature map with a dimension of c×w×h;
[0053] S123. Finally, the starting feature map of the Res_sam module is added to the feature map obtained in step S122 through the residual edge.
[0054] Since this algorithm has only one detection target, namely mushrooms, in order to simplify the algorithm structure and make it easier to maintain, the classification loss is removed. The total loss function is:
[0055] Loss_object=c1·loss_predict+c2·loss_conf
[0056] Among them, loss_conf is the confidence loss, loss_predict is the prediction box position regression loss, and C1 and C2 are the balance coefficients between the two.
[0057] S2. Training the improved YOLO v4 network: inputting the training set made of mushroom pictures and annotation information taken in a bag material environment into the built improved YOLO v4 network for weight parameter training to obtain the trained YOLO v4 network parameters;
[0058] First, in terms of data image processing, the mushrooms in the bag cultivation environment were photographed from multiple angles and distances, and a portion of the photographs were randomly selected in proportion for gamma_two transformation (the effect is as follows Figure 2 ), the expression of gama_two is:
[0059] k x =x σ
[0060] Among them, x is the pixel value of the original image, k x is the value of x pixel after transformation, σ is the transformation factor (σ values are 2 and 0.5 respectively),
[0061] The transformed photos constitute the training set. In one embodiment, 4 / 5 of the prepared data set is randomly selected for gamma_two transformation, and the remaining 1 / 5 is divided into a validation set and a prediction set at a ratio of 1:1. When 1000 pictures containing shiitake mushrooms are obtained, the target frame position of the shiitake mushrooms is marked, and 800 of them are randomly selected for gamma_two transformation. After the transformation, the number is expanded to 2400 to simulate different brightness. The remaining 200 are divided into a validation set and a prediction set at a ratio of 1:1, and the expanded 2400 pictures are set as the training set;
[0062] Secondly, the expanded training set is denoised. In one embodiment, 1 / 4 of the images in the training set are extracted and Gaussian noise is added. The Gaussian noise expression is:
[0063] P y =y+G[rand(y),u,σ],
[0064]
[0065] Among them, y is the pixel value of the image before adding noise, p x is the pixel value after adding noise, the rand function is used to generate random numbers, G(x,u,σ) is a Gaussian distribution with a mean of u and a variance of σ, x is the input value of the Gaussian distribution, and in one example, u is 0 and σ is 25;
[0066] During training, the training weights of the COCO-Train2017 dataset are first loaded into the backbone network, and then the loaded training parameters are frozen and unfrozen after the Nth epoch, and the parameters of other modules in the improved YOLO v4 network are put into training together. After each batch, the loss function is calculated and the parameters are updated in reverse, and the cycle is repeated until the loss function meets the requirements and the training is stopped. In one embodiment, the unfreezing is performed after 70 epochs. At this time, the loss function in the experiment is as follows Figure 7As shown in the figure, the horizontal axis is the number of epochs and the vertical axis is the loss value. At 100 epochs, the curve is basically stable, the loss value no longer decreases, and reaches a stable state. The training parameters at this time are saved as a .pth file.
[0067] S3, mushroom image detection: load the trained .pth file into the constructed network, and input the mushroom color image into the trained YOLO v4 network. Convert the captured color image into RGB format through testing, and use the obtained three-channel R, G and B feature maps as input. Then, pass through the backbone network, SPP structure area part, PANet part and YOLO_three_head prediction part in turn to obtain the final feature map, and generate a detection frame, that is, to realize mushroom detection and automatically locate the mushroom in the image. Among them, the detection effect sample is as follows: Figure 8 shown.
[0068] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0069] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A detection method for bag-grown mushrooms based on an improved YOLOV4 algorithm, characterized in that: The steps include: S1. Build an improved YOLO v4 network: including the backbone network part, SPP structure part, PANet structure part and YOLO_three_head prediction part. Add a predicted feature map transmission path to the PANet structure part. The predicted feature map transmission path is initially connected to the backbone network and is spliced and fused with the feature map in the PANet structure. The attention mechanism module R_cbam with residual edges is embedded in the path. The residual edge attention mechanism module R_cbam includes two sub-parts, Res_cam and Res_sam. The two sub-modules are connected in series so that the feature maps pass through successively, and the dimension of the feature map output by each sub-module is the same as the dimension of the input; The implementation process of Res_cam is as follows: S111, the starting feature map of the Res_cam module is subjected to dimensionality reduction by the maximum pooling layer and the average pooling layer respectively, and two sets of feature maps are obtained, both of which have dimensions of c×1×1; S112, respectively passing the two sets of feature maps through a weight sharing network, outputting two sets of feature maps 2 with a dimension of c×1×1, adding the two sets of feature maps 2 to obtain a feature map with a dimension of c×1×1, and then multiplying the obtained feature map with a dimension of c×1×1 with the starting feature map of the Res_cam module to obtain a feature map with a dimension of c×w×h; S113, finally, the starting feature map of the Res_cam module is added to the feature map obtained in step S112 through the residual edge; The implementation process of Res_sam is: S121, the starting feature map of the Res_sam module is subjected to dimensionality reduction by the maximum pooling layer and the average pooling layer respectively, to obtain two sets of feature maps, both of which have dimensions of 1×w×h, and then concatenated to obtain a feature map of dimension 2×w×h; S122, the concatenated feature map is passed through a convolutional dimension reduction layer to reduce the dimension of the feature map with a dimension of 2×w×h to obtain a feature map with a dimension of 1×w×h, and then a sigmoid function is activated and multiplied with the starting feature map of the Res_sam module to obtain a feature map with a dimension of c×w×h; S123, finally, the starting feature map of the Res_sam module is added to the feature map obtained in step S122 through the residual edge; S2. Training the improved YOLO v4 network: inputting the training set made of the mushroom pictures taken in the bag cultivation environment and the mushroom position annotation information into the built improved YOLO v4 network to train the weight parameters, and obtaining the trained YOLO v4 network parameters; S3. Mushroom image detection: Load the trained parameters and input the mushroom color image into the trained YOLO v4 network to obtain the final feature map and generate a detection frame to automatically locate the mushroom in the image.
2. The method for detecting bag-grown mushrooms based on the improved YOLOV4 algorithm according to claim 1, characterized in that: In the SPP structure part, PANet structure part and YOLO_three_head prediction part, depth-wise separable convolution is used.
3. The method for detecting bag-grown mushrooms based on the improved YOLOV4 algorithm according to claim 1, characterized in that: The predicted feature map transmission path starts at the first CSP-8 structure of the backbone network, and the feature map size at the first CSP-8 structure is twice that of the next CSP-8 structure.
4. The method for detecting mushrooms grown in bags based on an improved YOLOV4 algorithm according to claim 1, characterized in that: An attention mechanism module R_cbam with a residual edge is added to two input ends and one output end in the predicted feature map transmission path, the first input end receives the feature map generated after passing through the first CSP-8 of the backbone network; the second input end receives the maximum size feature map generated after upsampling and splicing to the DBL layer in the PANet of the original algorithm; the feature map of the output end is spliced and fused with the feature map of the second input end and integrated into PANet.
5. The method for detecting mushrooms grown in bags based on an improved YOLOV4 algorithm according to claim 1, characterized in that: The total loss function is: Loss_object=c1·loss_predict+c2·loss_conf Among them, loss_conf is the confidence loss, loss_predict is the prediction box position regression loss, and C1 and C2 are the balance coefficients between the two.
6. The method for detecting mushrooms grown in bags based on an improved YOLOV4 algorithm according to claim 1, characterized in that: The mushroom pictures are subjected to a gamma_two transformation, and the mushroom pictures before and after the transformation are used as the mushroom picture training set.
7. The method for detecting bag-grown mushrooms based on the improved YOLOV4 algorithm according to claim 1, characterized in that: The training set obtained after gamma_two transformation is denoised and trained together with the training set obtained after gamma_two transformation.
8. A bag-cultivated mushroom detection method based on an improved YOLOV4 algorithm according to claim 1, characterized in that: During training, the pre-trained weights of the COCO-Train2017 dataset are first loaded into the backbone network, and then the loaded training parameters are frozen. After the Nth epoch, they are unfrozen and trained together with the parameters of other modules in the improved YOLO v4 network. After each batch, the loss function is calculated and the parameters are updated in reverse, and the cycle is repeated until the loss function meets the requirements and the training is stopped.
