## 2 Materials and Methods  
### The Data Characteristics  
The cow images (RGB) and thermal images were taken from Holstein-Friesian cattle raised in the dairy farm of the Livestock Research Institute, COA. A total of 3152 dairy cattle images were included in the model establishment of this study, and the model was trained by cross-validation of 10:1. The data collection was completed from August 2019 to February 2020. The image tag content includes: (1) cow images; (2) individual IDs;(3) thermal images of eye sockets. These data were used as benchmarks, and served as a database. The digital and thermal images are shown in Figure 1a,b. The image capture system included an RGB network camera and thermal imager module, and was covered with an aluminum casing to prevent the intrusion of dust and moisture. The RGB images were collected using a Logitech C920 (HD PRO, Logitech, Suzhou, China) in color mode with full HD resolution of 1920 \(\times\) 1080 pixels. The thermal image resolution was 640 \(\times\) 480 pixels. The automatic body temperature detection system was set up on a wall in front of the dairy cattle aisle, 2 m away from the cattle to be tested, and shot forward at a 30\({}^{\circ}\) inclination angle, which could completely record the cows passing by (including their faces and bodies). The data included images of dairy farms on sunny, cloudy, and rainy days, and these were included in the training and analysis to ensure the inclusion of image feature information in different climates. All collected image information was individually labeled through the open-source program windows_v1.8.0 labelImg.exe. In this study, a total of 16 classification labels were established, including the individual numbers of 15 dairy cows in the RGB images and the thermal image marks of the eye sockets. Each input image was divided into a \(7\times 7\) grid in YOLO V3-tiny. This network uses the features in the target area to predict the bounding box. Each grid cell predicts bounding boxes and confidence scores for those boxes. The grid unit is responsible for detecting the object whose center falls into the grid cell [15]. The detection pipeline of YOLO V3-tiny is shown in Figure 2.  
Figure 1: Data collection: (**a**) RGB Image; (**b**) Thermal Image. Figure 2: Detection pipeline of YOLO V3-tiny: (**a**) 7 \(\times\) 7 grids on input; (**b**) probability map; (**c**) predict bounding boxes and confidence; (**d**) result. Each grid has B anchor boxes. We could predict the coordinates, confidence score and classification probability according to the calculation formula. The final output tensor of the neural network is shown in Equation (1). \[\text{Output tensor}=S\times S\times B\times(5+C) \tag{1}\]  
We used the YOLO V3-tiny model training architecture as the recognition basis for the automatic body temperature detection system. The network prediction bounding box contained four coordinates of \(t_{x}\), \(t_{y}\), \(t_{w}\) and \(t_{h}\). If the cell was offset from the top left boundary (\(C_{x}\) and \(C_{y}\)) of the image and the previous bounding box has height (\(p_{h}\)) and width (\(p_{w}\)), respectively, then the predictions corresponded to Equations (2)-(5) [12; 14]. Figure 3 shows the bounding boxes with location prediction and dimension priors. \[b_{x}=\sigma(t_{x})+c_{x} \tag{2}\] \[b_{y}=\sigma(t_{y})+c_{y}\] (3) \[b_{w}=p_{w}e^{t_{w}}\] (4) \[b_{h}=p_{h}e^{t_{w}} \tag{5}\]  
\(b_{x}\), \(b_{y}\), \(b_{w}\), \(b_{h}\) are the coordinate values of the offset prediction. These four coordinate values were calculated according to the square distance error loss. YOLO V3-tiny used logistic regression of each bounding box to predict the score of the object [14]. Through label classification, each box could predict the types of items contained in the bounding box. Compared with YOLO V3, the simplified characteristics of the YOLO V3-tiny model enable it to process image feature extraction and identification more quickly. In addition, it can be trained on hardware conditions with only 1 GB of GPU [15].