# Target Detection for Coloring and Ripening Potted Dwarf Apple Fruits Based on Improved YOLOv7-RSEs
## 2 Materials and Methods
### Improvements to YOLOv7
#### 2.4.3 Lightweight Improvement  
RepBlock is obtained via structural re-parameterization; multi-branch networks often outperform single-path networks in classification tasks, yet this advantage can result in higher inference latency [24]. Our paper draws inspiration from RepVGG. We aim to balance accuracy and speed by adopting RepBlock, an efficient and tunable backbone network. RepBlock capitalizes on specific hardware acceleration features, and post-training, we significantly reduce inference latency by transforming the multi-branch topology into a single 3 \(\times\) 3 convolution layer (RepConv) with ReLU activation. Figure 9 illustrates the backbone network structure of RepBlock.  
Figure 9: RepBlock structure. (**a**) Training structure; (**b**) inference structure.  
In this paper, we performed an equivalent mapping on the original multi-branch architecture. Specifically, each branch had its convolutional kernels transformed into \(3\times 3\) convolutional kernels. For \(1\times 1\) convolutional layers, to address the shortcut branch problem without convolutional layers, we introduced four fixed numerical convolutional kernels, \(K_{1},K_{2},K_{3},K_{4}\), where \(K_{1},K_{4}\) are \(3\times 3\) convolution kernels with a central parameter of one and zero values around the center, and \(K_{2},K_{3}\) are \(3\times 3\) convolutional kernels with a center parameter of one and zero values around the center, while B and D are \(3\times 3\) convolutional kernels with all zero values [25]. It is worth noting that the introduction of convolutional kernels did not change the nature of the original convolutional operations. Figure 10 demonstrates the effectiveness of the equivalent mapping.  
After equivalence mapping, we merged the convolutional layers and BN layers of each branch, resulting in a biased convolutional layer as shown in Figure 7. Specifically, we merged each branch into a single convolutional layer. The convolutional parameters and biases of the merged layer are denoted as \(W_{i},i=1,2,3\) and \(B_{i},i=1,2,3\), respectively. The structure of RepBlock is illustrated in Figure 8, and the relationship between its input and output operations is represented by Equation (14).  
\[\begin{split} Y&=(X*W_{1}+b_{1})+(X*W_{2}+b_{2})+( x*W_{3}+b_{3})\\ &=I*(W_{1}+K_{2}+W_{3})+(b_{1}+b_{2}+b_{3})\end{split} \tag{14}\]  
Then, letting \(W^{*}=W_{1}+W_{2}+W_{3}\) and \(b^{*}=b_{1}+b_{2}+b_{3}\), substituting into Equation (14), we obtain Equation (15).  
\[\begin{split} Y&=(X*K_{1}+b_{1})+(X*K_{2}+b_{2})+( X*K_{3}+b_{3})\\ &=X*W^{*}+b^{*}\end{split} \tag{15}\]  
In this paper, we successfully utilized the convolutional kernel fusion technique described in Equation (15) to convert three sets of parameters \(\{W_{i},B_{i},i=1,2,3\}\) into a single set of parameters \(\{W^{*},B^{*}\}\), as shown in Figure 11. This method effectively reduced the number of convolutional kernels by two-thirds and significantly improved the inference efficiency of the network.  
Figure 10: RepBlock equivalence mapping. (**a**) The structure and parameters of RepBlock; (**b**) the structure and parameters of RepBlock after equivalence mapping.