Greenhouse strawberry fruit target detection algorithm based on improved DETR

By improving the DETR algorithm, using pyramid convolution and Swiglu activation function, and improving the attention mechanism, the problem of low target detection accuracy and low training efficiency in the greenhouse environment is solved, and efficient strawberry fruit target detection is achieved.

CN118570443APending Publication Date: 2024-08-30JIANGSU UNIV
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410646892.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-23
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

In complex greenhouse environments, existing target detection algorithms have problems such as missed detection of small targets, low detection accuracy, and slow model training, making it difficult to meet the real-time and accuracy requirements.

Method used

Improve the DETR algorithm, use pyramid convolution PyConv as the backbone network, replace the ReLU activation function with Swiglu, change it to a group query attention mechanism, and optimize the self-attention mechanism of the encoder and decoder to improve detection accuracy and training efficiency.

Benefits of technology

While reducing the amount of parameters and calculations, the computational accuracy of greenhouse strawberry fruit target detection is significantly improved, and the problems of missed detection of small targets, low detection accuracy, and slow model training are solved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118570443A
    Figure CN118570443A
Patent Text Reader

Abstract

The invention provides a greenhouse strawberry fruit target detection algorithm based on an improved DETR, and the algorithm comprises the following steps: constructing a greenhouse strawberry fruit target detection network model, changing a backbone network residual network ResNet of the DETR into a pyramid convolution PyConv, replacing a ReLU activation function in a Transform module in the DETR with an activation function Swiglu, and carrying out the detection of the greenhouse strawberry fruit target through the activation function Swiglu. A self-attention mechanism in an encoder is changed into grouping query attention, and a first self-attention mechanism in a decoder is changed into grouping query attention. Establishing a training set and a verification set for training and verification of the greenhouse strawberry fruit target detection model; and training a greenhouse strawberry fruit detection model by using a gradient descent method, detecting the training set and / or the verification set, and outputting a greenhouse strawberry fruit detection result. According to the invention, the greenhouse strawberry fruit target detection effect with high detection precision is obtained under the condition that the parameter quantity and the calculated quantity are reduced slightly.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of target detection, and in particular to a greenhouse strawberry fruit target detection algorithm based on improved DETR. Background Art

[0002] With the rise of deep learning, the country has vigorously developed smart agriculture, and deep learning target detection technology has been increasingly used in the agricultural field. Strawberry is a precious fruit, and different irrigation techniques have an impact on the growth and ripening of strawberries. In order to accurately identify ripe strawberry fruits and achieve precise irrigation, deep learning target detection algorithms have advantages.

[0003] At present, vision-based target detection algorithms are developing rapidly. Great progress has been made in simple agricultural product target detection. However, in complex greenhouse environments, there are problems of mutual occlusion between dense targets and a large number of small targets, which leads to serious missed detection of targets and difficulty in meeting detection accuracy requirements. When target instances overlap with each other, the extracted features may not be sufficient for accurate detection and classification, resulting in failure to successfully identify the target. Many algorithms show poor robustness in practical applications and are difficult to meet real-time requirements. Therefore, improving the accuracy and efficiency of target detection has become an important issue that urgently needs to be solved. Summary of the invention

[0004] In view of the deficiencies in the prior art, the present invention provides a greenhouse strawberry fruit target detection algorithm based on improved DETR, which has the characteristics of high computational accuracy and can solve the following problems caused by using DETR in the single-stage target detection algorithm in the prior art: (1) missed detection of small targets; (2) low detection accuracy; and (3) slow model training.

[0005] The present invention achieves the above technical objectives through the following technical means.

[0006] A greenhouse strawberry fruit target detection method based on improved DETR includes the following steps:

[0007] A greenhouse strawberry fruit target detection network model is constructed. The greenhouse strawberry fruit target detection network model adopts DETR as the basic framework, and the backbone network residual network ResNet of DETR is changed to pyramid convolution PyConv; the activation function Swiglu is used to replace the ReLU activation function in the Transformer module in DETR; the self-attention mechanism MHA in the encoder is changed to group query attention GQA; the first self-attention mechanism MHA in the decoder is changed to group query attention GQA;

[0008] Establish training sets and validation sets for training and testing the greenhouse strawberry fruit target detection model;

[0009] Training a greenhouse strawberry fruit detection model, and testing the training set and / or the validation set;

[0010] Use the trained greenhouse strawberry fruit target detection model to detect the target.

[0011] Furthermore, the backbone network residual network ResNet of DETR is changed to pyramid convolution PyConv. Specifically, the backbone network residual network ResNet of DETR includes a 7×7 convolution, a 3×3 maximum pooling, four-layer residual network layer ResNet50Bottleneck, a mean pooling and a fully connected layer; in the backbone network residual network ResNet, the maximum pooling is deleted, and the four-layer residual network layer is changed to a four-layer pyramid convolution module PyConvResNet50Block, and 1×1 convolution is added before and after each layer of pyramid convolution module PyConvResNet50Block.

[0012] Furthermore, the backbone network pyramid convolution PyConv of DETR inputs the image to be detected, and the image to be detected is sequentially input into the 7×7 convolution layer, the four-layer pyramid convolution layer PyConvLayer, the mean pooling layer and the fully connected layer, turning the input image into a feature vector of size 7*7*2048. After passing through a 1*1 convolution layer, it becomes a feature vector of 7*7*256; the 7*7*256 feature vector is concatenated with the position encoding vector and input into the Transformer module.

[0013] Further, the four pyramid convolution layers PyConvLayer are respectively a first layer PyConvLayer1, a second layer PyConvLayer2, a third layer PyConvLayer3 and a fourth layer PyConvLayer4;

[0014] The first layer PyConvLayer1 includes three pyramid convolution modules PyConvBlock1 and the first downsampling layer downsample1; the first pyramid convolution module PyConvBlock1_0, the first downsampling layer downsample1, the first second pyramid convolution module PyConvBlock1_1 and the first third pyramid convolution module PyConvBlock1_2 are connected in series. The three pyramid convolution modules PyConvBlock1 in the first layer PyConvLayer1 have the same structure. Each pyramid convolution module PyConvBlock1 includes a 9×9 convolution layer, a 7×7 convolution layer, a 5×5 convolution layer, a 3×3 convolution layer and two 1*1 convolution layers; a 1*1 convolution layer, a 3×3 convolution layer, a 5×5 convolution layer, a 7×7 convolution layer, a 9×9 convolution layer and another 1*1 convolution layer in the pyramid convolution module PyConvBlock1 are connected in series;

[0015] The second layer PyConvLayer2 includes four pyramid convolution modules PyConvBlock2 and the second downsampling layer downsample2; the first pyramid convolution module PyConvBlock2_0, the second downsampling layer downsample2, the second pyramid convolution module PyConvBlock2_1, the third pyramid convolution module PyConvBlock2_2 and the fourth pyramid convolution module PyConvBlock2_3 are connected in series. The four pyramid convolution modules PyConvBlock2 in the second layer PyConvLayer2 have the same structure. Each pyramid convolution module PyConvBlock2 includes a 7×7 convolution layer, a 5×5 convolution layer, a 3×3 convolution layer and two 1*1 convolution layers; a 1*1 convolution layer, a 3×3 convolution layer, a 5×5 convolution layer, a 7×7 convolution layer and another 1*1 convolution layer in the pyramid convolution module PyConvBlock2 are connected in series;

[0016] The third layer PyConvLayer3 includes six pyramid convolution modules PyConvBlock3 and the third downsampling layer downsample3; the first pyramid convolution module PyConvBlock3_0 of the third layer, the third downsampling layer downsample3, the second pyramid convolution module PyConvBlock3_1 of the third layer, the third pyramid convolution module PyConvBlock3_2 of the third layer, the fourth pyramid convolution module PyConvBlock2_3 of the third layer, and the fifth pyramid convolution module PyConvBlock2_4 of the third layer. The convolution module PyConvBlock2_4 and the sixth pyramid convolution module PyConvBlock2_5 of the third layer are connected in series. The six pyramid convolution modules PyConvBlock3 in the third layer PyConvLayer3 have the same structure. Each pyramid convolution module PyConvBlock3 includes a 5×5 convolution layer, a 3×3 convolution layer and two 1*1 convolution layers; a 1*1 convolution layer, a 3×3 convolution layer, a 5×5 convolution layer and another 1*1 convolution layer in the pyramid convolution module PyConvBlock3 are connected in series.

[0017] The fourth layer PyConvLayer4 includes three pyramid convolution modules PyConvBlock4 and the fourth downsampling layer downsample4; the first pyramid convolution module PyConvBlock4_0, the fourth downsampling layer downsample4, the second pyramid convolution module PyConvBlock4_1 and the third pyramid convolution module PyConvBlock4_2 of the fourth layer are connected in series, and the three pyramid convolution modules PyConvBlock4 in the fourth layer PyConvLayer4 have the same structure, and each pyramid convolution module PyConvBlock4 includes 3×3 convolution and two 1*1 convolutions; a 1*1 convolution layer, a 3×3 convolution layer and another 1*1 convolution layer are connected in series in the pyramid convolution module PyConvBlock3;

[0018] The first downsampling layer downsample1, the second downsampling layer downsample2, the third downsampling layer downsample3 and the fourth downsampling layer downsample4 are all composed of a 3*3 maximum pooling layer and a 1*1 convolutional layer in series.

[0019] Furthermore, the 7*7*256 feature vector is concatenated with the position encoding vector and input into the Transformer module. Specifically, the position encoding is calculated for each channel of the input image to be detected in two dimensions and concatenated together, where the position encoding of each dimension uses the same sin-cos encoding as the encoder layer Transformer; the image is position-encoded to obtain a position encoding vector pos of size 256; the 7*7*256 feature vector is concatenated with the position encoding vector pos and deformed to obtain a pos_embed vector of size 49*2*256, which is input into the Transformer module. The 2 in the above pos_embed vector size represents the batch-size of the number of images input at a time.

[0020] Furthermore, the Transformer module in the DETR includes a Transformer encoder layer and a Transformer decoder layer; the Transformer encoder layer includes six serially connected encoders Transformer Encoders; the Transformer decoder layer includes six serially connected decoders Transformer Decoders; the pos_embed vector of size 49*2*256 is processed by six serially connected encoders Transformer Encoders to obtain an encoding vector of size 49*2*256; the encoding vector of 49*2*256 is input into the decoder layer, and a vector of 6*2*100*256 is output. The 2 in the above vector size represents the batch-size of the number of input images at a time.

[0021] Furthermore, each encoder Transformer Encoder includes an inter-group query self-attention layer, two encoding standardization layers and a forward propagation layer; the pos_embed vector passes through the inter-group query self-attention layer to obtain an Attention vector of size 49*2*256, denoted as src; the Attention vector src is input into an encoding standardization layer for standardization to obtain src2; the standardized src2 is input into the forward propagation layer; the forward propagation layer uses the Swiglu activation function to activate src2, and after activation, the output is a vector src3 of size 49*2*256, and the vector src3 and the vector src2 are respectively input into another standardization layer for standardization to obtain a vector src4 of size 49*2*256; the encoder Transformer Encoder inputs the vector src4 into the next serial encoder Transformer Encoder. The 2 in the above vector size represents the batch-size of the number of input images at a time.

[0022] Furthermore, each decoder Transformer Decoder includes a multi-head self-attention mechanism layer, an inter-group query self-attention layer, three decoding standardization layers and a forward propagation layer; a 100*2*256 vector query_pos is randomly generated in the first decoder Transformer Encoder, and the vector query_pos is input into the inter-group query self-attention layer for processing to obtain a vector tgt2 of size 100*2*256; the vector tgt2 is input into the first decoding standardization layer for standardization to obtain a vector tgt3 of size 100*2*256; the 100*2*256 vector tgt3 and the 49*2*256 encoding vector output by the encoder layer are jointly input into the multi-head self-attention mechanism layer, and the multi-head self-attention mechanism layer outputs a vector tgt4 of 100*2*256 and a vector tgt5 of 100*2*256. The vector tgt4 of 56 and the vector tgt3 of 100*2*256 are input to the second decoding normalization layer for normalization to obtain a vector tgt5 of size 100*2*256; the vector tgt5 of 100*2*256 is input to the forward propagation layer, and the output of the forward propagation layer is a vector tgt6 of 100*2*256; the vector tgt6 and the vector tgt5 are input to the third decoding normalization layer for normalization to obtain a vector tgt7 of 100*2*256; the vector tgt7 of 100*2*256 replaces the vector query_pos and inputs the inter-group query self-attention layer in the second decoder Transformer Encoder, and is repeated through six decoders Transformer Encoder to output a vector of 6*2*100*256. The 2 in the above vector size represents the batch-size of the number of input images at a time.

[0023] Furthermore, the activation function in the forward propagation layer is changed to Swiglu. Swiglu uses two activation functions to activate the input vectors respectively, and after activation, the two new vectors are transformed and output by dot product multiplication. Specifically, the input value x of the forward propagation layer is input into the first linear layer and the second linear layer with different weight matrices respectively. The output of the first linear layer uses the ReLU activation function to activate the input value x, and the output of the second linear layer uses the Sigmoid activation function to activate the input value x. After activation, the two new vectors are transformed and output by dot product multiplication as follows:

[0024]

[0025] Where x is the input value; W is the weight matrix of the second linear layer, V is the weight matrix of the first linear layer, the first and second linear layers convert the vector src2 of size 49*2*256 into a vector of 49*2*2048; b is the bias of the Sigmoid activation function, and c is the bias of the ReLU activation function; Swiglu (x, W, V, b, c) after dot product multiplication is converted into a vector of 49*2*256 through the third linear layer as the output of the forward propagation layer. The 2 in the above vector size represents the batch-size of the number of input images at a time.

[0026] Furthermore, the gradient descent method was used to train the greenhouse strawberry fruit detection model.

[0027] The beneficial effects of the present invention are:

[0028] The greenhouse strawberry fruit target detection network model constructed by the present invention is based on the DETR network structure, the backbone network residual network ResNet of DETR is changed into the pyramid convolution PyConv, the activation function Swiglu is adopted to replace the ReLU activation function in the Transformer module in DETR, the self-attention mechanism MHA in the encoder is changed into the group query attention GQA, and the first self-attention mechanism MHA in the decoder is changed into GQA, so that the greenhouse strawberry fruit target detection network model can achieve the greenhouse strawberry fruit target detection effect with high calculation accuracy while slightly reducing the parameter amount and the calculation amount, and well solves the problems of missed detection of small targets, low detection accuracy and slow model training. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] 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 description of the prior art will be briefly introduced below. The drawings described below are some embodiments of the present invention. For ordinary technicians in this field, it is obvious that other drawings can be obtained based on these drawings without paying any creative work.

[0030] Figure 1 It is a flow chart of the greenhouse strawberry fruit target detection method based on improved DETR according to the present invention;

[0031] Figure 2 It is a structural diagram of the greenhouse strawberry fruit target detection network model described in the present invention;

[0032] Figure 3 This is a structural diagram of the backbone network described in the present invention;

[0033] Figure 4 It is a structural diagram of the pyramid volume module of the present invention;

[0034] Figure 5 This is a structural diagram of the Transformer module with Swiglu added as described in the present invention. DETAILED DESCRIPTION

[0035] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present invention, and should not be construed as limiting the present invention.

[0036] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "upper", "lower", "axial", "radial", "vertical", "horizontal", "inner", "outer" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first" and "second" are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined.

[0037] In the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be an indirect connection through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0038] like Figure 1 As shown, the greenhouse strawberry fruit target detection method based on improved DETR of the present invention comprises the following steps:

[0039] S01: Construct a greenhouse strawberry fruit target detection network model, which uses DETR as the basic framework, and changes the backbone network residual network ResNet of DETR to pyramid convolution PyConv; uses the activation function Swiglu to replace the ReLU activation function in the Transformer module in DETR; changes the self-attention mechanism MHA in the encoder to group query attention GQA; changes the first self-attention mechanism MHA in the decoder to group query attention GQA;

[0040] Among them: the backbone network residual network ResNet of DETR is changed to pyramid convolution PyConv, specifically: the backbone network residual network ResNet of DETR includes a 7×7 convolution, a 3×3 maximum pooling, four residual network layers ResNet50Bottleneck, a mean pooling and a fully connected layer; among them, the four residual network layers are composed of 1×1, 3×3, and 1×1 convolutions. In the backbone network residual network ResNet, the maximum pooling is deleted, and the four residual network layers are changed to four-layer pyramid convolution modules PyConvResNet50Block, and 1×1 convolutions are added before and after each layer of pyramid convolution modules PyConvResNet50Block.

[0041] like Figure 3 and Figure 4 As shown in the figure, the backbone network pyramid convolution PyConv of DETR specifically includes a 7×7 convolution layer, four pyramid convolution layers PyConvLayer, a mean pooling layer and a fully connected layer. The four pyramid convolution layers PyConvLayer are the first layer PyConvLayer1, the second layer PyConvLayer2, the third layer PyConvLayer3 and the fourth layer PyConvLayer4.

[0042] The first layer PyConvLayer1 includes three pyramid convolution modules PyConvBlock1 and the first downsampling layer downsample1. The first layer first pyramid convolution module PyConvBlock1_0, the first downsampling layer downsample1, the first layer second pyramid convolution module PyConvBlock1_1 and the first layer third pyramid convolution module PyConvBlock1_2 are connected in series. The three pyramid convolution modules PyConvBlock1 in the first layer PyConvLayer1 have the same structure. Each pyramid convolution module PyConvBlock1 includes a 9×9 convolution layer, a 7×7 convolution layer, a 5×5 convolution layer, a 3×3 convolution layer and two 1*1 convolution layers, such as Figure 3As shown, in the pyramid convolution module PyConvBlock1, a 1*1 convolution layer, a 3×3 convolution layer, a 5×5 convolution layer, a 7×7 convolution layer, a 9×9 convolution layer and another 1*1 convolution layer are connected in series.

[0043] The second layer PyConvLayer2 includes four pyramid convolution modules PyConvBlock2 and the second downsampling layer downsample2; the first pyramid convolution module PyConvBlock2_0, the second downsampling layer downsample2, the second pyramid convolution module PyConvBlock2_1, the third pyramid convolution module PyConvBlock2_2 and the fourth pyramid convolution module PyConvBlock2_3 are connected in series. The four pyramid convolution modules PyConvBlock2 in the second layer PyConvLayer2 have the same structure. Each pyramid convolution module PyConvBlock2 includes a 7×7 convolution layer, a 5×5 convolution layer, a 3×3 convolution layer and two 1*1 convolution layers, such as Figure 3 As shown, in the pyramid convolution module PyConvBlock2, a 1*1 convolution layer, a 3×3 convolution layer, a 5×5 convolution layer, a 7×7 convolution layer and another 1*1 convolution layer are connected in series.

[0044] The third layer PyConvLayer3 includes six pyramid convolution modules PyConvBlock3 and a third downsampling layer downsample3; the first pyramid convolution module PyConvBlock3_0 of the third layer, the third downsampling layer downsample3, the second pyramid convolution module PyConvBlock3_1 of the third layer, the third pyramid convolution module PyConvBlock3_2 of the third layer, the fourth pyramid convolution module PyConvBlock2_3 of the third layer, the fifth pyramid convolution module PyConvBlock2_4 of the third layer and the sixth pyramid convolution module PyConvBlock2_5 of the third layer are connected in series. The six pyramid convolution modules PyConvBlock3 in the third layer PyConvLayer3 have the same structure. Each pyramid convolution module PyConvBlock3 includes a 5×5 convolution layer, a 3×3 convolution layer and two 1*1 convolution layers, such as Figure 3 As shown, in the pyramid convolution module PyConvBlock3, a 1*1 convolution layer, a 3×3 convolution layer, a 5×5 convolution layer and another 1*1 convolution layer are connected in series.

[0045] The fourth layer PyConvLayer4 includes three pyramid convolution modules PyConvBlock4 and the fourth downsampling layer downsample4; the first pyramid convolution module PyConvBlock4_0 of the fourth layer, the fourth downsampling layer downsample4, the second pyramid convolution module PyConvBlock4_1 of the fourth layer and the third pyramid convolution module PyConvBlock4_2 of the fourth layer are connected in series. The three pyramid convolution modules PyConvBlock4 in the fourth layer PyConvLayer4 have the same structure. Each pyramid convolution module PyConvBlock4 includes 3×3 convolution and two 1*1 convolutions, such as Figure 3 As shown, in the pyramid convolution module PyConvBlock3, a 1*1 convolution layer, a 3×3 convolution layer, and another 1*1 convolution layer are connected in series.

[0046] The first downsampling layer downsample1, the second downsampling layer downsample2, the third downsampling layer downsample3 and the fourth downsampling layer downsample4 are all composed of a 3*3 maximum pooling layer and a 1*1 convolutional layer in series.

[0047] The backbone network of DETR, pyramid convolution PyConv, takes as input the image to be detected, which is sequentially input into the 7×7 convolution layer, the four-layer pyramid convolution layer PyConvLayer, the mean pooling layer, and the fully connected layer. The input image is converted into a feature vector of size 7*7*2048, and after a 1*1 convolution layer, it is converted into a feature vector of size 7*7*256; see Table 1 for details.

[0048] Table 1 Backbone network pyramid convolution PyConv input and output

[0049]

[0050]

[0051]

[0052] The greenhouse strawberry fruit target detection method based on improved DETR requires position encoding of the input image. For the two dimensions of each channel of the input image to be detected, namely the length and width, the position encodings of the two dimensions are calculated respectively and spliced ​​together. The position encoding of each dimension uses the same sin-cos encoding as the encoder layer Transformer. After position encoding, the image obtains a position encoding vector pos of size 256. The above-mentioned 7*7*256 feature vector is spliced ​​with the position encoding vector and deformed to obtain a pos_embed vector with a size of 49*2*256. The pos_embed vector is input into the encoder layer. The 2 in the pos_embed vector size represents the batch-size of the number of input images at a time.

[0053] like Figure 5 As shown in the figure, the Transformer encoder layer includes six serially connected encoders; each encoder Transformer Encoder includes an inter-group query self-attention layer, two encoding standardization layers and a forward propagation layer; the pos_embed vector passes through the inter-group query self-attention layer to obtain an Attention vector of size 49*2*256, recorded as src; the Attention vector src is input into an encoding standardization layer for standardization to obtain src2; the standardized src2 is respectively input into the forward propagation layer and another encoding standardization layer. The 2 in the above vector size represents the batch-size of the number of images input at a time.

[0054] The activation function in the forward propagation layer of the present invention is changed to Swiglu, and Swiglu uses two activation functions to activate the input vectors respectively, and after activation, the two new vectors are converted and output by dot product multiplication. Specifically, the standardized src2 is input into the first linear layer and the second linear layer with different weight matrices respectively, the output of the first linear layer uses the ReLU activation function to activate the standardized vector src2, and the output of the second linear layer uses the Sigmoid activation function to activate the standardized vector src2. After activation, the two new vectors are converted and output by dot product multiplication. The calculation formula is:

[0055]

[0056] Where x is the normalized vector src2; W is the weight matrix of the second linear layer, V is the weight matrix of the first linear layer, and the first and second linear layers convert the vector src2 of size 49*2*256 into a vector of 49*2*2048. b is the bias of the Sigmoid activation function, and c is the bias of the ReLU activation function. After the dot product multiplication, Swiglu(x,W,V,b,c) is transformed into a vector of 49*2*256 through the third linear layer, denoted as src3. The 2 in the above vector size represents the batch-size of the number of input images at a time.

[0057] The forward propagation layer uses the Swiglu activation function to activate src2. After activation, the output is vector src3 with a size of 49*2*256. Vector src3 and vector src2 are input into another normalization layer for normalization to obtain vector src4 with a size of 49*2*256. Vector src3 and src2 are superimposed in another normalization layer. The encoder TransformerEncoder inputs vector src4 into the next serial encoder Transformer Encoder. The 2 in the above vector size represents the batch-size of the number of input images at a time.

[0058] The pos_embed vector of size 49*2*256 is processed by six serial encoders Transformer Encoder to obtain an encoding vector of size 49*2*256; the encoding vector of 49*2*256 is input into the decoder layer, as shown in Figure 5 As shown, the Transformer decoder layer has six serially connected decoders Transformer Decoder; each decoder Transformer Decoder includes a multi-head self-attention mechanism layer, an inter-group query self-attention layer, three decoding normalization layers and a forward propagation layer;

[0059] In the first decoder Transformer Encoder, a 100*2*256 vector query_pos is randomly generated. The vector query_pos is input into the inter-group query self-attention layer for processing to obtain a vector tgt2 of size 100*2*256; the vector tgt2 is input into the first decoding and normalized by the normalization layer to obtain a vector tgt3 of size 100*2*256; the 100*2*256 vector tgt3 and the 49*2*256 encoding vector output by the encoder layer are jointly input into the multi-head self-attention mechanism layer, and the multi-head self-attention mechanism layer outputs a 100*2*256 vector tgt4. The 100*2*256 vector tgt4 and the 100*2*256 vector tgt3 are jointly input into the second decoding and normalized by the normalization layer to obtain a vector tgt5 of size 100*2*256; the 100*2*256 vector tgt5 is input into the forward propagation layer, and the forward propagation layer and the encoder Transformer The forward propagation layer of the encoder is exactly the same, and the output of the forward propagation layer is a 100*2*256 vector tgt6. Vector tgt6 and vector tgt5 are input into the third decoder normalization layer for normalization to obtain a 100*2*256 vector tgt7; 100*2*256 vector tgt7 replaces the vector query_pos and inputs the inter-group query self-attention layer in the second decoder Transformer Encoder, repeats through six decoders Transformer Encoder, and finally outputs a 6*2 (batch-size)*100*256 vector. The 2 in the above vector size represents the batch-size of the number of images input at a time.

[0060] The inter-group query self-attention layer and multi-head self-attention mechanism layer in the encoder Transformer Encoder and decoder Transformer Encoder are both existing attention layers, and the specific internal logic is not described here. The greenhouse strawberry fruit target detection network model is established.

[0061] S02: Establish training set and validation set for training and detection validation of greenhouse strawberry fruit target detection model;

[0062] The training set and verification set are derived from a total of 3328 images of the original data set of greenhouse strawberry fruit images collected from the laboratory; the images in the data set are annotated, the obtained data images are annotated and converted into coco training files, the obtained training sample set is data enhanced and the converted target images are divided into a training sample set and a verification sample set; the verification sample set is directly used as the verification set.

[0063] S03: Use the gradient descent method to train the greenhouse strawberry fruit detection model, detect the training set and / or the verification set, and output the greenhouse strawberry fruit detection result.

[0064] The network model is trained using the stochastic gradient descent method. The entire training process is divided into three stages, each with 150 cycles. In the first stage, the Pyconv module is trained once for a total of 150 cycles. In the second stage, group query attention GQA is added on the basis of the first stage and training continues for 150 cycles. In the third stage, the activation function in Transformer is changed to Swiglu on the basis of the second stage and training continues for 150 cycles. In each stage, the initial learning rate lr is set to 0.0001, the number of iterations epochs is set to 150 times, the batch size batch_size is set to 4, and the lr_drop is set to 100.

[0065] The method for detecting the training set and / or the validation set is: six evaluation indicators, namely, accuracy (Precison), recall (Recall), intersection over union (IOU), average precision (AP), mean average precision (m AP) and detection speed (FPS), are used as evaluation criteria for traffic target detection experiments.

[0066] S04: Use the greenhouse strawberry fruit target detection network model to perform target detection.

[0067] It should be understood that although this specification is described according to various embodiments, not every embodiment contains only one independent technical solution. This narrative method of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation methods that can be understood by those skilled in the art.

[0068] The series of detailed descriptions listed above are only specific descriptions of feasible embodiments of the present invention. They are not intended to limit the scope of protection of the present invention. All equivalent embodiments or changes that do not deviate from the technical spirit of the present invention should be included in the scope of protection of the present invention.

Claims

1. A greenhouse strawberry fruit target detection method based on improved DETR, It is characterized in that The steps include: A greenhouse strawberry fruit target detection network model is constructed. The greenhouse strawberry fruit target detection network model adopts DETR as the basic framework, and the backbone network residual network ResNet of DETR is changed to pyramid convolution PyConv; the activation function Swiglu is used to replace the ReLU activation function in the Transformer module in DETR; the self-attention mechanism MHA in the encoder is changed to group query attention GQA; the first self-attention mechanism MHA in the decoder is changed to group query attention GQA; Establish training sets and validation sets for training and testing the greenhouse strawberry fruit target detection model; Training a greenhouse strawberry fruit detection model, and testing the training set and / or the validation set; Use the trained greenhouse strawberry fruit target detection model to detect the target.

2. The greenhouse strawberry fruit target detection method based on improved DETR according to claim 1, It is characterized in that The backbone network residual network ResNet of DETR is changed to pyramid convolution PyConv. Specifically, the backbone network residual network ResNet of DETR includes a 7×7 convolution, a 3×3 maximum pooling, four-layer residual network layer ResNet50Bottleneck, a mean pooling and a fully connected layer; in the backbone network residual network ResNet, the maximum pooling is deleted, and the four-layer residual network layer is changed to a four-layer pyramid convolution module PyConvResNet50Block, and 1×1 convolution is added before and after each layer of pyramid convolution module PyConvResNet50Block.

3. The greenhouse strawberry fruit target detection method based on improved DETR according to claim 2, It is characterized in that The backbone network pyramid convolution PyConv of DETR inputs the image to be detected. The image to be detected is sequentially input into the 7×7 convolution layer, the four-layer pyramid convolution layer PyConvLayer, the mean pooling layer and the fully connected layer, turning the input image into a feature vector of size 7*7*2048. After passing through a 1*1 convolution layer, it becomes a feature vector of 7*7*256. The 7*7*256 feature vector is concatenated with the position encoding vector and input into the Transformer module.

4. The greenhouse strawberry fruit target detection method based on improved DETR according to claim 3, It is characterized in that The four pyramid convolution layers PyConvLayer are respectively the first layer PyConvLayer1, the second layer PyConvLayer2, the third layer PyConvLayer3 and the fourth layer PyConvLayer4; The first layer PyConvLayer1 includes three pyramid convolution modules PyConvBlock1 and the first downsampling layer downsample1; the first pyramid convolution module PyConvBlock1_0, the first downsampling layer downsample1, the first second pyramid convolution module PyConvBlock1_1 and the first third pyramid convolution module PyConvBlock1_2 are connected in series. The three pyramid convolution modules PyConvBlock1 in the first layer PyConvLayer1 have the same structure. Each pyramid convolution module PyConvBlock1 includes a 9×9 convolution layer, a 7×7 convolution layer, a 5×5 convolution layer, a 3×3 convolution layer and two 1*1 convolution layers; a 1*1 convolution layer, a 3×3 convolution layer, a 5×5 convolution layer, a 7×7 convolution layer, a 9×9 convolution layer and another 1*1 convolution layer in the pyramid convolution module PyConvBlock1 are connected in series; The second layer PyConvLayer2 includes four pyramid convolution modules PyConvBlock2 and the second downsampling layer downsample2; the first pyramid convolution module PyConvBlock2_0, the second downsampling layer downsample2, the second pyramid convolution module PyConvBlock2_1, the third pyramid convolution module PyConvBlock2_2 and the fourth pyramid convolution module PyConvBlock2_3 are connected in series. The four pyramid convolution modules PyConvBlock2 in the second layer PyConvLayer2 have the same structure. Each pyramid convolution module PyConvBlock2 includes a 7×7 convolution layer, a 5×5 convolution layer, a 3×3 convolution layer and two 1*1 convolution layers; a 1*1 convolution layer, a 3×3 convolution layer, a 5×5 convolution layer, a 7×7 convolution layer and another 1*1 convolution layer in the pyramid convolution module PyConvBlock2 are connected in series; The third layer PyConvLayer3 includes six pyramid convolution modules PyConvBlock3 and the third downsampling layer downsample3; the first pyramid convolution module PyConvBlock3_0 of the third layer, the third downsampling layer downsample3, the second pyramid convolution module PyConvBlock3_1 of the third layer, the third pyramid convolution module PyConvBlock3_2 of the third layer, the fourth pyramid convolution module PyConvBlock2_3 of the third layer, and the fifth pyramid convolution module PyConvBlock2_4 of the third layer. The convolution module PyConvBlock2_4 and the sixth pyramid convolution module PyConvBlock2_5 of the third layer are connected in series. The six pyramid convolution modules PyConvBlock3 in the third layer PyConvLayer3 have the same structure. Each pyramid convolution module PyConvBlock3 includes a 5×5 convolution layer, a 3×3 convolution layer and two 1*1 convolution layers; a 1*1 convolution layer, a 3×3 convolution layer, a 5×5 convolution layer and another 1*1 convolution layer in the pyramid convolution module PyConvBlock3 are connected in series. The fourth layer PyConvLayer4 includes three pyramid convolution modules PyConvBlock4 and the fourth downsampling layer downsample4; the first pyramid convolution module PyConvBlock4_0, the fourth downsampling layer downsample4, the second pyramid convolution module PyConvBlock4_1 and the third pyramid convolution module PyConvBlock4_2 of the fourth layer are connected in series, and the three pyramid convolution modules PyConvBlock4 in the fourth layer PyConvLayer4 have the same structure, and each pyramid convolution module PyConvBlock4 includes 3×3 convolution and two 1*1 convolutions; a 1*1 convolution layer, a 3×3 convolution layer and another 1*1 convolution layer are connected in series in the pyramid convolution module PyConvBlock3; The first downsampling layer downsample1, the second downsampling layer downsample2, the third downsampling layer downsample3 and the fourth downsampling layer downsample4 are all composed of a 3*3 maximum pooling layer and a 1*1 convolutional layer in series.

5. The greenhouse strawberry fruit target detection method based on improved DETR according to claim 3, It is characterized in that The 7*7*256 feature vector is concatenated with the position encoding vector and input into the Transformer module. Specifically, the position encoding is calculated for the two dimensions of each channel of the input image to be detected and concatenated together, where the position encoding of each dimension uses the same sin-cos encoding as the encoder layer Transformer; the image is positionally encoded to obtain a position encoding vector pos of size 256; the 7*7*256 feature vector is concatenated with the position encoding vector pos and deformed to obtain a pos_embed vector of size 49*2*256. The pos_embed vector is input into the Transformer module.

6. The greenhouse strawberry fruit target detection method based on improved DETR according to claim 5, It is characterized in that The Transformer module in the DETR includes a Transformer encoder layer and a Transformer decoder layer; the Transformer encoder layer includes six serially connected encoders Transformer Encoders; the Transformer decoder layer includes six serially connected decoders Transformer Decoders; the pos_embed vector with a size of 49*2*256 is processed by six serially connected encoders Transformer Encoders to obtain an encoding vector with a size of 49*2*256; the 49*2*256 encoding vector is input into the decoder layer, and a 6*2*100*256 vector is output.

7. The greenhouse strawberry fruit target detection method based on improved DETR according to claim 6, It is characterized in that Each encoder Transformer Encoder includes an inter-group query self-attention layer, two encoding standardization layers and a forward propagation layer; the pos_embed vector passes through the inter-group query self-attention layer to obtain an Attention vector of size 49*2*256, denoted as src; the Attention vector src is input into an encoding standardization layer for standardization to obtain src2; the standardized src2 is input into the forward propagation layer; the forward propagation layer uses the Swiglu activation function to activate src2, and after activation, the output is a vector src3 of size 49*2*256, and the vector src3 and the vector src2 are respectively input into another standardization layer for standardization to obtain a vector src4 of size 49*2*256; the encoder Transformer Encoder inputs the vector src4 into the next serial encoder Transformer Encoder.

8. The greenhouse strawberry fruit target detection method based on improved DETR according to claim 6, It is characterized in that Each decoder Transformer Decoder includes a multi-head self-attention mechanism layer, an inter-group query self-attention layer, three decoding standardization layers and a forward propagation layer; a 100*2*256 vector query_pos is randomly generated in the first decoder Transformer Encoder, and the vector query_pos is input into the inter-group query self-attention layer for processing to obtain a vector tgt2 of size 100*2*256; the vector tgt2 is input into the first decoding standardization layer for standardization to obtain a vector tgt3 of size 100*2*256; the 100*2*256 vector tgt3 and the 49*2*256 encoding vector output by the encoder layer are jointly input into the multi-head self-attention mechanism layer, and the multi-head self-attention mechanism layer outputs a vector tgt4 of 100*2*256 and a vector tgt5 of 100*2*256. The vector tgt4 of size 56 and the vector tgt3 of size 100*2*256 are input into the second decoding normalization layer for normalization to obtain a vector tgt5 of size 100*2*256; the vector tgt5 of size 100*2*256 is input into the forward propagation layer, and the output of the forward propagation layer is a vector tgt6 of size 100*2*256; the vector tgt6 and the vector tgt5 are input into the third decoding normalization layer for normalization to obtain a vector tgt7 of size 100*2*256; the vector tgt7 of size 100*2*256 replaces the vector query_pos and is input into the inter-group query self-attention layer in the second decoder Transformer Encoder, and is repeated through six decoders Transformer Encoder to output a vector of size 6*2*100*256.

9. The greenhouse strawberry fruit target detection method based on improved DETR according to claim 7 or 8, It is characterized in that The activation function in the forward propagation layer is changed to Swiglu. Swiglu uses two activation functions to activate the input vectors respectively, and after activation, the two new vectors are transformed and output by dot product multiplication. Specifically, the input value x of the forward propagation layer is input into the first linear layer and the second linear layer with different weight matrices respectively. The output of the first linear layer uses the ReLU activation function to activate the input value x, and the output of the second linear layer uses the Sigmoid activation function to activate the input value x. After activation, the two new vectors are transformed and output by dot product multiplication as follows: Where x is the input value; W is the weight matrix of the second linear layer, V is the weight matrix of the first linear layer, the first and second linear layers convert the vector src2 of size 49*2*256 into a vector of 49*2*2048; b is the bias of the Sigmoid activation function, and c is the bias of the ReLU activation function; Swiglu(x,W,V,b,c) after dot product multiplication is converted into a vector of 49*2*256 through the third linear layer as the output of the forward propagation layer.

10. The greenhouse strawberry fruit target detection method based on improved DETR according to claim 1, It is characterized in that The greenhouse strawberry fruit detection model was trained using the gradient descent method.

Citation Information

Cited By

  • Fruit quality detection method, device, equipment and medium

    CN120599599A