# Deep Learning-Based Portable Image Analysis System for Real-Time Detection of _Vespa velutina_
## 2 Materials and Methods
### Deep Learning Model  
Deep learning algorithms for object detection in image data can be categorized into one- and two-stage methods. One-stage algorithms localize and classify the detected object simultaneously. Examples of one-stage algorithms are the single-shot detector (SSD) and YOLO [22; 23; 24; 25; 27]. In contrast, two-stage algorithms perform object localization first, followed by classification. Examples of two-stage algorithms include R-CNN, Fast R-CNN, and Faster R-CNN [28; 29; 30]. In general, one-stage algorithms have faster processing speeds but lower accuracy compared to the two-stage approach. [PERSON] et al. evaluated the performance of real-time object detection by YOLOv3, YOLOv5s, and MobileNet-SSD V2 and showed that the real-time object detection performance of YOLOv5s was superior to that of SSD [31].  
The proposed system performs real-time image analysis and transmission via RTSP simultaneously using the image analysis device Jetson Xavier NX. Therefore, YOLOv5s was selected because of its fast processing speed. YOLOv5s divides input image data into \(S\times S\) grid cells, and if an object's center is present in a grid cell, it is detected by that grid cell. Each grid cell predicts \(B\) number of bounding boxes and the confidence score for each bounding box. The confidence score is an indicator of the model's certainty in the detection and represents the probability that each bounding box contains an object \(Pr(Object)\) and  
Figure 4: Distance between the beehive and camera. Image data for setting the range of system detection: Image data including (**a**) one beehive (distance = 40 cm); (**b**) two beehives (distance = 55 cm); (**c**) three beehives (distance = 90 cm).  
the accuracy of the predicted bounding box (\(IoU_{pred}^{truth}\)). The confidence score calculation formula is expressed by Equations (1) and (2).  
\[Confidencescore=Pr(Object)*IoU_{pred}^{truth} \tag{1}\]  
\[IoU_{pred}^{truth}=\frac{B_{truth}\cap B_{pred}}{B_{truth}\cup B_{pred}} \tag{2}\]  
When an object is present, each grid cell also calculates the probability of each class \(Pr(Class_{i}|Object)\). Then, the detection of objects in image data is performed by multiplying the confidence score for each bounding box with the corresponding probability of each class, as shown in Equation (3).  
\[Pr(Class_{i}|Object)*Pr(Object)*IOU_{pred}^{truth}=Pr(Class_{i})*IOU_{pred}^{truth} \tag{3}\]  
\[Pr(Class_{i}|Object)*Pr(Object)\text{is replaced by}Pr(Class_{i})\text{ because}\ Pr(Class_{i})\text{ can represent the same mathematical expression.}\ Pr(Class_{i})\text{ represents the probability that the object contained in the grid cell belongs to \(Class_{i}\)[22].  
The biggest change in YOLOv5 is the implementation of CSP-Darknet using PyTorch, replacing the backbone, which was previously implemented in C language. The primary function of the backbone is to convert input image data into feature maps through convolutional operations (Conv, C3). The neck upsamples feature maps and concatenates (Concat) them with other feature maps to harmonize the features extracted from the backbone. The head is responsible for performing localization and classification. Due to the multiple feature maps generated by the neck, YOLOv5 can effectively detect multiple objects in a single image.