# A Study on Tomato Disease and Pest Detection Method
## 4 Methods  
### Backbone Network Improvements  
Although YOLOv5's CSPDarknet53 backbone network performs well in object detection tasks, it has some drawbacks. For example, it has high computational and storage costs because CSPDarknet53 contains multiple convolutional and pooling layers that require large amounts of computational and storage resources for training and inference. Deploying CSPDarknet53 can be difficult on resource-constrained devices such as edge and mobile devices. The network structure of CSPDarknet53 is relatively fixed, making it difficult to customize and extend. As a result, CSPDarknet53 may not be able to meet the requirements of some specific application scenarios, such as those requiring specific receptive fields or specific feature extraction capabilities. In addition, although YOLOv5 provides several versions of models, including YOLOv5s, YOLOv5m, YOLOv5l, and YOLOv5x, these models may still have high computational and storage costs on resource-constrained devices. To address these issues, the Google Brain team proposed the Vision Transformer (ViT) model [33] in 2020. The ViT model is an image classification model based on the Transformer architecture. It divides the image into a fixed number of image patches and uses each patch as an input to the model. ViT uses the multi-head self-attention mechanism of the Transformer encoder to process image data, so the model does not require convolutional operations to process images and therefore has better scalability and generalization ability. In the ViT model, each image patch is converted to a vector and then input to a multi-layer Transformer encoder for processing. The encoder maps the input vector sequence to another vector sequence, where each vector contains all the information in the sequence. To make the ViT model adaptable to images of different sizes, a deformable attention mechanism is introduced to adapt to different spatial structures when processing image patches. The structure is shown in Figure 4.  
Figure 3: C3_2 structure diagram. The ViT model partially compensates for the shortcomings of traditional CNN backbone networks, such as the ability to process large images, computational and memory costs, generalization, and flexibility. Subsequently, the MIT-IBM Watson AI Lab improved the traditional ViT model to obtain the EfficientViT model. The EfficientViT model can maintain high accuracy while having lower computational and memory costs. It also enhances the multi-scale attention mechanism and has greater scalability, which can be adapted to different tasks and devices. For example, by increasing or decreasing the number of attention heads, accuracy can be increased or decreased, and the depth of the model can be adjusted to balance accuracy and computational cost. The structure of EfficientViT is shown in Figure 5.  
MBConv [34] is a module for building efficient neural networks on mobile and embedded devices. It can reduce the number of parameters and computation while improving  
Figure 4: ViT structure. Figure 5: EfficientViT structure. the accuracy of the model by using Depthwise Separable Convolution (DSC) and Inverted Residual Connection. Lightweight MSA is a lightweight multi-scale attention mechanism in the EfficientViT model that is used to capture features at different scales. It consists of scale grouping modules, lightweight attention modules, and scale fusion modules, which are responsible for partitioning the input feature tensor into several groups of different scales, with each group containing features of the same scale. Attention weighting is performed on the features of each scale to capture feature information at different scales. This module uses a set of lightweight convolutional layers and attention mechanisms to reduce computational and memory costs. The weighted feature tensors are then fused in the channel dimension to produce the final multi-scale feature representation.