# A Study on Tomato Disease and Pest Detection Method
## 4 Methods
### Up-Sampling Improvements  
In the feature fusion network, YOLOv5 uses nearest-neighbor interpolation for upsampling, which only considers the position of the pixel points and does not fully exploit the information in the feature map. This can reduce the quality of the upsampled feature map. To address this issue, this paper proposes to use a lightweight and general upsampling operator called Content-Aware ReAssembly of Features (CARAFE) to replace nearest-neighbor interpolation and obtain a higher-quality upsampled feature map. The CARAFE operator consists of two blocks: the feature reassembly module and the up-sampling kernel prediction module. The upsample kernel prediction module analyzes and encodes the input feature map to predict the upsample kernels corresponding to different positions of the feature points. The feature reorganization module then performs upsampling using the predicted upsample kernels. Compared with nearest-neighbor interpolation, the CARAFE operator makes better use of the semantic information in the feature map during the upsampling process, thereby improving the quality of the upsampled feature map. The structure of the CARAFE module is shown in Figure 7.  
The upsampling kernel prediction module consists of a content encoding sub-module, a kernel normalization sub-module, and a channel compression sub-module. First, the channel compression sub-module reduces the computational cost by using a \(1\times 1\) convolutional layer to compress the channel dimension of the input feature map. Then, the content encoding sub-module uses a convolutional layer with a size of \(k_{encoder}\times k_{encoder}\times\sigma^{2}\times k_{  
Figure 6: Lightweight MSA structure.  
to encode the deep semantic information contained in each feature point and its surrounding points in the input feature map, generating an upsample kernel with a shape of \(H\times W\times\sigma^{2}\times k_{up}^{2}\). The channel dimension of the upsample kernel is then expanded to the width and height dimensions, resulting in an expanded upsample kernel with a shape of \(\sigma H\times\sigma W\times k_{up}^{2}\), where \(k_{up}^{2}\) is the size of the upsample kernel for a single feature point, and \(\sigma\) is the upsampling rate. Finally, the kernel normalization sub-module uses the softmax function to normalize the predicted upsample kernel. Overall, the upsample kernel prediction module uses the semantic information in the input feature map to adaptively generate corresponding upsample kernels for different feature points.  
The role of the feature reassembly module is to map each feature point in the output feature map back to the input feature map and extract a region of size \(k\_up\times k\_up\) centered on that feature point. The feature reassembly module then performs a dot product operation between the extracted region and the upsample kernel predicted by the upsample kernel prediction module for that point, generating the upsampled feature for that point. Since the feature reassembly module pays more attention to the information contained in the relevant feature points in the local region during the reassembly process, the reassembled feature map usually contains richer semantic information and is more expressive than the original feature map.  
Compared with the original nearest-neighbor interpolation upsampling, the CARAFE upsampling operator can aggregate contextual semantic information within a larger receptive field and perform adaptive upsampling operations for different feature points using the predicted upsampling kernels. This operation effectively reduces the loss, ensures the integrity of the feature information, and improves the quality of the upsampled feature map.