# Deep Learning Seehive Monitoring System for Early Detection of the Varroa Mite
## 4 Proposed Method for Varroa Mite Early Detection
The trained Convolutional Neural Network (CNN) is used to solve the problem of swarming by counting bees' concentration above the bee frames and inside the beehive lid. The detection categories that the authors' classifier has used are: **Class 0:** No bees detected. **Class 1:** very small number of bee detection (less than 10). **Class 2:** Small number of bee detection (20-30). **Class 3:** Medium number of bee detection (30-50). **Class 4:** High number of bee detection (more than 50). For each class, a number of detected bees has been set as a class identifier (The class identifier boundaries can be arbitrary and set accordingly at the detection service configuration file). Therefore, the selected initial dataset must consist of at least 1000 images per detection class, a total of 5000 images used for our training CNN case. * **Step 2--Images transformation and manual data annotation:** All images that went through the clearing process were manually annotated using the LabellImg [48] tool. There are other tools used for the photo annotation process, such as Labelbox [49], ImgAnnotation [50] and the Computer Vision Annotation Tool [51], which always create an output in either the JSON or XML format. The resolution and clarity of the original images are extremely important, as this facilitates the detection of the Varroa mite. Regarding the clarity of the photo, the method used is as follows. A bilateral filter smothers all images using a degree of smoothing sigma = 0.5-0.8 and a small \(7\times 7\) kernel. Afterward, all photos must be scaled to particular and fixed dimensions to be inserted into the training network. Scaling is performed either using a cubic interpolation process or a super-resolution EDSR process [52]. The preparation of the photos is initially based on the dimensions that each training algorithm requires for its smooth operation. The OpenCV [53] library is used for the image transformation process and is part of the second and fifth stages of detection. The second stage is before the detection of bees using CNN, and the fifth is the stage of detection of the Varroa mite (see Figure 2). * **Step 2--Training process:** The training process is based on the use of PyTorch pretrained Convolutional Neural Network (CNN) models [54] and the use of all available system resources. The essential computer subsystem for the training process is the GPU to speed up the neural network training. CUDA tools and libraries are used for this purpose according to PyTorch requirements. CNN's creation is based on pre-existing PyTorch [54] trained models used to train the neural network to detect bees. The selected PyTorch models and their capabilities for the detection process are presented in Table 1. After the annotation of the images of Step 2 is completed, the images are divided into two sets. The first set is the training set which contains 70-80% of the annotated photos, and the remaining 20-30% is the test set. The second can be divided into 50% to create another set which will be the validations sample. Then, you choose the model that will be used for the training. The output of the training process is the CNN model used in Figure 2, which is the Step 2 detection process of bee objects. * **Step 3--Detected bee contours:** This step includes a selection process of bee-detected objects based on the confidence threshold value set by the service. A good confidence value threshold that can be used is above 0.5 (50%). Then, the Gaussian filtering cubic interpolation is applied to the selected contours to scale them to sizes (wxh) of 40 \(\times\) 50 px for step 4 to apply on each distinct ROI. * **Step 4--ROI masking, Varroa mite detection step:** This step includes a color transformation from RGB to HSV. Then, an appropriate HSV mask is applied to each bee scaled image, transforming them into binary images, where the detected by the mask areas are set to white and all other areas to black. Then, a Hough transformation is