# A New Hybrid ConvViT Model for Dangerous Farm Insect Detection
## 3 Materials and Methods
### Proposed Hybrid ConvViT Model
The EfficientNet-B0 extracts information from local image features through GAP processing, creating a standardized vector from its final layer. The CNN delivers learned local features through this vector output. The ViT architecture divides image inputs into patches to send through its model input. Classification in ViT depends \begin{table}
\begin{tabular}{c c} \hline \hline
**Model** & **Hyper-Parameters** \\ \hline EfficientNetB0 & Learning rate: 0.001, dropout: 0.2, epoch: 50, optimizer: [PERSON], batch size: 32 \\ \hline DenseNet201 & Learning rate: 0.0001, dropout: 0.3, epoch: 50, optimizer: [PERSON], batch size: 16 \\ \hline ResNet-50 & Learning rate: 0.0001, dropout: none, epoch: 50, optimizer: [PERSON], batch size: 32 \\ \hline VGG-16 & Learning rate: 0.0001, dropout: 0.5, epoch: 50, optimizer: [PERSON], batch size: 16 \\ \hline ViT & Patch size: 16 \(\times\) 16, embedding size: 768, attention heads: 12, transformer layer count: 8, MLP learning rate: 0.0001, hidden layer size: 3072, dropout: 0.1, optimizer: [PERSON], batch size: 16, epoch: 50 \\ \hline ConvViT & CNN (kernel size: 3 \(\times\) 3, pooling size: 2 \(\times\) 2, number of convolution layers: 3, filter size: 64, dropout: 0.2, activation function: ReLU), ViT (learning rate: 0.0001, patch size: 16 \(\times\) 16, embedding size: 768, attention heads: 12, transformer layer count: 8, MLP hidden layer size: 3072, dropout: 0.1, optimizer: [PERSON], batch size: 32, epoch: 50) \\ \hline \hline \end{tabular}
\end{table} 
Table 2: The optimized parameters of the models. on class tokens that emerge from its final layer as global context information agents. A feature concatenation integration method joins GAP outputs from the CNN with ViT CLS token outputs. This process ensures that local and global features are learned together: Both features go through a fully connected layer, producing the model's output. The proposed method connects the CNN's local detail-processing capabilities with the ViT's ability to understand global context while creating a superior representation framework. The combined method enhances overall performance on complex images. Figure 3 illustrates the architecture of ConvViT. ConvViT, as seen in Figure 3, combines the powerful and practical features of a CNN and a ViT in a hybrid structure, extracting local features with the CNN and capturing global dependencies with the ViT. The CNN extracts local patterns from input images. In the ConvViT architecture, the CNN consists of convolutional and max pooling layers. Convolutional layers apply convolution to extract local features required to identify physical features in agricultural pest images. The pooling layer reduces the size of the feature map and allows the most essential features in the image to be focused on. The features extracted by the CNN are transferred to the ViT. The input layer takes the pixel values of the images and normalizes or resizes them for preprocessing. In the ConvViT model, the CNN is used for feature extraction. The CNN obtains feature maps by applying convolution and pooling to the images. Feature maps contain a high-level representation of the images. The ViT takes the feature maps as input, processes them, and models the visual relationships through attention mechanisms. The feature maps are divided into small tokens and embedded linearly. The ViT applies multi-head self-attention to capture global relationships between different tokens. The tokens are normalized and processed by a multi-layer perceptron (MLP) to improve representation learning. The output of ConvViT is passed to fully connected layers and undergoes softmax activation to predict the class label. Figure 3: The architecture of ConvViT. Our research study introduces the ConvViT model, which contains the primary features detailed below. The ConvViT framework uses local feature precision from CNN methods alongside global pattern expertise from ViT models. By adopting ConvViT, the model achieves its dual goal of maintaining effective modeling for both local details and the global context.