## 2 Materials and Methods
### Data Analysis Methodology
#### 2.5.2 Mask-Region-Based Convolutional Neural Network (Mask R-CNN)  
To determine the pesticide residue coverage, a Mask R-CNN was developed based on previously reported architectures with the integration of Faster R-CNN and Fast R-CNN [50, 58, 59]. The proposed standard Mask R-CNN model was based on the popular ResNet50 backbone, a ubiquitous pre-trained convolutional neural network, in addition to an FPN [60], which creates a multi-scale feature pyramid containing varying spatial resolutions from rich semantic information to precise spatial details, by combining features  
Figure 3: Diagram of the proposed convolutional neural network (CNN) structure for pesticide residue image analysis. from different levels of the backbone network. Generally, the Mask R-CNN consists of four stages: (1) The Region Proposal Network (RPN), used for generating region proposals (bounding boxes) that have a probability of containing objects within the image, operating on the feature map generated by the aforementioned backbone network. The Region of Interest (RoI) Align layer is introduced to align the features within a region of interest with the output spatial grid of the output feature map. This layer is crucial in preventing information loss that can occur during the quantization of the RoI's spatial coordinates to the nearest integer. (2) The RoI pooling layer is crucial for resizing images to a fixed dimension regardless of the original aspect ratio. (3) The feature extraction component feeds the resized RoIs to the CNN to extract the features of each region. (4) Classification and bounding Box regression is used to detect each object and classify it into the most suitable class, hence generating a binary mask for each object detected in the image by delineating the precise pixel values of each object instance. Altogether, these processes are based on the image features and the bounding box is specified based on the coordinates of the confined object present in the image. The Mask R-CNN was selected due to its wide acceptance and usage as segmentation model in the computer vision field. On the other hand, to avoid poor performance during both training and testing, as well as false positives and the generation of low-quality masks, in this work, the Mask R-CNN was firstly trained on a well-annotated and comprehensive dataset such as the MS COCO dataset [61]. The limited availability of specific high-quality annotated data led to the decision to fine-tune a pre-trained network according to the specifications rather than to train the network solely on the collected data. In this study, the model was finely tuned to identify and classify specific features related to the study objectives, following the previously reported method with some modification [62]. Lastly, the Mask R-CNN generated a high-quality segmentation mask of the area of the leaf coated with the pesticide residue. Subsequently, the number of pixels present in the segmented image was utilized to calculate the approximate pesticide (OTC and Kocide) residue coverage percentage. In order to acquire classifications and segmentation masks according to requirements, the ResNet-based Mask R-CNN was fine-tuned to be adapted to perform the specific task of pesticide residue detection and segmentation. The limited size of the custom dataset of pesticide-sprayed plant images was a crucial factor in the selection of hyperparameters such as the number of epochs to be trained, the learning rate chosen, and regularization techniques for optimizing the model's accuracy. The annotation tool VGG Image Annotator (VIA) was used to perform pixel-wise annotation on the custom dataset so as to provide fine-grained segmentation training masks. The dataset was divided into distinct subsets with a split of 70% for training, 20% for validation, and 10% for testing. To mitigate the risk of overfitting, especially given the small size of the dataset, we selected 50 training epochs.