Apple recognition algorithm in complex orchard environment
Through the Rep-ViG-Apple model, combined with RepIRD Block, SGVA and Rep-FPN-PAN network, the problem of generalization and feature information extraction and fusion of apple detection in complex environments is solved, and efficient identification and model compression of apple detection are achieved. Improved the accuracy and efficiency of automated apple picking.
Patent Information
- Application Number
- CN202410723249.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-05
- Publication Date
- 2024-10-01
Smart Images

Figure CN118736483A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of apple recognition and detection, and in particular to an apple recognition algorithm in a complex orchard environment. Background Art
[0002] Apple is an important part of my country's fruit industry, with a wide planting area and high total output. The intelligence and automation of the apple industry are of great significance to the development of domestic agriculture and economy. Apple picking is an important part of the apple production process. Due to the complex environment of apple orchards, apples are currently mainly picked manually during the harvest season, which has problems such as high labor costs and low production efficiency. It is an inevitable trend to replace manual picking with mechanical automated picking. Accurate detection of apples in the complex environment of orchards is an important part of mechanical automated picking. However, in the scene of apple detection in real apple orchards, the natural environment is relatively complex, which makes it difficult to identify apple targets. Therefore, designing a method that can achieve stable detection of apples in complex environments has important practical significance and broad application prospects.
[0003] At present, there are still some difficulties in apple detection in complex environments. For example, in the actual orchard environment, due to the interference of complex environments such as weather and low-light environments, the use of relatively simple data training will lead to weak generalization of the model; the leaves and apples are similar in color, branches and trunks block and overlap each other, and apples are of different sizes and shapes. It is difficult for the algorithm to effectively extract and fuse the feature information of apples, resulting in missed detections and false detections in the apple detection algorithm. Summary of the invention
[0004] The purpose of the present invention is to provide an apple recognition algorithm in a complex orchard environment to solve the problems raised in the above background technology.
[0005] In order to achieve the above-mentioned invention object, the present invention adopts the following technical scheme:
[0006] The present invention provides an apple recognition algorithm in a complex orchard environment, specifically using a Rep-ViG-Apple model, and the construction of the Rep-ViG-Apple model specifically includes the following steps:
[0007] S1: To address the problem of insufficient feature information of apples in complex environments, the RepIRD Block module is proposed and the SGVA module is introduced to design a new Rep-ViG feature extraction network;
[0008] S2: To address the problem of insufficient fusion of apple feature information, a RepConvsBlock re-parameterization module is proposed, and a Rep-FPN-PAN feature fusion network is constructed;
[0009] S3: To address the problem of weak model generalization, an offline data enhancement algorithm that simulates the real environment is proposed to expand the apple detection dataset. It is combined with the mosaic online data enhancement algorithm and applied to the training set to design an offline and online dual hybrid training data enhancement strategy.
[0010] S4: To address the problem of large computational complexity and large number of parameters in the improved Rep-ViG-Apple model, a channel pruning algorithm based on the LAMP score is adopted to prune redundant feature maps of the model, thereby compressing the size of the model to the greatest extent while ensuring the accuracy of the model, so as to achieve a balance between the computational complexity and accuracy of the model.
[0011] Preferably, in step S1, the RepIRD Block module extracts multi-scale feature information in the training stage to enhance the feature extraction capability of occluded and overlapping targets, and merges multiple branches into a single branch structure in the reasoning stage to losslessly compress the model; the SVGA module in step S1 is used to capture global feature information to enhance the focus on apples.
[0012] Preferably, in step S2, the Rep-FPN-PAN feature fusion network fuses multi-scale apple feature information in the training stage to improve the recognition ability of apple targets of different sizes; and merges into a single branch structure in the reasoning stage to reduce the computational complexity of the model and improve the detection speed of the model.
[0013] Preferably, in step S3, the simulated real environment includes different real weather environments such as rainy days, foggy days, cloudy days and low-light environments.
[0014] Preferably, in step S1, the proposal of the RepIRD Block module specifically includes a RepDwConv training phase, a merging of deep convolution and batch normalization layers, a multi-branch merging process into a single branch, and a RepDwConv reasoning phase.
[0015] Preferably, the RepDwConv module uses three different parallel branches of deep convolution with convolution kernel sizes of 3x3 and 1x1 and residual connection to capture information during the model training stage. At the same time, the three branches use batch normalization operations respectively, and then the outputs of the three branches are summed element by element. Finally, the GELU activation function is used to fuse multi-scale feature information in different spatial receptive fields.
[0016] Preferably, in the process of merging the depth convolution and batch normalization layer, the operation formula (1) of the depth convolution is:
[0017] DwConv(x d )=wDwConv x d +b DwConv (1)
[0018] where x d represents the input of the depthwise convolution, w DwConv represents the weight of the standard convolution operation, b DwConv Represents the bias term of the standard convolution;
[0019] The batch normalization layer operation formula (2) is:
[0020]
[0021] where x b represents the input of the batch normalization layer, σ, μ, γ and β represent the variance, mean, weight and bias of the batch normalization layer respectively;
[0022] The output of the deep convolution is used as the input of the batch normalization layer. The specific operation formula (3) is:
[0023]
[0024] exist When , the DwConv_bn operation is simplified to formula (4):
[0025] DwConv_bn(x)=w DwConv_bn x+b DwConv_bn (4)
[0026] Where DwConv_bn represents the new deep convolution generated by combining the deep convolution and batch normalization layers, w DwConv_bn represents the weight of DwConv_bn, b DwConv_bn Indicates the bias of DwConv_bn.
[0027] Preferably, in the process of merging multiple branches into a single branch, the three branches of different scales are merged into a single branch of 3x3DwConv, where the identity mapping operation is regarded as a depth convolution with a convolution kernel size of 1x1, and a padding operation is used to fill it with zeros around it to form a DwConv with a convolution kernel size of 3x3. padding , transform the identity map and 1x1DwConv into 3x3 DwConv padding Finally, put the two 3x3DwConv padding The weights and bias terms of are merged into the weights and bias terms of 3x3 DwConv.
[0028] Preferably, in the reasoning stage of the RepDwConv, a structural reparameterization technique is used to improve the reasoning speed of the model while ensuring the model detection accuracy, so as to reduce the number of parameters and the amount of calculation.
[0029] Preferably, in step S1, the introduction of the SGVA module specifically includes an SVGA sparse graph construction process and an SVGA feature information aggregation update process.
[0030] Preferably, in the process of constructing the SVGA sparse graph, the input feature map is segmented, each image pixel is regarded as a vertex, and aggregation operations are performed in parallel on the width and height dimensions of the feature map. In the wide dimension, all pixel vertices in each column are aggregated with vertices whose distance measurement in the positive direction of their rows is nk (n=1, 2,..., Width / / k); in the high dimension, all vertices in each row are aggregated with vertices whose distance measurement in the positive direction of their columns is mk (m=1, 2,..., Height / / k);
[0031] Where k is the sparsity rate of the aggregation operation, Height represents the height of the feature map, and Width represents the width of the image. Due to the high similarity between neighboring pixels in the image, it is difficult to capture effective long-distance feature information when performing aggregation and update operations on pixels and neighboring pixels. When each vertex and its neighboring vertices perform feature information aggregation, the distance measurement operation is introduced to effectively improve the efficiency of parameters, prevent feature information redundancy, and reduce the amount of calculation when constructing a sparse graph. All vertices perform the aggregation and update operation, and after multiple rounds of iterations, a sparse graph is constructed.
[0032] Preferably, in the SVGA feature information aggregation and update process, the sparse graph attention mechanism uses MRGConv to perform aggregation and update operations, wherein the maximum aggregator aggregates the feature information of the current vertex and the neighboring vertices, and the update operation uses a fully connected layer to fuse the feature information of the current vertex and the neighboring vertices. The specific method is shown in formula (5), formula (6), formula (7) and formula (8):
[0033]
[0034] act(·)=GeLU(·) (6)
[0035] φ(·)=act(mlp(·)) (7)
[0036]
[0037] In formula (5) to formula (8), v i represents a vertex, θ represents the vertex feature information aggregation function, φ represents the vertex feature information update function, Represents vertex vi Aggregate and update the feature information before. Represents vertex v i The sparse neighbor vertex feature information of Represents vertex v i The sparse neighbor vertex set of i Represents vertex v i The sparse neighbor vertices of θ represents the weight of the aggregation function, w φ represents the weight of the update function, GeLU represents the activation function, and mlp represents the fully connected operation.
[0038] Preferably, the specific operation of the SVGA module is as shown in formula (9) and formula (10):
[0039] FFN(input)=mlp(act(mlp(input))))+input (9)
[0040] SVGA=FFN(mlp(MRGConv(mlp(innput)))+input) (10)
[0041] in Represents the input feature map information, mlp represents the multi-layer perceptron and batch normalization operation, and combines the residual idea to prevent network performance degradation in deep layers, and act represents the GeLU activation function.
[0042] Preferably, in step S1, the Rep-ViG includes a Stem module, a RepIRD block, an SVGAblock, a Downsample module and an SPPF module, the Rep-ViG network contains 9 layers, and the RepIRD block module is used to gradually extract visual feature information of apples at different scales in a complex environment from shallow to deep, and the SVGAblock and SPPF modules are used to extract semantic information in the deep layer. The SVGAblock is composed of two SVGA sparse graph attention mechanisms connected in series, and the SPPF module is used to capture multi-scale feature information of the feature map, so as to realize the fusion of global feature information and local feature information.
[0043] Preferably, in step S2, when the RepConvsBlock re-parameterization module is proposed, the RepConvs module is improved, and the improved RepConvs module uses the SiLU activation function to replace the ReLU activation function to process the output; wherein the calculation method of the SiLU activation function is shown in formula (11):
[0044] SiLU(x)=x / (1+exp(-x)) (11)
[0045] The calculation method of the ReLU activation function is shown in formula (12):
[0046] ReLU(x)=max(0,x) (12)
[0047] Preferably, in step S2, the Rep-FPN-PAN feature fusion network includes Rep-FPN and Rep-PAN; wherein the Rep-FPN is a top-down network that fuses deep multi-scale semantic information with shallow multi-scale visual information; the Rep-PAN is a bottom-up network that fuses the feature information output by Rep-FPN and the deep semantic feature information again, uses the CBS module to downsample and converts the feature maps to be merged into the same size, then merges the feature maps, and finally uses the RepConvsBlock module to perform feature fusion.
[0048] Preferably, in step S4, when the channel pruning algorithm based on the LAMP score is used, only the L2 norm is used to calculate the square sum of all weights of each input channel and the sum operation, without introducing additional calculation amount and parameters, and the channel layer sparsity is automatically selected for channel pruning. The specific calculation process of the LAMP score is: for all input channels of a certain layer of the model, the square sum of the weight of each input channel is calculated, the square sum of the weight of each channel is sorted, and an index mapping is established in the order of weight, that is, as long as the index u is less than the index v, the square sum of the channel weight corresponding to the index u (C W (u)) 2 is less than or equal to the sum of squares of the channel weights corresponding to v (C W (v)) 2 , the definition of LAMP score is shown in formula (13):
[0049]
[0050] Among them, (C W (u)) 2 represents the sum of squares of target channel weights, ∑ u≤v (C W (v)) 2 represents the sum of the weight squares of all remaining channels except the target channel that have not been clipped and whose index is greater than the target channel index; LAMP Score (u; C W ) indirectly reflects the importance of the target channel relative to the uncut channel, that is, the larger the sum of squares of the channel weights, the more important the channel is, as shown in formula (14):
[0051]
[0052] Channel pruning based on LAMP score is divided into global pruning and local pruning. Global pruning allocates adaptive sparsity to different layers in the model according to the LAMP score of the global channel of the model. Local pruning calculates the LAMP score of the local channel of each layer and prunes the number of channels of each layer with the same pruning ratio.
[0053] Compared with the prior art, one or more of the above technical solutions have the following beneficial effects:
[0054] 1. In the apple recognition algorithm under the complex environment of the orchard, a new inverted residual multi-scale structure re-parameterized feature extraction module (RepIRD Block) was designed, and a CNN-GCN architecture feature extraction network Rep-ViG was proposed by introducing the sparse graph attention mechanism (SVGA) to enhance the ability to extract apple feature information;
[0055] 2. In the apple recognition algorithm under the complex environment of the orchard, the RepConvsBlock re-parameterization module is proposed and the Rep-FPN-PAN feature fusion network is constructed to solve the problem of insufficient fusion of apple feature information;
[0056] 3. In the apple recognition algorithm in the complex environment of the orchard, a data enhancement algorithm (apple_aug) that simulates the real environment is designed to improve the generalization of the apple detection model in complex environments;
[0057] 4. In the apple recognition algorithm under the complex environment of the orchard, the channel pruning algorithm based on the LAMP score is used to compress the Rep-ViG-Apple model to reduce the number of parameters and calculations of the model. The improved Rep-ViG-Apple model has a mAP@0.5 of 93.3% and a size of 12.4MB, which effectively achieves a balance between accuracy and model size;
[0058] In summary, since accurate identification of apples in complex environments is of great significance to their automated picking operations, in natural environments such as cloudy, snowy, foggy, rainy days and low-light conditions, in order to solve the problems of reduced accuracy of apple target detection caused by branch occlusion, overlap between apples and different scales of near and far scenes, the present invention proposes a Rep-ViG-Apple algorithm. In the backbone network, the inverted residual multi-scale structure re-parameterized feature extraction module (RepIRD Block) is designed to enhance the feature extraction capability of occluded and overlapping apple targets; the sparse graph attention mechanism (SVGA) is introduced to capture global feature information, enhance the attention to apples, and suppress the interference of complex environmental features; the feature extraction network Rep-ViG of the CNN-GCN architecture is constructed, combining the advantages of CNN in local multi-scale feature extraction with the expertise of GCN global modeling, and further improving the extraction effect of apple feature information. In the neck network, the RepConvsBlock re-parameterized module is designed, and the Rep-FPN-PAN feature fusion network is constructed to improve the recognition capability of apple targets with different scales of near and far scenes.
[0059] In addition, an offline data augmentation algorithm (apple_aug) that simulates the real environment is added to improve the generalization ability of the model. Finally, a channel pruning algorithm based on the LAMP score is adopted to effectively balance the computational complexity and accuracy of the model. Experimental results show that the precision, recall and average precision of the improved Rep-ViG-Apple can reach 92.5%, 85.0% and 93.3%, respectively, which are 1.5%, 1.5% and 2.0% higher than YOLOv8n, and the model size of Rep-ViG-Apple is compressed by 22%. Based on this, the Rep-ViG-Apple model in a complex orchard environment has outstanding performance in detection precision, recall and model size, and can be regarded as one of the efficient models for automated apple picking. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.
[0061] In addition, the terms "installed", "set", "provided with", "connected", "connected", and "socketed" should be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or an integral structure; it can be a mechanical connection, or an electrical connection; it can be a direct connection, or an indirect connection through an intermediate medium, or it can be an internal connection between two devices, elements, or components. For those of ordinary skill in the art, the specific meanings of the above terms in this application can be understood according to specific circumstances.
[0062] Figure 1is the Rep-ViG-Apple network structure diagram of the present invention;
[0063] Figure 2 It is a schematic diagram of the RepDwConv training phase of the present invention;
[0064] Figure 3 It is a schematic diagram of the process of merging multiple branches into a single branch of the present invention;
[0065] Figure 4 It is a schematic diagram of the RepDwConv reasoning stage of the present invention;
[0066] Figure 5 It is a schematic diagram of the structure of the RepIRD Block of the present invention;
[0067] Figure 6 It is a schematic diagram of constructing an SVGA sparse graph of the present invention;
[0068] Figure 7 is a schematic diagram of an SVGA module of the present invention;
[0069] Figure 8 is a schematic diagram of the Rep-ViG network structure of the present invention;
[0070] Fig. 9 It is a schematic diagram of the SPPF module of the present invention;
[0071] Fig.10 It is a comparison diagram of the SVGA and SPPF output characteristic diagrams of the present invention;
[0072] Fig.11 It is a schematic diagram of the training and reasoning phases of RepConvs of the present invention;
[0073] Fig.12 It is a schematic diagram of the Rep-FPN-PAN feature fusion network of the present invention;
[0074] Fig.13 It is a comparison diagram of output feature maps of different feature fusion modules of the present invention;
[0075] Fig.14 It is a collection location and data sample diagram of the present invention;
[0076] Fig.15 is a schematic diagram of data enhancement of the present invention;
[0077] Fig.16 is a schematic diagram of am_aug data enhancement of the present invention;
[0078] Fig.17 is the heat map of different attention mechanisms of the present invention;
[0079] Fig.18 is a comparison diagram of different feature extraction networks of the present invention;
[0080] Fig.19 is a comparison diagram of different detection models of the present invention;
[0081] Fig. 20 This is a comparison diagram of the cloudy environment detection effect of the present invention;
[0082] Fig.21 This is a comparison diagram of the low-light environment detection effect of the present invention;
[0083] Fig. 22 This is a comparison diagram of the rainy day environment detection effect of the present invention;
[0084] Fig.23 It is a comparison diagram of the foggy environment detection effect of the present invention. DETAILED DESCRIPTION
[0085] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0086] See also Figure 1-Figure 23 YOLOv8 is divided into five models: n, s, m, l, and x according to the number of parameters and the amount of calculation. Due to its high accuracy, it is widely used in target detection related tasks. In the detection of apples in orchards under complex environments, the smallest YOLOv8n detection model is prone to missed detection and false detection, resulting in low accuracy. The larger YOLOv8m model has higher accuracy, but there are problems with large number of parameters and large amount of calculation, resulting in excessively high computational costs and difficult to apply in practice. In response to the above problems, in order to achieve a balance between the number of parameters and the amount of calculation of the model and the accuracy of the model, the lightweight YOLOv8n is used as the baseline model, and its network structure is innovatively studied and improved. A model Rep-ViG-Apple for orchard apple detection under complex environments is proposed. The improvement strategy mainly includes the following aspects:
[0087] (1) To address the problem of insufficient feature information of apples in complex environments, the RepIRD Block module is proposed and the SGVA module is introduced to design a new Rep-ViG feature extraction network. The RepIRD Block module extracts multi-scale feature information during the training phase to enhance the feature extraction capability of occluded and overlapping targets. At the same time, it merges multiple branches into a single branch structure during the inference phase to perform lossless compression on the model. SVGA can capture global feature information, enhance the focus on apples, and solve the problem that apple features and complex environment features are easily confused. Rep-ViG can effectively extract multi-scale local feature information and global feature information, improving the performance of the apple detection model in complex environments.
[0088] (2) To address the problem of insufficient fusion of apple feature information, a RepConvsBlock re-parameterization module was proposed, and a Rep-FPN-PAN feature fusion network was constructed. Multi-scale apple feature information was fused during the training phase to improve the recognition capability of apples of different sizes; during the inference phase, it was merged into a single-branch structure to reduce the amount of model calculation and improve the detection speed of the model. Rep-FPN-PAN can effectively solve the problem of large differences in apple size caused by long and short views.
[0089] (3) To address the problem of weak generalization of the model, an offline data augmentation algorithm (apple_aug) that simulates real environments is proposed to expand the apple detection dataset. Different real weather environments such as rainy days, foggy days, cloudy days, and low-light environments are simulated. It is combined with the mosaic online data augmentation algorithm and applied to the training set. A dual-hybrid offline and online training data augmentation strategy is designed to improve the generalization ability of the Rep-ViG-Apple model.
[0090] (4) To address the problem of large computational complexity and large number of parameters in the improved Rep-ViG-Apple model, a channel pruning algorithm based on the LAMP score is adopted to prune redundant feature maps of the model. This method can minimize the size of the model while ensuring the accuracy of the model, thus achieving a balance between the computational complexity and accuracy of the model.
[0091] 1.1 Rep-ViG-Apple network structure:
[0092] The Rep-ViG-Apple network structure is as follows Figure 1As shown in the figure, the feature extraction network is Rep-ViG, the feature fusion network is Rep-FPN-PAN, the prediction head adopts the decoupled head idea (Decoupled-Head) of YOLOX, which includes the classification head and the regression head. The loss function of the regression head adopts CIoU and Distribution Focal Loss (DFL). The sample matching uses the TaskAlignedAssigner positive and negative sample allocation strategy and the Anchor-Free strategy. The classification head adopts the binary cross entropy loss function (BCE);
[0093] 1.2 Rep-ViG feature extraction network:
[0094] In the scenario of the orchard apple detection task, the weather environment is relatively complex, the orchard background has a great interference on apple detection, and the occlusion of branches and leaves, overlapping fruits and other problems will make it difficult to identify apple targets. The feature information extracted by YOLOv8n has a single scale, which is prone to insufficient feature information extraction in complex environments and multi-scale target detection. For this reason, an inverted residual heavy parameter multi-scale feature extraction module is proposed to enhance the feature extraction capability of occluded and overlapping targets; a sparse graph attention mechanism is used to enhance the attention to apples and suppress the interference of complex environmental features, thereby constructing a feature extraction network for apple detection in complex environments;
[0095] 1.2.1 Inverted Residual Multi-Scale Structure Reparameterization Feature Extraction Module
[0096] The inverted residual structure (IRD) is a lightweight single-branch structure that uses deep convolution to learn more expressive feature information between high-dimensional feature maps. It is still widely used, but the single-branch structure will lead to insufficient feature information extraction. The multi-scale structural reparameterization idea is introduced to improve deep convolution, and a multi-scale reparameterization module (RepDwConv) is designed. The residual idea is introduced, and a lightweight inverted residual multi-scale structural reparameterization feature extraction module (RepIRD Block) is proposed to effectively solve the problem of insufficient apple feature information extraction. RepIRDBlock can extract feature information of different scales, so that the model can extract richer visual information such as color and contour in the shallow network, and can extract complex semantic information of the concept layer in the deep network. RepIRD Block combines the efficient modeling local feature capability of the CNN architecture and the multi-scale feature extraction capability to extract richer feature information. The residual idea can effectively prevent the problem of network performance degradation as the network depth increases. At the same time, the structural reparameterization idea is used to perform reasoning in a simpler and more efficient structure in the reasoning stage.
[0097] (1) RepDwConv training stage
[0098] The RepDwConv module uses three different parallel branches of deep convolution with kernel sizes of 3x3 and 1x1 and residual connection to capture information during the model training stage. At the same time, the three branches use batch normalization (bn) respectively, and then sum the outputs of the three branches element by element. Finally, the GELU activation function is used to fuse multi-scale feature information in different spatial receptive fields. The training stage of RepDwConv is as follows: Figure 2 shown.
[0099] (2) DwConv and bn merging process
[0100] In the model inference stage, the structural reparameterization method is used. First, the deep convolution and batch normalization layers are merged. The deep convolution DwConv operation is shown in formula (1):
[0101] DwConv(x d )=w DwConv x d +b DwConv (1)
[0102] where x d represents the input of the depthwise convolution, w DwConv represents the weight of the standard convolution operation, b DwConv Represents the bias term of the standard convolution. The batch normalization operation is shown in formula (2):
[0103]
[0104] where x b represents the input of the BN layer, σ, μ, γ and β represent the variance, mean, weight and bias of the BN layer respectively.
[0105] The output of DwConv is used as the input of bn. The specific operation is shown in formula (3):
[0106]
[0107] Assumptions The DwConv_bn operation can be simplified as formula (4):
[0108] DwConv_bn(x)=w DwConv_bn x+b DwConv_bn (4)
[0109] Where DwConv_bn means that the new deep convolution is generated after the deep convolution and bn layer are merged, w DwConv_bn represents the weight of DwConv_bn, b DwConv_bnIndicates the bias of DwConv_bn.
[0110] (3) The process of merging multiple branches into a single branch
[0111] The three branches of different scales are merged into a single branch of 3x3DwConv, where the identity mapping operation can be regarded as a depth convolution with a convolution kernel size of 1x1. The padding operation can be used to fill it with zeros around it to form a DwConvpadding with a convolution kernel size of 3x3. The identity mapping and 1x1DwConv are transformed into 3x3 DwConvpadding in turn. Finally, the weights and bias items of the two 3x3 DwConvpadding are merged into the weights and bias items of 3x3 DwConv. The process of merging the three branches is as follows: Figure 3 shown.
[0112] (4) Reasoning stage of RepDwConv
[0113] After RepDwConv uses the structural reparameterization technology in the reasoning stage, it ensures the model detection accuracy while improving the model reasoning speed, realizing the reduction of parameters and calculation amount. Figure 4 As shown;
[0114] Combining the RepDwConv module with the inverted residual idea, an inverted residual multi-scale re-parameter feature extraction module (RepIRD Block) is proposed. The RepIRD Block module uses 1x1 standard convolution to increase the number of channels of the feature map, uses the bn layer to normalize the feature map information, and then uses the GeLU function, whose output is close to the Gaussian distribution when it is close to zero, which can improve the generalization of the RepIRD Block module model. Decouple the spatial dimension and the channel dimension to reduce the computational complexity of the module. Use RepDwConv to extract multi-scale feature information in the spatial dimension. However, RepDwConv can only capture multi-scale feature information in the spatial dimension and ignores the feature information in the channel dimension. The 1x1 standard convolution extracts feature information in the channel dimension, which makes up for the shortcomings of RepDwConv. The feature map output by RepDwConv is used to exchange cross-channel information in the channel dimension to extract feature information, thereby improving the nonlinear expression ability of the model. At the same time, the dimension of the feature map can be reduced, so that the number of channels of the output feature map of RepIRDBlock matches the number of channels of the input feature map. Combined with the residual connection operation, the gradient disappearance is prevented. The RepIRD Block module uses the multi-branch structure of RepDwConv in the training phase to capture rich apple feature information. In the inference phase, it is re-parameterized to merge into a single-branch structure, reducing the computational complexity and parameter amount of the model. While ensuring accuracy, it improves the inference speed of the apple detection model and achieves lossless model compression on the apple detection task. The structure of RepIRD Block is as follows: Figure 5 shown.
[0115] 1.2.2SVGA Sparse Graph Attention Mechanism
[0116] The sparse graph attention mechanism captures global features, increases the focus on apples, reduces the interference caused by complex environments, and effectively improves the ability to recognize apple targets under adverse environmental conditions such as rainy, foggy, snowy days, and low light at night.
[0117] (1) SVGA sparse graph construction process
[0118] When constructing a sparse graph structure, the SVGA module introduces a concept similar to the dilation rate in the dilated convolution, splits the input feature map, regards each image pixel as a vertex, and performs aggregation operations in parallel on the width and height dimensions of the feature map. In the wide dimension, all pixel vertices in each column aggregate feature information with vertices whose distance measurement in the positive direction (Down) of their rows is nk (n=1,2,···, Width / / k); in the high dimension, all vertices in each row aggregate with vertices whose distance measurement in the positive direction (Right) of their columns is mk (m=1,2,···, Height / / k), as shown in the following example. Figure 6 As shown;
[0119] Where k is the sparsity rate of the aggregation operation, Height represents the height of the feature map, Width represents the width of the image, Down represents the downward direction, and Right represents the right direction. Due to the high similarity between neighboring pixels in the image, it is difficult to capture effective long-distance feature information when performing aggregation update operations on pixels and neighboring pixels. When each vertex aggregates feature information with its neighboring vertices, the distance measurement operation is introduced to effectively improve the efficiency of parameters, prevent redundancy of feature information, and reduce the amount of calculation when constructing a sparse graph. All vertices perform the aggregation update operation, and after multiple rounds of iterations, a sparse graph is constructed.
[0120] (2) SVGA feature information aggregation update process
[0121] Maximum neighbor graph convolution (MRGConv) is an efficient and lightweight graph convolution method. The sparse graph attention mechanism uses MRGConv for aggregation update operations. The maximum aggregator aggregates the feature information of the current vertex and the neighboring vertices, and the update operation uses a fully connected layer to fuse the feature information of the current vertex and the neighboring vertices. The specific method is shown in formula (5)-formula (8):
[0122]
[0123] act(·)=GeLU(·) (6)
[0124] φ(·)=act(mlp(·)) (7)
[0125]
[0126] In formula (5) to formula (8), v i represents a vertex, θ represents the vertex feature information aggregation function, φ represents the vertex feature information update function, Represents vertex v i Aggregate and update the feature information before. Represents vertex v i The sparse neighbor vertex feature information of Represents vertex v i The sparse neighbor vertex set of i Represents vertex v i The sparse neighbor vertices of θ represents the weight of the aggregation function, w φ represents the weight of the update function, GeLU represents the activation function, and mlp represents the fully connected operation.
[0127] The specific process of sparse graph attention mechanism (SVGA) is as follows Figure 7As shown, each pixel of the apple feature map is regarded as a vertex, and an initial sparse graph structure is constructed. The distance metric k is set to 2, and the scrolling operation is performed in the width and height dimensions of the feature map. Starting from the pixel in the upper left corner, scroll right and down respectively. Because each pixel is connected in the same way, the pixels in the same column as the starting point will also perform the scrolling operation of aligning with its connection at the same time. In the width direction, scroll right by Width / / k times; in the height direction, scroll down by Height / / k times. After the scrolling operation is completed, the maximum neighbor graph convolution (MRGConv) is used to aggregate and update the feature information of the vertex and the neighboring vertices, so that each vertex captures the global feature information in the sparse graph structure. Finally, combined with the FFN module, the over-smoothing phenomenon caused by multiple series in the deep network of the graph convolution model is effectively alleviated, and the nonlinear expression ability of the model is improved. The specific operation of the SVGA module is shown in formula (9-10):
[0128] FFN(input)=mlp(act(mlp(input))))+input (9)
[0129] SVGA=FFN(mlp(MRGConv(mlp(innput)))+input) (10)
[0130] in Represents the input feature map information, mlp represents the multi-layer perceptron and batch normalization operation, and combines the residual idea to prevent network performance degradation in deep layers, and act represents the GeLU activation function.
[0131] 1.2.3 Rep-ViG feature extraction network construction
[0132] Combining the advantages of CNN in local multi-scale feature extraction with the advantages of GCN in global modeling, a feature extraction network (Rep-ViG) of CNN-GCN architecture is designed using RepIRD block module and SVGAblock module. Rep-ViG is mainly composed of Stem module, RepIRD block, SVGA block, Downsample module and SPPF module. The Rep-ViG feature extraction network is shown in Figure 8 As shown;
[0133] The Rep-ViG network consists of 9 layers in total. The RepIRD block module is used to gradually extract the visual feature information of apples at different scales in complex environments from shallow to deep. In the deep layer, the SVGAblock and SPPF modules are used to extract semantic information. The SVGAblock can build a feature sparse graph structure and capture global long-distance feature information. The SVGAblock is composed of two SVGA sparse graph attention mechanisms in series. The SPPF module is used to capture the multi-scale feature information of the feature graph and realize the fusion of global feature information and local feature information. The SPPF module structure is as follows Fig. 9 As shown;
[0134] The Rep-ViG network uses the feature map with the output size of (84, 80, 80) in the 4th layer, the feature map with the output size of (168, 40, 40) in the 6th layer, and the feature map with the output size of (256, 20, 20) in the 9th layer as the input of three different scales of the feature fusion network. The specific information of the Rep-ViG apple feature extraction network is shown in Table 1:
[0135] Table 1 Detailed structure information of Rep-ViG network
[0136]
[0137] In order to prove the effectiveness of the Rep-ViG apple feature extraction network, the deep semantic information feature maps of the Rep-ViG apple feature extraction network and the feature extraction network of YOLOv8n are visually compared. The SPPF modules of Rep-ViG and YOLOv8n and the SVGA module and C2f module of the previous layer are selected. Fig.10 As shown in the figure. The SVGA module of Rep-ViG (d) is better than the C2f module of YOLOv8n (b). The three apple regions in the feature map extracted by the SVGA module are more obvious. The C2f module fails to extract the feature information of the first apple. The SVGA module can better extract the global long-distance feature information. The C2f module has a relatively poor effect in extracting features due to the limited receptive field of the convolution operation. Compared with the output of the SPPF module, the information of semantic features extracted by YOLOv8n is poor (c), and the semantic feature information extracted by the Rep-ViG network is more obvious (e), and the focus on apples is stronger.
[0138] 1.3Rep-FPN-PAN Apple Feature Fusion Network:
[0139] In the task of detecting apples under complex backgrounds, due to the different distances, the sizes of apples are inconsistent in the same scene, making it difficult to identify small distant targets. The neck network of the YOLOv8n model uses the C2f feature extraction module for feature fusion. The C2f feature extraction module has a single scale, and the split operation is relatively complex. In order to improve the multi-scale expression ability of the feature fusion module, an improved RepConvs module is proposed, and a RepConvsBlock module is constructed. The RepConvsBlock is used to replace the C2f module, and a Rep-FPN-PAN multi-scale apple feature fusion network is designed to effectively solve the problem of difficult identification caused by the different sizes of distant and near apples. Multi-branch structure fusion features are used during training, and merged into single-branch structure fusion features during inference, which reduces the number of model parameters and calculations, improves the inference speed, and avoids the waste of computing power.
[0140] 1.3.1 RepConvs Module
[0141] The RepConv structure reparameterization module consists of two standard convolutions 3x3Conv, 1x1Conv, bn layer, ReLU activation function and residual connection. The use of standard convolution can simultaneously fuse spatial information and channel information, and more fully integrate the apple feature information extracted by the Rep-ViG network. The RepConv module is divided into three parallel branches during the training phase. After the input is operated by two standard convolution branches and one identity mapping branch, the bn operation is used to standardize the data, and then the Add operation is used to add the elements corresponding to the output positions of the three branches. Since the ReLU activation function will cause the gradient to disappear during the training process, the SiLU activation function is smooth, continuous and differentiable at the zero point, which reduces the problem of local gradient disappearance and has a small amount of calculation. The calculation method of the SiLU activation function is shown in formula (11):
[0142] SiLU(x)=x / (1+exp(-x)) (11)
[0143] The calculation method of the ReLU activation function is shown in formula (12):
[0144] ReLU(x)=max(0,x) (12)
[0145] In the module design, the SiLU activation function is used to replace the ReLU activation function to process the output, and the RepConvs reparameterization module is constructed. RepConvs uses the reparameterization technology in the inference phase to first merge the standard convolution and batch normalization layers, and then merge the three parallel branches into a single branch structure of 3x3Conv. The structure of the RepConvs module in the training phase (a) and the inference phase (b) is shown in the figure. Fig.11As shown;
[0146] In the neck network, two structures are constructed using RepConvs, namely the RepConvsBlock module and the RepConvsBlockPlus module. The RepConvsBlock module is composed of two RepConvs in series, and the RepConvsBlockPlus module is composed of three RepConvs in series.
[0147] 1.3.2Rep-FPN-PAN feature fusion network construction
[0148] The Rep-FPN-PAN feature fusion network is composed of Rep-FPN (Rep Feature pyramid networks) and Rep-PAN (Rep Path Aggregation Network). The specific structure is as follows Fig.12 As shown. Rep-FPN is a top-down network that fuses deep multi-scale semantic information with shallow multi-scale visual information. First, the upsampling algorithm is used to convert the feature maps of the deeper and shallower layers to the same size, and then the concat operation is used to merge the feature maps of the deeper and shallower layers. Finally, the feature extraction module is used to fuse the semantic features and visual features. Rep-PAN is a bottom-up network that fuses the feature information output by Rep-FPN and the deep semantic feature information again. The CBS (Conv_BN_SiLU) module is used for downsampling to convert the feature maps to be merged to the same size, and then the feature maps are merged. Finally, the RepConvsBlock module is used for feature fusion;
[0149] To prove the superiority of the proposed Rep-FPN-PAN feature fusion network, YOLOv8n-Backbone and Rep-ViG are used as feature extraction networks respectively. The RepConvsBlock feature fusion module in the improved Rep-FPN-PAN network is compared with the C2f feature fusion module in the FPN-PAN network of YOLOv8n. The feature maps of the three feature output layers of the feature fusion network are visualized. The specific visualization results are shown in the figure. Fig.13As shown. When the backbone network (Backbone) of YOLOv8n is used as the feature extraction network, (b), (c), and (d) are the three output feature maps of the FPN-PAN network, and (e), (f), and (g) are the three output feature maps of the Rep-FPN-PAN network. The comparative analysis shows that the RepConvsBlock module fuses multi-scale features, and the overall effect is better than the single-scale C2f module. The RepConvsBlock module can better fuse apple feature information. When Rep-ViG is used as the feature extraction network, RepConvsBlock and RepConvsBlock Plus are used to construct the Rep-FPN-PAN network. (k), (l), and (m) are the three feature maps output after the RepConvsBlock feature fusion, and (h), (i), and (j) are the three feature maps output after the RepConvsBlock feature fusion. It can be seen that the RepConvsBlockPlus module has a poor effect after feature fusion due to its high complexity and deep hierarchy.
[0150] 1.4 Model pruning:
[0151] The apple detection algorithm under complex background is a deep convolutional neural network model. The reasoning process of the model requires a lot of computing power and memory support. Without significantly reducing the accuracy of the apple detection model, the neural network pruning algorithm is used to prune the channels with less feature information in the model, which can effectively reduce the number of model parameters and the amount of calculation. In view of the large number of parameters and calculations of the Rep-Vig-Apple model, channel pruning based on the LAMP score is used to compress the model. Layer-Adaptive Magnitude-based Pruning (LAMP) is an adaptive sparse pruning method that performs fine-grained unstructured pruning on model weights, but the weight matrix after pruning is in an indexed sparse format, which is not conducive to parallel computing. Channel pruning is structured pruning at the channel level, and the original convolution structure of the pruned model is still retained. The structured pruning ideas based on LAMP score pruning and channel pruning are combined to prune the Rep-Vig-Apple model. The trained Rep-Vig-Apple model is pruned first, and then the pruned model is retrained and fine-tuned using a lower learning rate to recover the performance loss caused by model pruning.
[0152] The channel pruning method based on LAMP score only uses L2 norm to calculate the square sum of all weights of each input channel and the sum operation, without introducing additional calculation amount and parameters, and automatically selects channel layer sparsity for channel pruning. The specific calculation process of LAMP score is as follows: for all input channels of a certain layer of the model, the square sum of the weight of each input channel is calculated, the square sum of the weight of each channel is sorted, and the index mapping is established in the order of weight, that is, as long as the index u is less than the index v, the square sum of the channel weight corresponding to the index u C W (u) is less than or equal to the square sum of the channel weights corresponding to v C W (v), the definition of LAMP score is shown in formula (13):
[0153]
[0154] Among them, (C W (u)) 2 represents the sum of squares of target channel weights, ∑ u≤v (C W (v)) 2 It represents the sum of the weighted squares of all remaining channels that have not been pruned and whose index is greater than the target channel index. According to the formula, in the LAMP score of each layer, there is at least one connection with a score of 1, which means that at least one connection will survive in each layer, preventing the problem of layer collapse during pruning. Score (u; C W ) indirectly reflects the importance of the target channel relative to the uncut channel, that is, the larger the sum of squares of the channel weights, the more important the channel is, as shown in formula (14):
[0155]
[0156] Channel pruning based on LAMP scores is divided into global pruning and local pruning. Global pruning allocates adaptive sparsity to different layers in the model according to the LAMP scores of the global channels of the model, but it may cause over-pruning of specific layers, resulting in a serious decrease in model accuracy after pruning. Local pruning calculates the LAMP scores of the local channels of each layer and prunes the same number of channels in each layer.
[0157] Specifically, the experiments and analysis are as follows:
[0158] 2.1 Experimental environment and parameter settings:
[0159] The operating system version of this experiment is CentOS 7.9.2009, the processor is 12vCPU Intel(R)Xeon(R)Platinum 8255C CPU@2.50GHz, the graphics card is NVIDIA GeForce RTX 3090, the video memory size is 24G, the integrated development environment is Anaconda, the model is built using Pytorch and MMDetection deep learning frameworks, and the CUDA version 11.3 is used to accelerate the model training process. The image resolution is 640*640, the optimizer uses SGD, the initial learning rate is 1e-2, and the batch size of each network training is 64. The baseline model and the improved model are trained for 200 rounds according to the above parameter settings, and the mosaic data enhancement is turned off in the last 10 rounds.
[0160] 2.2 Construction of Apple Dataset in Complex Environments:
[0161] Since there is currently no publicly available dataset for apple detection in complex environments, apples of different scales, backgrounds, and brightness environments were photographed manually, and apple data was collected at different shooting angles and distances in different light environments (weak light and strong light). The shooting period was from 10:00 to 16:00. The shooting locations were the Yiganqi Town Apple Plantation and the Meilidi Yaremu Orchard in Aksu City, China. The image was collected using a smartphone (iPhone 14pro). The data collection location and environment are as follows: Fig.14 shown.
[0162] The collected image dataset is manually screened to retain clear and high-quality images, and the constructed dataset is divided into training set, test set, and validation set in a ratio of 8:1:1.
[0163] For the task of apple detection in complex environments, an offline data enhancement method (apple_aug) is proposed in the data construction stage to simulate different complex environments for data expansion. The apple_aug algorithm is a method of simulating complex environments for data enhancement. It randomly simulates several real weather conditions of different intensities, such as snowy days (d), sunny days (e), cloudy days (f), foggy days (g), rainy days (h), and low-light environments (c). The apple dataset after using the apple_aug enhancement algorithm is more in line with the real complex environment, which improves the robustness of the apple detection model. At the same time, the contrast enhancement (b) algorithm is introduced in the data enhancement to enhance the detail information of the apple target. The results of the apple_aug enhancement algorithm are shown in the figure. Fig.15 As shown;
[0164] The apple_aug image enhancement algorithm is used to expand the data of the divided apple dataset. The enhanced apple dataset contains a total of 4080 images. The X-AnyLabeling annotation tool is used to manually annotate the apple enhanced dataset in VOC format. The label file is in XML format. Code is written to convert the XML label file into YOLO's TXT format. The number of training sets, test sets, and validation sets of the apple detection dataset under complex background and the number of corresponding enhancement categories are shown in Table 2:
[0165] Table 2 Distribution of different types of data
[0166]
[0167] 2.3 Training set preprocessing:
[0168] During the model training phase, an offline and online dual hybrid data enhancement (am_aug) method was designed. That is, the mosaic data enhancement algorithm was used during the training phase to randomly splice the data processed by apple_aug offline enhancement to enhance the robustness and generalization ability of the model. A new training sample is created by splicing multiple apple images from different environments together, thereby increasing the diversity of training data. The specific steps are as follows: Fig.16 As shown in Figure 2, the training data of the comparative experiments and ablation experiments below are all enhanced using the offline and online dual hybrid data enhancement methods, and the verification data are enhanced using the offline enhancement method.
[0169] 2.4 Experimental evaluation indicators:
[0170] The experiment uses commonly used evaluation indicators to evaluate the performance of the complex background apple detection model, namely mAP (meanAverage Precision), AP (Average Precision), recall rate R (Recall), precision rate P (Precision), model calculation amount (GFLOPS), model parameter amount (params). The specific calculation formula (15)-formula (18) is shown as follows:
[0171]
[0172] Where n refers to the number of categories, AP refers to the area enclosed by the PR (precision-recall) curve of a certain category, P refers to the proportion of boxes correctly predicted by the model, which measures the degree of false detection of the model, R refers to the proportion of the number of boxes correctly predicted by the model to the number of true boxes, which measures the degree of missed detection of the model, TP refers to the number of samples predicted as positive when they are actually positive, FP refers to the number of samples predicted as positive when they are actually negative, and FN refers to the number of samples predicted as negative when they are actually positive;
[0173] 2.5 Comparative experiments between SVGA and different attention mechanisms:
[0174] In order to prove the superiority of the sparse graph attention mechanism (SVGA), SVGA, MLCA, CA, and EMA are compared. The specific experimental results are shown in Table 3. It can be seen that the mAP@0.5 and mAP@0.5:0.95 performance indicators of the SVGA attention mechanism are 91.9% and 78.1%, respectively, which are higher than other attention mechanisms.
[0175] Table 3 Comparative experiments of different attention mechanisms
[0176]
[0177] At the same time, a heat map is used for visualization to compare the detection strength of the apple target by different attention mechanisms. The specific visualization effects are as follows: Fig.17 As shown in the figure, it can be seen that the SVGA attention mechanism has the best effect and pays the highest attention to apples.
[0178] 2.6 Comparative experiments between Rep-ViG and different types of feature extraction networks:
[0179] The effectiveness of the proposed Rep-ViG feature extraction network is demonstrated by setting up comparative experiments. It is compared with CNN architectures of different types (residual connection, depthwise separable convolution, multi-scale feature extraction, large convolution kernel, partial convolution), mainly including ResNet18, GhostNet, MobileNetv3, ResNeXt, ResNeSt, LcNet, LSKNet and FasterNet, as well as the feature extraction network EfficientViT of Transformer architecture. The feature fusion network and prediction head in the experiment are consistent with those in YOLOv8n. The specific comparative experimental results of different feature extraction networks are shown in Table 4:
[0180] Table 4 Comparative test of different feature extraction networks
[0181]
[0182] In order to more intuitively show the superiority of the proposed Rep-ViG feature extraction network, the experimental comparison results of different feature extraction networks are visualized. The specific contents are as follows: Fig.18 As shown, the size of the circle represents the size of the model. Table 4 Experimental results and Fig.18The visualization proves that the Rep-ViG feature extraction network built with multi-scale structure reparameterization technology and sparse graph attention mechanism has better results with lower computational complexity and smaller model size. The model has the highest accuracy and can better extract the feature information of apples in complex environments.
[0183] 2.7 Ablation experiment of the improvement process:
[0184] In order to prove that the proposed improvement strategy has an improvement effect in the apple detection task in a complex environment, different ablation experiments are designed. YOLOv8n is used as the baseline model, and the Rep-ViG feature extraction network, two different Rep-FPN-PAN feature fusion networks constructed based on the RepConvsBlock module and the RepConvsBlockPlus module, and different combined improved baseline models are used. The specific ablation experimental results of different improvement strategies are shown in Table 5:
[0185] Table 5 Ablation experiment of the improved process
[0186]
[0187]
[0188] 2.8 Structural reparameterization comparison experiment:
[0189] In the structural reparameterization experiment, the parameters and computational complexity of the Rep-ViG feature extraction network, the Rep-FPN-PAN feature fusion network, and the Rep-ViG-Apple model in the training and inference stages were compared. The specific results are shown in Table 6.
[0190] It can be seen from Table 6 that the number of parameters and the amount of calculation in the reasoning stage of Rep-ViG, Rep-FPN-PAN and Rep-ViG-Apple are reduced to varying degrees compared with the training stage, and the average accuracy of the model has not decreased.
[0191] Table 6 Structural reparameterization comparison experiment
[0192]
[0193] 2.9 Comparative experiments of different detection models:
[0194] In order to verify the superiority of the proposed Rep-ViG-Apple in the apple detection task in complex environments, it is compared with the current mainstream single-stage and two-stage target detection algorithms. The single-stage target detection algorithms are divided into YOLO series and non-YOLO series. The YOLO series mainly includes YOLOv8 series (n, s, m), YOLOv6 series (n, s), YOLOv5 series (n, s, m), YOLOv3 series (tiny), n, s, m, tiny represent models of different sizes, as well as YOLOX and YOLOf models. The non-YOLO series mainly includes SSD, Retinanet, FCOS, and the two-stage algorithms mainly include FasterRCNN and CascadeRCNN. A comparative analysis is carried out based on different detection model performance indicators. The specific comparative experimental results are shown in Table 7:
[0195] Table 7 Comparative experiments of different detection models
[0196]
[0197]
[0198] From the quantitative analysis results in Table 7, it can be seen that the overall performance of the proposed Rep-ViG-Apple is better than other compared models. Rep-ViG-Apple has the highest P value and mAP@0.5, which are 94.2% and 92.7% respectively, while GFLOPS and size remain at a low level. The performance of the single-stage detection algorithm is better than that of the two-stage target detection algorithm. Among the single-stage YOLO series algorithms, the mAP@0.5:0.95 values of YOLOv8, YOLOv6, and YOLOv5 increase as the size of the model increases. Although the mAP@0.5:0.95 of the models corresponding to the s and m sizes are higher than the mAP@0.5:0.95 values of Rep-ViG-Apple, their GFLOPS and size are larger, and their mAP@0.5 values are both smaller than the mAP@0.5 value of Rep-ViG-Apple. Although the size of the n series model is smaller than that of Rep-ViG-Apple, its accuracy is relatively low. The detection effect of YOLOv3-Tiny, YOLOX, YOLOf, non-YOLO series and two-stage target detection algorithms on the apple dataset in complex environment is poor. Among them, the model size of YOLOf, non-YOLO series and two-stage target detection algorithm is much larger than the proposed Rep-ViG-Apple model.
[0199] 2.10 Comparative Experiments on Pruning the Rep-ViG-Apple Model
[0200] Since the model size of Rep-ViG-Apple is relatively large compared to other YOLO series models of size n, the channel pruning method based on LAMP score is used to compress the model and prune redundant feature maps. In the pruning experiment, two types of pruning, global pruning and non-global pruning, are set up, and the performance of pruning strategies with different compression rates is compared. The comparison results are shown in Table 8:
[0201] Table 8 Comparative experiments on model pruning with different compression rates
[0202]
[0203] It can be seen from Table 8 that when the compression rate (Speed_up) is set to 1.8, the GFLOPS and size of the model decrease a lot, but the accuracy decreases more seriously. When the compression rate is set to 1.3 and 1.5, the redundant feature maps are pruned during the pruning process, and the accuracy of the model is further improved. When the compression rate is set to 1.3, the pruning effect of non-global pruning is the best, and the mAP@0.5 reaches 93.3%, and the mAP@0.5:0.95 reaches 79.7%, which is comparable to the performance of the model of size s in the YOLO series in the table, but the GFLOPS and size of Rep-ViG-Apple after compression are smaller.
[0204] 2.11 Comparison of experimental results of different detection models:
[0205] In order to prove the effectiveness of the proposed Rep-ViG-Apple in apple target detection under natural conditions, different types of complex environments were selected, including overcast sky, low light, rainy sky, foggy sky, and several representative orchard complex environments. The comparison model used both single-stage detection algorithm and two-stage detection algorithm. The single-stage detection algorithm mainly includes YOLO series and non-YOLO series. The YOLO series mainly includes YOLOv8n, YOLOv6n, YOLOv5n, and YOLOv3-tiny, which are comparable in size to Rep-ViG-Apple. The non-YOLO series (based on the MMDetection framework) uses the representative RetinaNet and FCOS. The two-stage algorithm uses CascadeRCNN with better performance.
[0206] Fig. 20The figure shows the comparison of detection effects of different algorithms in a multi-cloud environment. Among the YOLO series detection algorithms, the proposed Rep-ViG-Apple algorithm has the highest detection accuracy for apples. YOLOv5n has false detections, and YOLOv3-tiny has missed detections. Among the non-YOLO series detection algorithms, FCOS has the lowest detection accuracy. RetinaNet and CascadeRCNN have high accuracy, but the models are relatively large.
[0207] Fig.21 The figure shows the comparison of detection effects of different algorithms in low-light environments. Compared with the YOLO series detection algorithms, the proposed Rep-ViG-Apple algorithm has the highest overall detection accuracy for apples. The YOLOv3-tiny model misses detection in the upper left corner. Compared with non-YOLO series algorithms, the RetinaNet model has overlapping detection frames, and the detection accuracy of FCOS is low.
[0208] Fig. 22 The figure shows the comparison of detection effects of different algorithms in rainy environment. The proposed Rep-ViG-Apple algorithm has the best overall detection effect, which shows that the sparse graph attention mechanism can make the feature extraction network pay more attention to the information of apples. Other detection models have different degrees of missed detection and wrong detection. The missed detection of RetinaNet, CascadeRCNN and FCOS detection algorithms is more serious, among which CascadeRCNN has wrong detection.
[0209] Fig.23 The figure shows the comparison of detection effects of different algorithms in foggy environment. The proposed Rep-ViG-Apple algorithm has the best detection effect for apples, which shows that the multi-scale structure re-parameterization idea can better extract and fuse feature maps and improve the network's perception ability of occluded apples. Other detection models have different degrees of missed detection and cannot detect apples that are severely occluded in foggy environment.
[0210] In summary, in this embodiment, a Rep-ViG-Apple apple detection algorithm is proposed to solve the problem of low apple recognition accuracy in complex environments in orchards. A feature extraction network Rep-ViG with a CNN-GCN architecture is designed to effectively solve the problem of difficulty in identification caused by occlusion of branches and leaves and overlapping of apples, enhance the focus on apples, and suppress the interference of complex environmental features; a Rep-FPN-PAN feature fusion network is constructed to improve the recognition ability of apple targets and effectively solve the problem of large differences in apple size caused by far and near scenes; an offline data enhancement algorithm (apple_aug) simulating a real environment is designed to enhance the anti-interference ability of the model; a channel pruning algorithm based on LAMP scores is used to prune the redundant channels of the model and reduce the number of parameters and calculations of the model. The proposed Rep-ViG-Apple algorithm can be applied to the field of apple detection in complex environments in orchards, and can effectively detect apples that are occluded and have different sizes in far and near scenes under different weather conditions. In the future, the deployment of the model will continue to be optimized so that the Rep-ViG-Apple model can be applied to apple picking operations.
[0211] The above are only preferred specific implementation modes of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can make equivalent replacements or changes according to the technical solutions and inventive concepts of the present invention within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.
Claims
1. An apple recognition algorithm in a complex orchard environment. Features: The Rep-ViG-Apple model is used, and the construction of the Rep-ViG-Apple model specifically includes the following steps: S1: To address the problem of insufficient feature information of apples in complex environments, the RepIRD Block module is proposed and the SGVA module is introduced to design a new Rep-ViG feature extraction network; S2: To address the problem of insufficient fusion of apple feature information, a RepConvsBlock re-parameterization module is proposed, and a Rep-FPN-PAN feature fusion network is constructed; S3: To address the problem of weak model generalization, an offline data enhancement algorithm that simulates the real environment is proposed to expand the apple detection dataset. It is combined with the mosaic online data enhancement algorithm and applied to the training set to design an offline and online dual hybrid training data enhancement strategy. S4: To address the problem of large amount of computation and parameters in the improved Rep-ViG-Apple model, a channel pruning algorithm based on LAMP score is used to prune redundant feature maps of the model, thereby compressing the size of the model to the greatest extent while ensuring the accuracy of the model, so as to achieve a balance between the computational complexity and accuracy of the model; Among them, in the step S1, the RepIRD Block module extracts multi-scale feature information in the training stage to enhance the feature extraction capability of occluded and overlapping targets, and merges multiple branches into a single branch structure in the inference stage to perform lossless compression on the model; the SVGA module is used to capture global feature information to enhance the focus on apples, and, In step S2, the Rep-FPN-PAN feature fusion network fuses multi-scale apple feature information in the training stage to improve the recognition ability of apple targets of different sizes; and merges it into a single branch structure in the reasoning stage to reduce the calculation amount of the model and improve the detection speed of the model.
2. The apple recognition algorithm in the complex environment of the orchard according to claim 1, Features: In step S3, the simulated real environment includes different real weather environments such as rainy days, foggy days, cloudy days and low-light environments.
3. The apple recognition algorithm in the complex environment of the orchard according to claim 1, Features: In the step S1, the proposal of the RepIRD Block module specifically includes the RepDwConv training stage, the merging of deep convolution and batch normalization layers, the merging of multiple branches into a single branch process, and the RepDwConv reasoning stage.
4. The apple recognition algorithm in the complex environment of the orchard according to claim 3, Features: The RepDwConv module uses three different parallel branches of deep convolution with kernel sizes of 3x3 and 1x1 and residual connection to capture information during the model training stage. At the same time, the three branches use batch normalization operations respectively, and then sum the outputs of the three branches element by element. Finally, the GELU activation function is used to fuse multi-scale feature information in different spatial receptive fields. and, In the process of combining the deep convolution and batch normalization layers, the operation formula (1) of the deep convolution is: DwConv(x d )=w DwConv x d +b DwConv (1) where x d represents the input of the depthwise convolution, w DwConv represents the weight of the standard convolution operation, b DwConv Represents the bias term of the standard convolution; The batch normalization layer operation formula (2) is: where x b represents the input of the batch normalization layer, σ, μ, γ and β represent the variance, mean, weight and bias of the batch normalization layer respectively; The output of the deep convolution is used as the input of the batch normalization layer. The specific operation formula (3) is: exist When , the DwConv_bn operation is simplified to formula (4): DwConv_bn(x)=w DwConv_bn x+b DwConv_bn (4) Among them, DwConv_bn represents the new deep convolution generated by combining the deep convolution and batch normalization layers, w DwConv_bn represents the weight of DwConv_bn, b DwConv_bn represents the bias of DwConv_bn; and, In the process of merging multiple branches into a single branch, the three branches of different scales are merged into a single branch of 3x3DwConv, where the identity mapping operation is regarded as a depth convolution with a convolution kernel size of 1x1, and a padding operation is used to fill it with zeros around it to form a DwConv with a convolution kernel size of 3x3. padding , transform the identity mapping and 1x1DwConv into 3x3DwConv in turn padding Finally, put the two 3x3DwConv padding The weights and bias terms of are merged into the weights and bias terms of 3x3 DwConv; and, In the reasoning stage of the RepDwConv, the structure reparameterization technology is used to improve the reasoning speed of the model while ensuring the model detection accuracy, so as to achieve the reduction of parameter quantity and calculation amount.
5. The apple recognition algorithm in the complex environment of the orchard according to claim 4, Features: In step S1, the introduction of the SGVA module specifically includes an SVGA sparse graph construction process and an SVGA feature information aggregation update process; wherein, In the process of constructing the SVGA sparse graph, the input feature map is segmented, each image pixel is regarded as a vertex, and aggregation operations are performed in parallel on the width and height dimensions of the feature map. In the wide dimension, all pixel vertices in each column are aggregated with vertices whose distance measurement in the positive direction of their rows is nk (n=1, 2,..., Width / / k); in the high dimension, all vertices in each row are aggregated with vertices whose distance measurement in the positive direction of their columns is mk (m=1, 2,..., Height / / k); Where k is the sparsity rate of the aggregation operation, Height represents the height of the feature map, and Width represents the width of the image; and, In the SVGA feature information aggregation and update process, the sparse graph attention mechanism uses MRGConv to perform aggregation and update operations, in which the maximum aggregator aggregates the feature information of the current vertex and the neighboring vertices, and the update operation uses a fully connected layer to fuse the feature information of the current vertex and the neighboring vertices. The specific method is shown in formula (5), formula (6), formula (7) and formula (8): act(·)=GeLU(·) (6) φ(·)=act(mlp(·)) (7) In formula (5) to formula (8), v i represents a vertex, θ represents the vertex feature information aggregation function, φ represents the vertex feature information update function, Represents vertex v i Aggregate and update the feature information before. Represents vertex v i The sparse neighbor vertex feature information of Represents vertex v i The sparse neighbor vertex set of i Represents vertex v i The sparse neighbor vertices of θ represents the weight of the aggregation function, w φ represents the weight of the update function, GeLU represents the activation function, and mlp represents the fully connected operation.
6. The apple recognition algorithm in the complex environment of the orchard according to claim 5, Features: The specific operation of the SVGA module is shown in formula (9) and formula (10): FFN(input)=mlp(act(mlp(input))))+input (9) SVGA=FFN(mlp(MRGConv(mlp(innput)))+input) (10) in Represents the input feature map information, mlp represents the multi-layer perceptron and batch normalization operation, and combines the residual idea to prevent network performance degradation in deep layers, and act represents the GeLU activation function.
7. The apple recognition algorithm in the complex environment of the orchard according to claim 6, Features: In step S1, the Rep-ViG includes a Stem module, a RepIRD block, an SVGAblock, a Downsample module and an SPPF module. The Rep-ViG network contains 9 layers. The RepIRD block module is used to gradually extract visual feature information of apples at different scales in a complex environment from shallow to deep. The SVGAblock and SPPF modules are used to extract semantic information in the deep layer. The SVGAblock is composed of two SVGA sparse graph attention mechanisms connected in series. The SPPF module is used to capture multi-scale feature information of the feature map and realize the fusion of global feature information and local feature information.
8. The apple recognition algorithm in the complex environment of the orchard according to claim 1, Features: In step S2, when the RepConvsBlock re-parameterization module is proposed, the RepConvs module is improved, and the improved RepConvs module uses the SiLU activation function to replace the ReLU activation function to process the output; wherein the calculation method of the SiLU activation function is shown in formula (11): SiLU(x)=x / (1+exp(-x)) (11) The calculation method of the ReLU activation function is shown in formula (12): ReLU(x)=max(0,x) (12) 9. The apple recognition algorithm in the complex environment of the orchard according to claim 8, Features: In step S2, the Rep-FPN-PAN feature fusion network includes Rep-FPN and Rep-PAN; wherein the Rep-FPN is a top-down network that fuses deep multi-scale semantic information with shallow multi-scale visual information; the Rep-PAN is a bottom-up network that fuses the feature information output by Rep-FPN and the deep semantic feature information again, uses the CBS module to downsample and converts the feature maps to be merged into the same size, then merges the feature maps, and finally uses the RepConvsBlock module to perform feature fusion.
10. The apple recognition algorithm in a complex orchard environment according to claim 1, Features: In step S4, when the channel pruning algorithm based on the LAMP score is used, only the L2 norm is used to calculate the square sum of all weights of each input channel and the sum operation, without introducing additional calculation amount and parameters, and the channel layer sparsity is automatically selected for channel pruning. The specific calculation process of the LAMP score is as follows: for all input channels of a certain layer of the model, the square sum of the weight of each input channel is calculated, the square sum of the weight of each channel is sorted, and an index mapping is established in the order of the weight, that is, as long as the index u is less than the index v, the square sum of the channel weight corresponding to the index u (C W (u)) 2 is less than or equal to the sum of squares of the channel weights corresponding to v (C W (v)) 2 , the definition of LAMP score is shown in formula (13): Among them, (C W (u)) 2 represents the sum of squares of target channel weights, ∑ u≤v (C W (v)) 2 represents the sum of the weight squares of all remaining channels except the target channel that have not been clipped and whose index is greater than the target channel index; LAMP Score (u; C W ) indirectly reflects the importance of the target channel relative to the uncut channel, that is, the larger the sum of squares of the channel weights, the more important the channel is, as shown in formula (14): Channel pruning based on LAMP score is divided into global pruning and local pruning. Global pruning allocates adaptive sparsity to different layers in the model according to the LAMP score of the global channel of the model. Local pruning calculates the LAMP score of the local channel of each layer and prunes the number of channels of each layer with the same pruning ratio.
Citation Information
Cited By
Water surface target detection tracking method based on YOLOV5s and DeepSORT network
CN119540621A
