Next Article in Journal
Developing a Reliable Welfare Assessment Tool for Captive Hibernatory Bear Species
Previous Article in Journal
Systematic Analysis of Breed, Methodological, and Geographical Impact on Equine Sperm Progressive Motility
Previous Article in Special Issue
The Application of Cameras in Precision Pig Farming: An Overview for Swine-Keeping Professionals
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Deep-Learning-Based Automatic Monitoring of Pigs’ Physico-Temporal Activities at Different Greenhouse Gas Concentrations

1
Department of Biosystems Engineering, Institute of Smart Farm, Gyeongsang National University, Jinju 52828, Korea
2
Ministry of Communication and Information Technology, Singha Durbar, Kathmandu 44600, Nepal
3
Smart Farm Research Center, Gyeongsang National University, Jinju 52828, Korea
*
Author to whom correspondence should be addressed.
Animals 2021, 11(11), 3089; https://doi.org/10.3390/ani11113089
Submission received: 13 October 2021 / Revised: 27 October 2021 / Accepted: 28 October 2021 / Published: 29 October 2021

Abstract

:

Simple Summary

Animals exhibit their internal and external stimuli through changing behavior. Therefore, people intrinsically used animal physical activities as an indicator to determine their health and welfare status. A deep-learning-based pig posture and locomotion activity detection and tracking algorithm were designed to measure those behavior changes in an experimental pig barn at different greenhouse gas (GHG) levels. The naturally occurring GHGs in the livestock were elevated by closing ventilators for an hour in the morning, during the day, and at nighttime. Additionally, the corresponding pig posture and locomotion activity were measured before, during, and after an hour of treatment. With the increase in GHG concentration, the pigs became less active, increasing their lateral-lying posture duration. In addition, standing, sternal-lying, and walking activities were decreased with the increment in GHG levels. Therefore, monitoring and tracking pigs’ physical behaviors using a simple RGB camera and a deep-learning object detection model, coupled with a real-time tracking algorithm, would effectively monitor the individual pigs’ health and welfare.

Abstract

Pig behavior is an integral part of health and welfare management, as pigs usually reflect their inner emotions through behavior change. The livestock environment plays a key role in pigs’ health and wellbeing. A poor farm environment increases the toxic GHGs, which might deteriorate pigs’ health and welfare. In this study a computer-vision-based automatic monitoring and tracking model was proposed to detect pigs’ short-term physical activities in the compromised environment. The ventilators of the livestock barn were closed for an hour, three times in a day (07:00–08:00, 13:00–14:00, and 20:00–21:00) to create a compromised environment, which increases the GHGs level significantly. The corresponding pig activities were observed before, during, and after an hour of the treatment. Two widely used object detection models (YOLOv4 and Faster R-CNN) were trained and compared their performances in terms of pig localization and posture detection. The YOLOv4, which outperformed the Faster R-CNN model, was coupled with a Deep-SORT tracking algorithm to detect and track the pig activities. The results revealed that the pigs became more inactive with the increase in GHG concentration, reducing their standing and walking activities. Moreover, the pigs shortened their sternal-lying posture, increasing the lateral lying posture duration at higher GHG concentration. The high detection accuracy (mAP: 98.67%) and tracking accuracy (MOTA: 93.86% and MOTP: 82.41%) signify the models’ efficacy in the monitoring and tracking of pigs’ physical activities non-invasively.

Graphical Abstract

1. Introduction

Pig behavior is a key trait for recognizing their health and welfare conditions [1]. Regular monitoring of pigs’ physical activity is essential to identify short- and long-term pig stresses [2]. Although the monitoring of pigs round-the-clock in precision farming provides invaluable information regarding their physical and biological status, manual monitoring of every single pig in a large-scale commercial farm is impractical due to the requirement for a higher animal-to-staff ratio, consequently increasing production cost. Therefore, the staff can only observe the pig briefly and might miss identifying subtle changes in the pigs’ activity [3]. Furthermore, the presence of a human in the barn influences the pigs’ behavior, leading to unusual activity that can be misunderstood during the decision-making process [4,5]. Therefore, sensor-based non-disturbing automatic monitoring of pigs is being used considerably.
Numerous studies have shown that the housing environment greatly influences the physical and social behavior of the pigs. Changes in posture and locomotion are key indicators of disease (clinical and subclinical) and compromised welfare [6]. It is also an indicator of pig comfort in the reared environment. For instance, a pig utilizes different lying postures to cope with ambient temperature and maintains body temperature through thermoregulation [7]. They prefer lateral-lying positions in high ambient temperature and sternal-lying at low-temperature conditions. Alameer et al. [8] observed significant changes in posture and locomotion activities with limited feed supply. Identifying subtle changes in pig posture is challenging by sporadic human observation since a pig spends most of the time (88% time in a day) lying in a thermo-comfort environment [7]. Therefore, a computer vision-based automatic monitoring system is valuable, identifying the minute changes in posture through continuous monitoring.
Moreover, there is a burgeoning concern of animal health and welfare in the intensive farmhouse [8,9]. Behavior monitoring is even more pertinent in group-housed pigs as they exhibit significant behavior changes in the compromised environment [10]. Another equally important concern is the emission of greenhouse gases (GHGs) from the extensive livestock farming. Pig manure management is the second-highest contributor (27%) after feed production (60%) in the overall emission of GHGs from the livestock barn. Besides, enteric fermentation and various on-farm energy usage devices produce the major GHGs [11]. Correspondingly, the high GHG concentration inside the livestock barn stems from poor manure management, an improper ventilation system, and densely populated pigs, affecting the pigs’ behaviors [12,13]. Since pigs are averse to an excessive amount of GHGs, such as carbon dioxide (CO2), methane (CH4), and nitrous oxide (N2O), and show discomfort and pain in such environments, it is essential to observe the response of pigs in terms of posture activities with increased indoor GHGs.
CO2 and N2O, two major GHGs produced in the livestock, are commonly used for euthanizing the pigs, regardless of questions over the pigs’ welfare. Various studies have been conducted by assessing the pigs’ response during stunning. Atkinson et al. [13] observed the changes in pigs’ behavior and meat quality while applying different concentrations of CO2. Two different CO2 concentrations, 20C2O (20% CO2 and 2% O2) and 90C (90% CO2 in air), were exposed to slaughter pigs, and it was found that pigs felt more uncomfortable in the 90C concentration, with 100% of pigs being stunned. In another experiment, CO2, CO2 plus Butorphanol, and N2O gases were applied to compare stress levels during the euthanization of pigs [12]. Although they were unable to identify the distinction in stress levels in those treatments, N2O application could be more humane than CO2. Similar results were found by Lindahl et al. [14] in that N2O-filled foam could be a suitable alternative to CO2 when stunning pigs, improving animal welfare. Verhoeven et al. [15] studied the time taken for the slaughter pig to become unconscious by using different concentrations of CO2 (80% and 95%) and studying their corresponding effects on behavior changes. The higher the gas concentration, the quicker the time for the pig to become unconscious (33 ± 7 s). This shows that pigs are significantly affected by a high concentration of GHGs. However, to our knowledge, no study has been conducted to observe the pigs’ behavioral alteration in naturally increased GHGs due to poor livestock management. Therefore, it is essential to monitor the pigs’ behavior in the GHG-concentrated environment, as the livestock barn emits a considerable amount of GHGs [16].
In this scenario, several studies have been conducted for monitoring the pigs’ activity at individual and group levels over the last few decades. The implementation of computer-vision-based monitoring systems in pig barns has been soaring due to the automatic, low cost, real-time monitoring, non-contact, animal friendly, and state-of-the-art performance [17,18,19,20,21,22,23,24,25,26]. An ellipse-fitting and image-processing technique was used to monitor the pigs’ mounting behavior in the commercial farm [18]. Various features such as ellipse-like shape, centroid, axis lengths, and Euclidean distance of head-tail and head-side were extracted to detect the pigs’ mounting position. Similarly, lying behaviors (sternal and lateral lying) at individual and group levels have been classified using image-processing techniques [19,20], where pig bodies from the video frames were extracted using background subtraction and the Otsu threshold algorithm, and then an ellipse-fitting method was applied to determine the lying postures. Matthews et al. [21] implemented a 3D camera and an image-processing algorithm to detect pigs’ behaviors (standing or not standing, feeding, and drinking). The XYZ coordinates obtained from the depth sensor, camera position, and vertical angle of the camera were used to filter out unnecessary scenes such as the floor, walls, and gates. In addition, an outlier threshold calculated from the grand mean and standard deviation was set to remove the unusual depth noise. A region-growing technique for similar pixels was used to detect the pig, whereas a Hungarian algorithm was used to track pigs between the frames. The image-processing technique, although widely used in pig monitoring, demands various pre- and post-processing steps. It is even challenging in an uncontrolled house environment, variable illumination, huddled pigs, and deformed body shapes [17,22].
Accordingly, a convolutional neural network (CNN)-based deep-learning object detection model outperformed the conventional image-processing techniques. Recently, various researches have been carried out using a deep-learning model as an end-to-end activity detection and scoring model rather than only for object detection. A combination of a CNN and a recurrent neural network (RNN) has been used to extract the spatial and temporal features of pigs for tail-biting detection [23], where a pair of bitten and biting pigs from the video frames were detected using a single-shot detector (SSD) with two base networks, Visual Graphic Group-16 (VGG-16) and Residual Network-50 (ResNet-50). A video of tail-biting behavior was sub-divided into a short video of 1 s length to minimize the tracking error. Then, the pairwise interaction of the two pigs was identified by the trajectory of motion in the subsequent frames to detect the biting and bitten pigs. They achieved an accuracy of 89.23% to identify and locate the tail-biting behavior of pigs. Likewise, the pigs’ posture (standing, dog sitting, sternal lying, and lateral lying) and drinking activity were detected automatically using two deep-learning models (YOLO: you only look once; Faster R-CNN) [8]. They found that the YOLO model outperformed the Faster R-CNN (ResNet-50 as a base network) in both activity detection accuracy and speed. They observed the distinction in pig behavior by creating hunger stress and achieved the highest mAP from the YOLO model (0.989 ± 0.009). In addition, the mean squared error (MSE) on the distance traveled by a pig and its average speed were 0.078 and 0.002, respectively.
Similarly, the performance of three deep-learning architectures—namely, Faster R-CNN, SSD, and region-based fully convolutional network (R-FCN) having Inception V2, ResNet, and Inception ResNet V2, respectively, as their base networks—have been evaluated during the detection of pigs’ standing, belly-lying, and lateral-lying activities [24]. The datasets were collected from three commercial pig barns with different colors and age groups of pigs. All the models showed superior detection capabilities (maximum AP of 0.95 compared to standing AP of 0.93 and belly lying AP of 0.92) for the lying by side pigs due to having unique features. Yang et al. [25] developed an FCN-based segmentation and feature extraction model coupled with an SVM classifier to detect sow nursing behavior. Initially, the sow image was segmented from the video frames, and converted into a binary image. Features such as area and length-to-width ratio were extracted to find out the possible nursing conditions. Then, the nursing activity was further confirmed by identifying the udder region using geometrical information from the sows′ shape and the number of piglets present, which was estimated by the area covered by them and their movement. Although this technique required heavy manual effort during the spatial and temporal feature extraction and analysis, it produced state-of-the-art performance on their testing videos (accuracy, sensitivity, and specificity of 97.6%, 90.9%, and 99.2%, respectively).
Even though the deep-learning-based object detection model has surpassed the conventional image-processing technique, due to the limited availability of labeled datasets for wide varieties of piggery environments, it is, therefore, challenging to build a fully generalized model. However, Riekert et al. [26] attempted to develop a generalized deep-learning model using a faster region-based convolutional neural network (R-CNN) with neural architecture search (NAS) as a base network to detect lying or not lying pigs. They applied a large number of training datasets (7277 manually annotated) captured by multiple 2D cameras (20), from various pens (18), prepared from 31 different one-hour videos. The trained model achieved an average precision (AP) of 87.4% and a mean AP (mAP) of 80.2% for the images taken from separate pens with a similar experimental environment during testing. However, the performance reduced significantly (AP of 67.7% and mAP between 44.8% and 58.8%) for those pens with different and complex environmental conditions, which is obvious and signifies that the training dataset is crucial for the deep-learning model to make a generalized model.
Therefore, in this study, a CNN-based deep-learning object detection model, coupled with a real-time tracking algorithm (Deep-SORT), was implemented to detect and track pigs’ standing and lying (sternal and lateral lying) posture along with their locomotion activity in both group-wise and individual. Two commonly used object detection models (YOLOv4 and Faster R-CNN) were trained and compared their performance on pig posture detection. The walking activity of the standing pig was determined by assessing the changes in pig position for the consecutive frames. The distance and speed of the walking pig were calculated by cumulating the movement of the standing pigs within a period. In addition, the GHG concentration in the experimental barn was increased naturally by entrapping the GHGs emitted from the pig barn. The gas samples taken during the study period were analyzed using a gas chromatography. Then, the pigs’ activities during the treatment hours were compared with the activities before and after the treatment hour. Finally, an automatic pig-activity-scoring algorithm was integrated with the trained model for scoring the pig behavior. Thus, the main objective of this experiment was to build a deep-learning-based end-to-end model for the detection and scoring of group-wise and individual pigs’ postures and locomotion activity in the compromised environment.

2. Materials and Methods

2.1. Experimental House and Animals

This experiment was conducted in an experimental pig barn located at the Gyeongsang National University (Latitude: 35.1517241; Longitude: 128.0958942; and Altitude: 44 M). The pig barn has dimensions of 5.4 m × 3.4 m × 2.9 m (length × breadth × ridge height) with four walls, a symmetrical double-pitched roof of thickness 5 cm, and fully slatted floors [27]. Beneath the slatted floor, there were two boxes for manure collection. The pig house has a feeder system for individual feeding with hydraulic-controlled separate gates for pig entry and exit and three drinking nipples at different heights at the mid-section of a long sidewall. It is equipped with an air damper (Auto-Damper 250, Sanison Co., Ltd., Daegu, Korea) above the door and an exhaust fan opposite the entrance for smooth air movement with an average of 0.16 m3/s [28]. Five pigs (four female and one male) of the Yorkshire breed were transferred from the local breeding house in May 2020 and bred up to the fattening stage for experimental purposes. The available floor space for each pig in this experiment was 3.67 m2/pig, which was more spacious than the optimum floor space required (0.8 m2/pig) in the commercial pig barn in Korea [29]. The pigs were fed twice per day (09:00 and 17:00) with dry feed, and the water supply was continuously available for drinking purposes. The pigs were marked on their backs using different colors and patterns to identify each pig visually, which was taken as a reference while annotating the pig identity for tracking. There was an attached room for monitoring and controlling the system with data collection facilities.

2.2. Experimental Setup and Data Collection

This study was conducted for the fattened pigs (107.14 ± 6.81 kg). The door, ventilator, and damper of the experimental pig barn were closed to increase the GHG concentrations. In addition, the major apertures on the wall, ventilator, and manure boxes were covered, as shown in Figure 1. The treatment was applied for an hour three times a day in the morning time (07:00–08:00), daytime (13:00–14:00), nighttime (20:00–21:00), repeating for three days. During the study period, the average indoor temperature and relative humidity were 26.68 ± 5.23 °C and 57.62 ± 15.14%, respectively. The environmental parameters were maintained and recorded by a livestock environment monitoring system (LEMS) (AgriRobo Tech Co. Ltd., Icheon, Korea). The gas samples were collected before starting treatment, after completing treatment, and one hour later of finishing treatment, using 50 mL syringes [30]. Three gas samples from three different spatial positions were taken at each time, as shown in Figure 1a. Then, the concentration of GHGs was analyzed using gas chromatography (GC) (7890B GC system, Agilent Technologies, Santa Clara, CA, USA). Additionally, the CO2 data were also recorded in the LEMS system using two sensors.
A top-view network camera (HIKVISION IP camera, Model: DS-2CD2010-I, HIKVISION Co. Ltd., Hangzhou, China) was installed on the ceiling, with the camera view pointing vertically down. The field of view covered all the pigs that resided on the open floor area, but the pig staying inside the feeder was blocked by the feeder structure. The camera was configured at 30 frames per second (FPS) with a high-definition resolution (1920 × 1080 pixels), which was connected to a network video recorder (NVR) (HIKVISION 4K NVR, Model: DS-7608NI-I2/8P, HIKVISION Co. Ltd., Hangzhou, China) to store the video throughout the experiment period. The camera was also accessed through its application programming interface (API) [31] in Python and saved every second frame in the server for the training and testing purpose of the model. However, the pigs’ activities during the study period were analyzed from the video files exported from the NVR. In each experiment instance, three hours of videos (before, during, and after the treatment) were analyzed. Therefore, throughout the study period, a total of 27 h of videos (3 × 3 × 3 h) were examined.

2.3. Image Pre-Processing and Dataset Preparation

The raw images were pre-processed before further utilization. The original image of dimensions 1920 × 1080 was resized to 640 × 640 pixels to meet the requirements of the pre-trained deep-learning model. Moreover, the pig postures (sternal lying, lateral lying, and standing) were localized and labeled on the resized frames. Before annotation, the similarity between the consecutive frames was checked because, in every second frame, the adjacent image frames were not varying significantly, as the pigs mostly remained inactive. We used a perceptive hash (pHash) technique [32], which generates 64-bit long hash values according to the visual appearances. This was to provide diverse training images, increasing the robustness of the model while testing. A discrete cosine transform (DCT) of an image was calculated, and 8 × 8 transform coefficients were selected and raveled to make a 64-bit one-dimensional array. A median was calculated from the 64 DCT coefficients and then 64-bit long hash values were created using Equation (1):
h i = { 0 , C i < m 1 , C i m
where h i is an ith position bit of the pHash value, C i is the ith position’s DCT coefficient, and m is the median of DCT coefficients. The hash distance was set to 1 to filter out only the too similar frames. In addition, the corrupt frames that occurred during the image collection were removed. In this way, a total of 6680 pre-processed images were prepared and annotated manually using a computer vision annotation tool (CVAT) [33]. Some of the guidelines set by the Pascal VOC 2010 [34] were followed while annotating the pig postures. As per the guidelines, if more than 15–20% of the object is not covered by the bounding box (BB), it needs to be marked as truncated and a BB drawn to cover only the visible part. Similarly, for the occluded object, the BB is drawn to cover all the visible parts, setting the occluded flag if the occlusion is more than 5%. We followed the BB generation method similar to the guidelines except the setting of the truncated and occlusion flag [26].
Although there are no standard datasets available for pig posture, three posture categories of pigs (standing, lateral lying, and sternal lying) were labeled manually in this study according to the convention applied by Nasirahmadi et al. [19] and Alameer et al. [8], as shown in Table 1. The annotated information was saved in Pascal VOC format and later converted into TFRecord format for the Faster R-CNN model and in Darknet format for the YOLO model. The total number of annotated postures was 30,233. The labeled images were then randomly split into training and testing datasets at a ratio of 90:10. Thus, 6012 images were used for model training, and the remaining (668) images were used for testing purposes. We had opted to select the 90:10 ratio for training and testing because of the limited number of labeled datasets. The trained model was later utilized for detecting the pigs’ postures in the images collected during the study periods. The labeled testing datasets are made available in the supplementary files [Datasets].
For the tracking dataset, one-minute video clips after downsizing to 5 frames per second (FPS) were annotated in a similar way to the pig detection dataset with an additional pig ID assigned to each pig. All the pigs were marked by a color marker with a distinct pattern, which helped to set the pig IDs even in different video clips. If a pig was out of a frame and later visible into the frame, we gave the same ID to that pig.

2.4. Proposed Methodology

The prime objectives of this study were to detect the pig postures in a frame, tracking them individually, and finally scoring each pig posture with time. Therefore, the foremost task in the input video frame was to detect the pig posture and localize it in the given frame. Secondly, a tracking algorithm associated the detection metric with an ID and maintained the same ID for the successive frames. Finally, the quantification of pig activities during the study period was performed. The complete steps of the proposed methodology are shown in Figure 2. The posture detection model and tracking model were trained separately. Then the trained models were coupled together with a posture scoring algorithm to make a complete end-to-end pig posture scoring model.

2.4.1. Pig Posture Activity Detection Model

YOLOv4 model: YOLO is a prominent object detection model that outperforms other detection models in terms of both accuracy and speed. Moreover, the latest version of the YOLO series improved significantly in both object detection accuracy and speed. This study uses YOLO version 4 [35] due to its superior performance than the earlier versions in public datasets. It works as a single-stage object detection model, which speeds up the object detection time. The network architecture of YOLOv4 consists of three blocks, as shown in Figure 3. The backbone block uses the deep convolutional neural network CSPDarknet53 (cross-stage partial connections Darknet53) for feature extraction. The neck block uses a spatial pyramid pooling (SPP) and path aggregation network (PAN) to concatenate and fuse the different-sized feature maps. The head block uses the dense prediction network implemented by YOLOv3 [36] to predict the bounding box and class. The significant improvement in the methodological, regularization, and data augmentation techniques placed the YOLOv4 on top.
Faster R-CNN model: A pre-trained object detection model trained by a large number of Microsoft common object in context (COCO) datasets [37] was downloaded from a GitHub archive [38] and re-trained to detect pig posture. A Faster R-CNN [39] with ResNet101 with the input image size of 640 × 640 as a feature extractor was implemented (Figure 4). It consisted of two modules, a region proposal network (RPN) and a Fast R-CNN detector [40]. First, an RPN module, a fully convolutional network that generates region proposals, was implemented. In RPNs, an n × n spatial window slides over the feature maps generated from the last shared convolutional layer to generate bounding boxes. The RPN shared the image features extracted by the object detection network resulting in faster computation than Fast R-CNN. It predicts the region proposal using anchor boxes of different sizes and aspect ratios to speed up the training and testing process. Second, a Fast R-CNN detector, which uses the proposed regions provided by the RPN, was implemented. A Faster R-CNN object detection model was chosen as it produces a satisfying average precision on pig posture detection [3,23].

2.4.2. Pig-Tracking Algorithm

After detecting and localizing the pig postures in a frame, a visual- and distance-based tracking algorithm called deep simple online real-time tracking (Deep-SORT) [41] was implemented to track the pigs individually. The Hungarian algorithm [42], implemented alongside, preserved the individual pig identity in consecutive frames, allowing for the detection of a lost or new pig in the next frame. The location of the missed pig was estimated using the Kalman filter [43]. Thus, it can track the pigs even in certain occlusions and frame corruptions. However, errors in detection led to deterioration of the tracking performance. Moreover, the pig posture obtained from the detection model was associated with an ID to determine the individual pig’s profile. The overall flow diagram of the pig-tracking algorithm is presented in Figure 5 [41]. In this study, we used offline video clips for analysis. Therefore, all the video files were sub-divided into 1-min video clips. Then the IDs of pigs in the first frame of each video clip were assigned based on the hierarchy of the detected pigs, allowing the algorithm to track for a minute.

2.4.3. Pig-Moving Detection and Activity-Scoring Algorithm

When the center coordinates of the standing pig changed more than the threshold pixels (4 pixels), the standing pig was considered as a walking pig [3]. The Euclidean distance (∆d) between the centroid of the standing pig in the consecutive frames was calculated to check the movement, and the total distance covered by the pig was obtained by summing the ∆ds for an hour. Likewise, the average speed of the moving pig was determined by dividing the total distance covered by the time taken. Moreover, the posture scores of the pigs at the individual and group levels were obtained using Equation (2) [8]:
P i ( a ) = k = 1 n A F k n
where P i ( a ) is the posture activity (for instance, lateral lying) of an ith pig, A F k is the kth frame that has the ith pig’s ath activity, and n is the total number of frames in a video clip. We first identified the individual pigs’ posture within one-minute video clips and then integrated them hour-wise to see the changes in behavior before, during, and after an hour of the treatment.

2.4.4. Training and Evaluation of the Model

The selection of a suitable learning rate in the deep-learning model is crucial. However, there is no ready-made solution for selecting the best learning rate in machine learning. The higher the learning rate, the quicker the learning speed and vice versa. However, too high and too low learning rates will not converge the network effectively [44]. As per the number of training datasets and the network structure, the training hyperparameters were chosen, as shown in Table 2 [35] and Table 3 [24].
The evaluation of the trained model was carried out on validation datasets. The intersection over union (IoU), which measures how accurately the model creates a bounding box of a pig in the frame, was calculated using an Equation (3) with a threshold of 0.6 [3]. The model’s localization performance is good when the detected bounding box and ground-truth bounding boxes have an IoU close to 1.
I o U = B B G T B B P B B G T B B P
where B B G T is a ground-truth bounding box, B B P is a predicted bounding box, is an intersection operator that calculates the common area covered by B B G T and B B P , and is a union operator that obtains the total area covered by both B B G T and B B P . Moreover, mean average precision (mAP), a widely used metric in object detection, was used to evaluate the model’s detection performance.
For the tracking algorithm, the commonly used metrics mentioned in the MOT 2016 MOT Challenge [45] were used. Multi-object tracking accuracy (MOTA) and multi-object tracking precision (MOTP), as given in Equations (4) and (5), respectively, were used to evaluate the tracking algorithm:
M O T A = 1 i ( F N i + F P i + I D S W i ) i G T i
where F N i is the false negative (untracked pigs in the ith frame), F P i is the false positives (wrongly tracked the pigs in the ith frame), I D S W i is the identity-switched pigs (given a new ID in the ith frame for the same pig in the previous frame), and G T i is the ground truth of pigs.
M O T P = t , i d i t i c i
where d i t is the distance or IoU between the ground-truth bounding box of an object and target t in the ith frame, and c i is the number of ground-truth targets in the ith frame.
The training and evaluation of the model were performed in Python 3.7.10 installed on the Windows 10 Pro operating system. The hardware configurations of the computer were Intel Core 10th generation i9-10900k processor with 32 × 2 GB RAM and an NVIDIA GeForce RTX 2070 GPU with 8 GB of dedicated memory. The main codes and algorithms are provided in the supplementary files [Code].

3. Results

3.1. Greenhouse Gas Concentrations

The GHG concentrations obtained after analyzing the gas samples were averaged and are presented in Figure 5. The GC has the ability to detect five varieties of GHGs, namely carbon dioxide (CO2), methane (CH4), carbon monoxide (CO), nitric oxide (NO), and nitrous oxide (N2O). CO2 is the dominant GHG, followed by CO and NO, whereas N2O was found in the lowest concentration in this experimental pig barn. The GHG concentrations were measured three times in each treatment instance (before, after, and one hour later of treatment completion), as shown in Figure 6.

3.2. Group-Wise Pig Posture and Walking Behavior Score

Group-wise pig posture and walking activity scores are measured by dividing the number of pigs with a particular posture by the number of frames before, during, and after treatment hour. Most of the time, pigs stayed in the lying position (sternal and lateral). However, the pigs were more active in the morning compared to the day and nighttime. Moreover, at night, pigs primarily rested in the lateral lying position. With the peak value in GHGs, the standing and walking activities of the pigs were decreased significantly (almost by half), as shown in Figure 7a,b. The standing score was increased with the decrease in GHGs (one hour later of treatment). A similar pattern was followed by the walking activity score, except in the morning, where the walking score did not increase noticeably. Likewise, the sternal lying behavior of the pigs also decreased with the increase in GHGs (Figure 7c). Conversely, the lateral lying behavior of the pigs increased significantly in the morning and daytime (nearly 40% in the morning and 30% in the day). However, it was marginally increased in the nighttime, as given in Figure 7d. One hour later of the treatment (08:00–09:00, 14:00–15:00, and 21:00–22:00), the GHGs remained relatively higher than before the treatment. Therefore, the respective effects on all the pigs’ activities were observed, as presented in Figure 7. The total distance traveled (in terms of pixels) by all walking pigs was higher in the morning before treatment hour and observed least in the nighttime treatment hour. Figure 8 demonstrates the total distance traveled and the locomotion pattern of walking pigs on the morning of the day 1 experiment. The detected pig postures with the locomotion activity and pig identifications are available in the supplementary file [Result].

3.3. Individual Pig Posture and Walking Behavior

The tracking algorithm provided a virtual ID to each pig and hept tracking them until the number of missing frames was less than the specified age of the ID (50). The individual posture and walking activities were determined similarly as group-wise behavior measurements, except treating them individually. The posture and walking activity scores of each pig are given in Figure 9. Pig 5 was more active than the other pigs, whereas Pig 3 was inactive most of the time.

3.4. Pig-Activity Detection and Tracking Model Performance

The YOLO model was trained for 500 epochs, whereas the Faster R-CNN model was trained for 50,000 iterations and saved with trained weights. Then, the model performance was assessed comprehensively using a toolkit implemented in the object detection metrics analysis [46]. The overall and class-wise average precision and recall obtained from the two models are shown in Figure 10. The YOLO model gave balance accuracy metrics (Figure 10a) compared to the Faster R-CNN model, which produced the highest accuracies for lateral lying posture detection and least for standing posture (Figure 10b). The APs of the Faster R-CNN model for the lateral lying, sternal lying, and standing postures were 97.21%, 96.83%, and 95.23%, respectively, with an overall mAP of 96.42% at 0.5 IoU. In comparison, the YOLO model provided 98.52%, 98.33%, and 99.18% accuracies for lateral lying, sternal lying, and standing postures, respectively, with an overall mAP of 98.67% at 0.5 IoU. Figure 11 shows the example frames of pig posture detection in different scenarios. The detection confidence of the Faster R-CNN model was higher for the sparsely located pigs. However, it declines with the increase in pig congestion and occlusion occurrence. Whereas the YOLO model produced balanced detection confidence in all scenarios, providing better precision and recall values. The Faster R-CNN model provided some false positive detections for standing and sternal lying postures, reducing the precision score, as shown in Figure 10b. The posture dections by the models for a sample video is provided as supplementary files. Similarly, the time taken by the YOLO model was 0.0314 s per image compared to 0.15 s per image of the Faster R-CNN model. The models’ detection speed was calculated by averaging the time taken to detect 30 min video frames.
Our proposed model works on tracking by detection strategy. The pig location in the frame was detected by the YOLO model with the corresponding pig posture. Then, the tracking algorithm assigned a virtual ID to the detected pig and tracked it throughout the frames in a video clip. Therefore, the accuracy of the tracking algorithm also depends upon the accuracy of the detection algorithm. In this study, the YOLOv4 produced good detection accuracy (98.67%), resulting in a good tracking accuracy of MOTA 93.13% and MOTP 81.23%. Some example frames after implementing the tracking algorithm are shown in Figure 12. Sample videos of pig posture detection from the YOLO model [Video S1], from the Faster R-CNN model [Video S2], and the tracking algorithm [Video S3] have been provided as supplementary files.

4. Discussion

Although the pig posture detection accuracy of the model is impressive, this study has some limitations. In this section, we discuss those limitations with the inference of the results. The first limitation is the pen environment. A big-sized feeder structure obstructed capturing all the pigs throughout the study period, especially those who stayed inside the feeder. Figure 13 shows the number of frames with the different numbers of visible pigs. Not all pigs were visible throughout the study period; nonetheless, the majority of pigs were visible in most of the video frames. This might be the one reason for getting a higher standard deviation while analyzing the group-wise activity (Figure 7). The second limitation was the manual system for gas sample collection and treatment application, which disturbed the natural activity of pigs for a while. Therefore, the video frames (10 min after the human entrance) were not considered for the activity analysis. In addition, the treatment duration (1 h) was set empirically. However, further research is recommended to identify the minimum duration and GHG concentration required for the pig to feel discomfort.
Even though there was no spatial variation in the GHGs in the livestock barn [47], we took three air samples from three spatial locations near the center of the pig barn each time and averaged them, as shown in Figure 1. The acquisition of GHG values using the air sampling method collects the air samples near the center of the barn. Dong et al. [47] collected air samples from three pen sections near the middle area of each pen. The space of two pens had an equal size of 4 m × 7 m each, and the third one had 8 m × 8 m. Likewise, Ni et al. [48] chose the one-one location for each pen near the exhaust fan (1 m from central exhaust fan) and one at the center of the aisle in the large pig barn of size 61.0 m × 13.2 m. Compared to those pig barns, our pig barn was small in size (5.4 m × 3.4 m), and we have collected three gas samples from three different locations and averaged them so that the GHG values would be more reliable. Dong et al. [47] reported that the GHG concentration profile in the pig barn has diurnal variations. A similar pattern was observed in our pig barn, with the concentration being higher in the nighttime and lower in the daytime. All the GHG concentrations displayed almost a similar pattern. The GHG concentrations in the morning were high because of the reduced ventilation at low temperatures during the nighttime, resulting in highly concentrated GHGs. CO2 gas was found in considerably higher concentrations than other GHGs. Previous research has also reported that CO2 and CH4 are the major GHGs produced in the pig barn, and their concentrations are highly correlated with farm management systems [47,48]. CO2 mainly occurs from pig respiration, with some from manure, and CH4 comes from the fermentation of pig waste. Our pig barn was equipped with a shallow manure-flushing system, which was flushed every week, which might be the reason for there being less CH4 concentration compared to other GHGs, as Moller et al. [49] found that the CH4 emissions from pig waste is dependent on the storage time. The GHGs were increased by more than 100%, with the turning off of the ventilation system for an hour. Thus, poor farm handling may produce a severe level of GHGs inside the pig barn causing stress on the pig.
CO2 is a commonly used GHG for stunning the pigs before slaughter. Recently, some research on N2O and N2 gases has been carried out as a substitute or a supplementary of CO2. However, CO2 and N2O with various other hazardous gases are produced naturally in the animal house, and the concentration of emissions largely depends on the farm management practices. We have developed a model to identify the pigs’ response to elevated GHG concentrations. Verhoeven et al. [15] reported that the increase in CO2 concentration decreases the sitting and lying latency, increasing their durations. Nevertheless, there was no significant difference in walking activity. Similar behavioral responses were observed in this study, except for walking activity, which might be due to the difference in CO2 concentration and exposure method. There is still a debate on the amount of CO2 concentrations required to create aversion to pig since it responds differently in different studies. Nevertheless, more than 30% of CO2 inhalation by volume in air and 15 to 30% of CO2 in nitrogen atmosphere causes aversion to pig [50]. In the case of humans, CO2 of more than 1000 ppm shows disturbance on cognitive performances, and above 3000 ppm significantly increases headache, sleepiness, and exhaustion [51]. When a higher amount of CO2 is inhaled, it spreads on the blood, reducing the pH level since it is mildly acidic, resulting in a state of hypercapnic hypoxia. Therefore, pigs became more inactive at higher concentrations of GHGs. Also, the CO2 is a strong respiratory stimulator, showing the gasping and hyperventilation activities on the pig [15]. A pig ethogram is an essential parameter for monitoring its health and welfare. Alameer et al. [8] found a decrease in standing activity in response to a certain level of food stress, which increased sharply when the stress increased. However, the lateral lying activity increased sharply even under initial food stress and decreased gradually with the increase in food stress, but overall, it was higher in stress conditions. However, the sternal lying activity changed remarkably with severe food stress only. The pigs showed similar behavior in the GHG stress as well. The standing, walking, and sternal lying decreased with the increase in GHGs in contrast to lying laterally for a longer time. Moreover, with the increase in GHGs, the pigs might feel difficulty in breathing, causing stress on the pigs. Stress on the pigs also increases their body temperature [52], and hence the pigs are likely to stay in the lateral-lying position [53]. Therefore, monitoring the pigs’ ethogram using a camera would be pertinent in identifying the pigs’ welfare. Furthermore, the individual monitoring and tracking of the pig will provide essential information for identifying each pig’s health and welfare conditions. For instance, Pig number 5 was found the most active pig, and pig number 3 was the most inactive.
As we used an automatic posture detection and tracking model to observe changes in the pigs’ behavior, the reliability of the posture observation is inevitably dependent on model performance. Our model produced an excellent detection result (mAP: 98.67%), which is better than [3,24] and similar to [8]. The higher detection accuracy might be due to the latest model, lower pig population, clean pen environment, enough lighting, single pig breed, and clear and large pig body. Similar to [8,24], the AP of the Faster R-CNN model for the lateral-lying class was the highest among the postures, whereas the AP for the standing class was the lowest, as shown in Figure 8b. However, the YOLO model provided balanced APs for all classes of pig posture (relatively higher for standing posture and the lowest for sternal lying posture). Implementation of an SPP network in the neck block improved the detection accuracy of the model, even for some deformed object shapes. For the top-view images, sometimes, the standing pig looked similar to a sternal-lying pig [24]; thus, the models got higher false positives and false negatives, reducing the APs of those classes. However, the YOLO model showed a robust performance on all posture detections. Additionally, models’ classification and localization confidence decreased in huddled and posture transitional scenes, which should be improved in the future. However, the model performed satisfactorily in all the posture classes, which is inspiring for its implementation in pig posture detection. To our knowledge, this is the first study on pig behavior measurement using deep-learning networks under various GHG concentrations. Also, this study focuses only on the short-term effect of GHG concentrations on pig behavior. Therefore, further research is recommended to identify the long-term impact on pig growth performance.

5. Conclusions

The posture and locomotion activity of pigs is a vital indicator for health and the monitoring of well-being. We developed a deep-learning-based automatic algorithm utilizing the computer vision system for measuring the changes in such behaviors under a compromised breeding environment. Two widely used object detection models (YOLOv4 and Faster R-CNN) were implemented and adopted the YOLO model due to its fast and accurate detection. We observed the changes in pig posture both group-wise and individually at the different concentrations of GHGs that occurred naturally in an experimental pig barn. The detection model performed remarkably with mAP of 96.42%, and the tracking algorithm provided a MOTA and MOTP of 93.13% and 81.23%, respectively. The tracking algorithm allowed to find out the individual pig-activity profiles during the study period.
Even though we did not find previous research regarding the influence of GHG concentrations on pig behavior changes, our study showed significant differences in pig posture activities. Standing, walking, and sternal lying activities were inversely correlated with the GHG concentrations, whereas lateral lying showed a positive correlation. However, there needs to be further experiments to determine the impact of GHGs on pigs’ health and growth.

Supplementary Materials

The following are available online at https://drive.google.com/file/d/1DmkR5AyysQkFbMEwjPjJnnNVyGvtsu9H/view, Video S1. Sample video of pig posture detection from the YOLO model; Video S2. Sample video of pig posture detection from the Faster R-CNN model; Video S3. Sample video of pig tracking; Code. Pig tracking by detection algorithm code; Datasets. Labeled testing datasets; Result: Pig posture detected and tracking results.

Author Contributions

Conceptualization, experimental design, experiment, coding, and writing paper, A.B.; assistance in resource management, E.A. and B.-E.M.; and supervision, H.-T.K. All authors have read and agreed to the published version of the manuscript.

Funding

This work was supported by the Korea Institute of Planning and Evaluation for Technology in Food, Agriculture, Forestry and Fisheries (IPET) through the Agriculture, Food and Rural Affairs Convergence Technologies Program for Educating Creative Global Leader, funded by the Ministry of Agriculture, Food and Rural Affairs (MAFRA) (717001-7).

Institutional Review Board Statement

The current research was conducted at the smart farm research center of Gyeongsang National University. The Institutional Animal Care and Use Committee (IACU) (GNU-150508-R0029) approved the experimental procedure and collection of data.

Data Availability Statement

The code, algorithm, and testing datasets are provided as Supplementary Materials.

Conflicts of Interest

On behalf of all the authors, the corresponding author declares that there is no conflict of interest.

References

  1. Czycholl, I.; Büttner, K.; grosse Beilage, E.; Krieter, J. Review of the assessment of animal welfare with special emphasis on the Welfare Quality® animal welfare assessment protocol for growing pigs. Arch. Anim. Breed. 2015, 58, 237–249. [Google Scholar] [CrossRef] [Green Version]
  2. Matthews, S.G.; Miller, A.L.; Clapp, J.; Plötz, T.; Kyriazakis, I. Early detection of health and welfare compromises through automated detection of behavioural changes in pigs. Vet. J. 2016, 217, 43–51. [Google Scholar] [CrossRef] [Green Version]
  3. Cowton, J.; Kyriazakis, I.; Bacardit, J. Automated Individual Pig Localisation, Tracking and Behaviour Metric Extraction Using Deep Learning. IEEE Access 2019, 7, 108049–108060. [Google Scholar] [CrossRef]
  4. Villain, A.S.; Lanthony, M.; Guérin, C.; Tallet, C. Manipulable Object and Human Contact: Preference and Modulation of Emotional States in Weaned Pigs. Front. Vet. Sci. 2020, 7, 577433. [Google Scholar] [CrossRef]
  5. Leruste, H.; Bokkers, E.A.; Sergent, O.; Wolthuis-Fillerup, M.; van Reenen, C.G.; Lensink, B.J. Effects of the observation method (direct v. From video) and of the presence of an observer on behavioural results in veal calves. Animal 2013, 7, 1858–1864. [Google Scholar] [CrossRef] [PubMed]
  6. Rostagno, M.H.; Eicher, S.D.; Lay, D.C., Jr. Immunological, physiological, and behavioral effects of salmonella enterica carriage and shedding in experimentally infected finishing pigs. Foodborne Pathog. Dis. 2011, 8, 623–630. [Google Scholar] [CrossRef] [PubMed]
  7. Huynh, T.T.T.; Aarnink, A.J.A.; Gerrits, W.J.J.; Heetkamp, M.J.H.; Canh, T.T.; Spoolder, H.A.M.; Kemp, B.; Verstegen, M.W.A. Thermal behaviour of growing pigs in response to high temperature and humidity. Appl. Anim. Behav. Sci. 2005, 19, 1–16. [Google Scholar] [CrossRef]
  8. Alameer, A.; Kyriazakis, I.; Bacardit, J. Automated recognition of postures and drinking behaviour for the detection of compromised health in pigs. Sci. Rep. 2020, 10, 13665. [Google Scholar] [CrossRef] [PubMed]
  9. Benjamin, M.; Yik, S. Precision Livestock Farming in Swine Welfare: A Review for Swine Practitioners. Animals 2019, 9, 133. [Google Scholar] [CrossRef] [Green Version]
  10. Diana, A.; Carpentier, L.; Piette, D.; Boyle, L.A.; Berckmans, D.; Norton, T. An ethogram of biter and bitten pigs during an ear biting event: First step in the development of a Precision Livestock Farming tool. App. Anim. Behav. Sci. 2019, 215, 26–36. [Google Scholar] [CrossRef]
  11. MacLeod, M.; Gerber, P.; Mottet, A.; Tempio, G.; Falcucci, A.; Opio, C.; Vellinga, T.; Henderson, B.; Steinfeld, H. Greenhouse Gas Emissions from Pig and Chicken Supply Chains–A Global Life Cycle Assessment; Food and Agriculture Organization of the United Nations (FAO): Rome, Italy, 2013; Available online: http://www.fao.org/3/i3460e/i3460e.pdf (accessed on 4 March 2021).
  12. Çavuşoğlu, E.; Rault, J.-L.; Gates, R.; Lay, D.C., Jr. Behavioral Response of Weaned Pigs during Gas Euthanasia with CO2, CO2 with Butorphanol, or Nitrous Oxide. Animals 2020, 10, 787. [Google Scholar] [CrossRef]
  13. Atkinson, S.; Algers, B.; Pallisera, J.; Velarde, A.; Llonch, P. Animal Welfare and Meat Quality Assessment in Gas Stunning during Commercial Slaughter of Pigs Using Hypercapnic-Hypoxia (20% CO2 2% O2) Compared to Acute Hypercapnia (90% CO2 in Air). Animals 2020, 10, 2440. [Google Scholar] [CrossRef] [PubMed]
  14. Lindahl, C.; Sindhøj, E.; Brattlund Hellgren, R.; Berg, C.; Wallenbeck, A. Responses of Pigs to Stunning with Nitrogen Filled High-Expansion Foam. Animals 2020, 10, 2210. [Google Scholar] [CrossRef]
  15. Verhoeven, M.; Gerritzen, M.; Velarde, A.; Hellebrekers, L.; Kemp, B. Time to Loss of Consciousness and Its Relation to Behavior in Slaughter Pigs during Stunning with 80 or 95% Carbon Dioxide. Front Vet. Sci. 2016, 3, 38. [Google Scholar] [CrossRef] [Green Version]
  16. Sejian, V.; Bhatta, R.; Malik, K.; Madiajagan, B.; Al-Hosni, Y.A.S.; Sullivan, M.; Gaughan, J.B. Livestock as Sources of Greenhouse Gases and Its Significance to Climate Change. In Greenhouse Gases; Llamas, B., Pous, J., Eds.; IntechOpen: London, UK, 2016; pp. 243–259. [Google Scholar]
  17. Nasirahmadi, A.; Edwardsa, S.A.; Sturm, B. Implementation of machine vision for detecting behaviour of cattle and pigs. Livest. Sci. 2017, 202, 25–38. [Google Scholar] [CrossRef] [Green Version]
  18. Nasirahmadi, A.; Hensel, O.; Edwards, S.A.; Sturm, B. Automatic detection of mounting behaviours among pigs using image analysis. Comput. Electron. Agric. 2016, 124, 295–302. [Google Scholar] [CrossRef] [Green Version]
  19. Nasirahmadi, A.; Sturm, B.; Olsson, A.C.; Jeppsson, K.H.; Müller, S.; Edwards, S.; Hensel, O. Automatic scoring of lateral and sternal lying posture in grouped pigs using image processing and Support Vector Machine. Comput. Electron. Agric. 2019, 156, 475–481. [Google Scholar] [CrossRef]
  20. Nasirahmadi, A.; Richter, U.; Hensel, O.; Edwards, S.; Sturm, B. Using machine vision for investigation of changes in pig group lying patterns. Comput. Electron. Agric. 2015, 119, 184–190. [Google Scholar] [CrossRef] [Green Version]
  21. Matthews, S.G.; Miller, A.L.; Plötz, T.; Kyriazakis, I. Automated tracking to measure behavioural changes in pigs for health and welfare monitoring. Sci. Rep. 2017, 7, 17582. [Google Scholar] [CrossRef]
  22. Zhang, L.; Gray, H.; Ye, X.; Collins, L.; Allinson, N. Automatic Individual Pig Detection and Tracking in Pig Farms. Sensors 2019, 19, 1188. [Google Scholar] [CrossRef] [Green Version]
  23. Liu, D.; Oczak, M.; Maschat, K.; Baumgartner, J.; Pletzer, B.; He, D.; Norton, T. A computer vision-based method for spatial-temporal action recognition of tail-biting behavior in group-housed pigs. Biosyst. Eng. 2020, 195, 27–41. [Google Scholar] [CrossRef]
  24. Nasirahmadi, A.; Sturm, B.; Edwards, S.; Jeppsson, K.-H.; Olsson, A.-C.; Müller, S.; Hensel, O. Deep Learning and Machine Vision Approaches for Posture Detection of Individual Pigs. Sensors 2019, 19, 3738. [Google Scholar] [CrossRef] [Green Version]
  25. Yang, A.; Huang, H.; Zhu, X.; Yang, X.; Chen, P.; Li, S.; Xue, Y. Automatic recognition of sow nursing behavior using deep learning-based segmentation and spatial and temporal features. Biosyst. Eng. 2018, 175, 133–145. [Google Scholar] [CrossRef]
  26. Riekert, M.; Klein, A.; Adrion, F.; Hoffmann, C.; Gallmann, E. Automatically detecting pig position and posture by 2D camera imaging and deep learning. Comput. Electron. Agric. 2020, 174, 105391. [Google Scholar] [CrossRef]
  27. Moon, B.E.; Lee, M.H.; Kim, H.T.; Choi, T.H.; Kim, Y.B.; Ryou, Y.S.; Kim, H.T. Evaluation of thermal performance through development of an unglazed transpired collector control system in experimental pig barns. Sol. Energy 2017, 157, 201–215. [Google Scholar] [CrossRef]
  28. Basak, J.K.; Okyere, F.G.; Arulmozhi, A.; Park, J.; Khan, F.; Kim, H.T. Artificial neural networks and multiple linear regressionas potential methods for modelling body surface temperature of pig. J. Appl. Anim. Res. 2020, 48, 207–219. [Google Scholar] [CrossRef]
  29. Kim, K.H.; Kim, K.S.; Kim, J.E.; Kim, D.W.; Seol, K.H.; Lee, S.H.; Chase, B.J.; Kim, K.H. The effect of optimal space allowance on growth performance and physiological responses of pigs at different stages of growth. Animal 2017, 11, 478–485. [Google Scholar] [CrossRef]
  30. Sander, B.O.; Wassmann, R. Common practices for manual greenhouse gas sampling in rice production: A literature study on sampling modalities of the closed chamber method. Greenh. Gas. Meas. Manag. 2014, 4, 1–13. [Google Scholar] [CrossRef]
  31. Hikvisionapi 0.2.1. Available online: https://pypi.org/project/hikvisionapi/ (accessed on 14 June 2020).
  32. Zauner, C.; Steinebach, M.; Hermann, E. Rihamark: Perceptual image hash benchmarking. In Proceedings of the SPIE 7880, Media Watermarking, Security, and Forensics III, San Francisco, CA, USA, 10 February 2011. [Google Scholar]
  33. Sekachev, B.; Manovich, N.; Zhiltsov, M.; Zhavoronkov, A.; Kalinin, D.; Hoff, D.; Tosmanov; Kruchinin, D.; Zankevich, A.; Sidnev, D.; et al. OpenCV/CVAT: v1.1.0. Available online: https://cvat.org (accessed on 12 November 2020).
  34. VOC2010 Annotation Guidelines. Available online: http://host.robots.ox.ac.uk/pascal/VOC/voc2010/guidelines.html (accessed on 12 November 2020).
  35. Bochkovskiy, A.; Wang, C.Y.; Liao, H.Y.M. YOLOv4: Optimal speed and accuracy of object detection. arXiv 2020, arXiv:2004.10934v1. Available online: https://arxiv.org/pdf/2004.10934.pdf (accessed on 16 September 2021).
  36. Redmon, J.; Farhadi, A. YOLOv3: An incremental improvement. arXiv 2018, arXiv:1804.02767. Available online: https://arxiv.org/pdf/1804.02767.pdf (accessed on 16 September 2021).
  37. Lin, T.Y.; Maire, M.; Belongie, S.; Hays, J.; Perona, P.; Ramanan, D.; Dollár, P.; Zitnick, C.L. Microsoft COCO: Common Objects in Context. In Proceedings of the European Conference on Computer Vision, Zurich, Switzerland, 6–12 September 2014; Fleet, D., Pajdla, T., Schiele, B., Tuytelaars, T., Eds.; Computer Vision–ECCV 2014. Springer: Cham, Germany; pp. 740–755. [Google Scholar]
  38. TensorFlow2 Detection Model Zoo. Available online: https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md (accessed on 15 February 2021).
  39. Ren, S.; He, K.; Girshick, R.; Sun, J. Faster R-CNN: Towards real-time object detection with region proposal networks. IEEE Trans. 2016, 39, 1137–1149. [Google Scholar] [CrossRef] [Green Version]
  40. Girshick, R. Fast R-CNN. In Proceedings of the IEEE International Conference on Computer Vision, Washington, DC, USA, 13–16 December 2015; pp. 1440–1448. [Google Scholar]
  41. Wojke, N.; Bewley, A.; Paulus, D. Simple online and real-time tracking with a deep association metric. In Proceedings of the IEEE International Conference on Image Processing (ICIP), Beijing, China, 17–20 September 2017; pp. 3645–3649. [Google Scholar]
  42. Kuhn, H.W. The Hungarian method for the assignment problem. Naval. Res. Logist. Q. 1955, 2, 83–97. [Google Scholar] [CrossRef] [Green Version]
  43. Kalman, R.E. A new approach to linear filtering and prediction problems. Trans. ASME J. Basic. Eng. 1960, 82, 35–45. [Google Scholar] [CrossRef] [Green Version]
  44. Forst, W.; Hoffmann, D. Optimization—Theory and Practice; Springer: Berlin/Heidelberg, Germany, 2010. [Google Scholar]
  45. Milan, A.; Leal-Taixé, L.; Reid, I.; Roth, S.; Schindler, K. Mot16: A benchmark for multi-object tracking. arXiv 2016, arXiv:1603.00831. [Google Scholar]
  46. Padilla, R.; Passos, W.L.; Dias, T.L.B.; Netto, S.L.; da Silva, E.A.B. A Comparative Analysis of Object Detection Metrics with a Companion Open-Source Toolkit. Electronics 2021, 10, 279. [Google Scholar] [CrossRef]
  47. Dong, H.; Kang, G.; Zhu, Z.; Tao, X.; Chen, Y. Ammonia, Methane, and Carbon Dioxide Concentrations and Emissions of a Hoop Grower-Finisher Swine Barn. Trans. ASABE 2008, 52, 1741–1747. [Google Scholar] [CrossRef]
  48. Ni, J.Q.; Heber, A.J.; Lim, T.T.; Tao, P.C.; Schmidt, A.M. Methane and carbon dioxide emission from two pig finishing barns. J. Env. Qual. 2008, 37, 2001–2011. [Google Scholar] [CrossRef] [PubMed]
  49. Moller, H.B.; Sommer, S.G.; Ahring, B.K. Biological degradation and greenhouse gas emissions during pre-storage of liquid animal manure. J. Env. Qual. 2004, 33, 27–36. [Google Scholar] [CrossRef]
  50. Lionch, P.; Dalmau, A.; Rodriguez, P.; Manteca, X.; Velarde, A. Aversion to nitrogen and carbon dioxide mixtures for stunning pigs. Anim. Welf. 2012, 21, 33–39. [Google Scholar] [CrossRef]
  51. Azuma, K.; Kagi, N.; Yanagi, U.; Osawa, H. Effects of low-level inhalation exposure to carbon dioxide in indoor environments: A short review on human health and psychomotor performance. Env. Int. 2018, 121, 51–56. [Google Scholar] [CrossRef]
  52. Ruis, M.A.; Brake, J.H.; Engel, B.; Buist, W.G.; Blokhuis, H.J.; Koolhaas, J.M. Adaptation to social isolation. Acute and long-term stress responses of growing gilts with different coping characteristics. Physiol. Behav. 2001, 73, 541–551. [Google Scholar] [CrossRef] [Green Version]
  53. Nasirahmadi, A.; Hensel, O.; Edwards, S.A.; Sturm, B. A new approach for categorizing pig lying behaviour based on a Delaunay triangulation method. Animal 2017, 11, 131–139. [Google Scholar] [CrossRef] [PubMed] [Green Version]
Figure 1. Experimental setup in the pig barn: (a) camera setup for capturing the top-view video frames and (b) covering of pig barn gas inlet and outlet to elevate the GHGs concentration.
Figure 1. Experimental setup in the pig barn: (a) camera setup for capturing the top-view video frames and (b) covering of pig barn gas inlet and outlet to elevate the GHGs concentration.
Animals 11 03089 g001
Figure 2. Complete steps of proposed methodology. The pig postures are identified and localized by using a deep-learning object detection model, then the simple online real-time tracking with deep association (Deep-SORT) algorithm tracks each pig by associating the corresponding detected posture, and, finally, the detected pigs’ postures with time information are analyzed to score the posture activity occurring in an hour. All the modules are integrated to provide an end-to-end posture scoring.
Figure 2. Complete steps of proposed methodology. The pig postures are identified and localized by using a deep-learning object detection model, then the simple online real-time tracking with deep association (Deep-SORT) algorithm tracks each pig by associating the corresponding detected posture, and, finally, the detected pigs’ postures with time information are analyzed to score the posture activity occurring in an hour. All the modules are integrated to provide an end-to-end posture scoring.
Animals 11 03089 g002
Figure 3. YOLOv4 network architecture.
Figure 3. YOLOv4 network architecture.
Animals 11 03089 g003
Figure 4. Architecture of Faster R-CNN.
Figure 4. Architecture of Faster R-CNN.
Animals 11 03089 g004
Figure 5. Pig-tracking algorithm adopted in Deep-SORT. A virtual ID is assigned to each detected pig in the first frame, and the IDs are given to the respective pigs based on the matching IoU in the subsequent frames.
Figure 5. Pig-tracking algorithm adopted in Deep-SORT. A virtual ID is assigned to each detected pig in the first frame, and the IDs are given to the respective pigs based on the matching IoU in the subsequent frames.
Animals 11 03089 g005
Figure 6. Average greenhouse gas (GHG) concentrations before, during, and after an hour of treatment. The x-axis represents the time (hh:mm) of day, whereas the left y-axis represents the average CO2 concentration, and the right y-axis represents the average CO, NO, CH4, and N2O.
Figure 6. Average greenhouse gas (GHG) concentrations before, during, and after an hour of treatment. The x-axis represents the time (hh:mm) of day, whereas the left y-axis represents the average CO2 concentration, and the right y-axis represents the average CO, NO, CH4, and N2O.
Animals 11 03089 g006
Figure 7. Group-wise average posture and walking frame scores of pigs: (a) standing score, (b) walking score, (c) sternal-lying score, and (d) lateral-lying score. The scores show the average number of pigs in a frame with a particular posture. The bars represent the average activity scores obtained in three days at an hour before, during, and after the treatment period in the morning, day, and nighttime.
Figure 7. Group-wise average posture and walking frame scores of pigs: (a) standing score, (b) walking score, (c) sternal-lying score, and (d) lateral-lying score. The scores show the average number of pigs in a frame with a particular posture. The bars represent the average activity scores obtained in three days at an hour before, during, and after the treatment period in the morning, day, and nighttime.
Animals 11 03089 g007aAnimals 11 03089 g007b
Figure 8. Total distance traveled by the pigs in group and the day 1-morning time locomotion activities: (a) the total distance traveled by all pigs during the study period, (b) locomotion of the group pigs before treatment in the morning of day 1, (c) during the treatment, and (d) after the treatment.
Figure 8. Total distance traveled by the pigs in group and the day 1-morning time locomotion activities: (a) the total distance traveled by all pigs during the study period, (b) locomotion of the group pigs before treatment in the morning of day 1, (c) during the treatment, and (d) after the treatment.
Animals 11 03089 g008aAnimals 11 03089 g008b
Figure 9. Posture and walking activity score profiles of individual pigs during the study period.
Figure 9. Posture and walking activity score profiles of individual pigs during the study period.
Animals 11 03089 g009
Figure 10. Class-wise and overall precision-recall evaluation metrics of the model: (a) YOLOv4 model and (b) Faster R-CNN model.
Figure 10. Class-wise and overall precision-recall evaluation metrics of the model: (a) YOLOv4 model and (b) Faster R-CNN model.
Animals 11 03089 g010
Figure 11. Sample of pig posture detection under various conditions by two models: (ac) by YOLOv4 model for the frame having sparsely located pigs, frame having densely located pigs, and the frame having occlusion, respectively, and (df) by Faster R-CNN model for the same frames applied in the YOLOv4 model.
Figure 11. Sample of pig posture detection under various conditions by two models: (ac) by YOLOv4 model for the frame having sparsely located pigs, frame having densely located pigs, and the frame having occlusion, respectively, and (df) by Faster R-CNN model for the same frames applied in the YOLOv4 model.
Animals 11 03089 g011aAnimals 11 03089 g011b
Figure 12. Sample of tracked frames by the tracking algorithm: (a) the first frame, (b) the 150th frame as Pig 5 is moving, and (c) the 300th frame where Pig 5 has changed its posture from standing to sternal lying.
Figure 12. Sample of tracked frames by the tracking algorithm: (a) the first frame, (b) the 150th frame as Pig 5 is moving, and (c) the 300th frame where Pig 5 has changed its posture from standing to sternal lying.
Animals 11 03089 g012
Figure 13. Number of frames vs. number of visible pigs during the study period.
Figure 13. Number of frames vs. number of visible pigs during the study period.
Animals 11 03089 g013
Table 1. Pig posture categories and their convention used to classify them in human annotation.
Table 1. Pig posture categories and their convention used to classify them in human annotation.
Pig Posture and LabelIdentification ConventionInstances
Standing pig (standing_pig)Only feet or feet and snout in contact with the floor 10,124
Sternal lying pig (sl_pig) Belly and folded limbs in contact with the floor 9364
Lateral lying pig (ll_pig)Side trunk and extended limbs in contact with the ground 10,745
Table 2. Hyperparameters selected for the training of the YOLOv4 model.
Table 2. Hyperparameters selected for the training of the YOLOv4 model.
HyperparameterValue
Learning rate0.001
Epochs 500
Optimizer Adam
Batch size 2
Subdivisions 1
Activation Mish
Input image size[640, 640, 3]
Data augmentationHorizontal and vertical flip, Rotations by 90°, 180°, and 270°, and mosaic augmentation
Table 3. Hyperparameters selected for the training of the Faster R-CNN model.
Table 3. Hyperparameters selected for the training of the Faster R-CNN model.
HyperparameterValue
Learning rate0.004
Iteration 50,000
Warmup learning rate0.0013333
Momentum 0.9
Batch size2
Score converterSoftmax
Input image size[640, 640, 3]
Data augmentationHorizontal and vertical flip; Rotations by 90°, 180°, and 270°
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Share and Cite

MDPI and ACS Style

Bhujel, A.; Arulmozhi, E.; Moon, B.-E.; Kim, H.-T. Deep-Learning-Based Automatic Monitoring of Pigs’ Physico-Temporal Activities at Different Greenhouse Gas Concentrations. Animals 2021, 11, 3089. https://doi.org/10.3390/ani11113089

AMA Style

Bhujel A, Arulmozhi E, Moon B-E, Kim H-T. Deep-Learning-Based Automatic Monitoring of Pigs’ Physico-Temporal Activities at Different Greenhouse Gas Concentrations. Animals. 2021; 11(11):3089. https://doi.org/10.3390/ani11113089

Chicago/Turabian Style

Bhujel, Anil, Elanchezhian Arulmozhi, Byeong-Eun Moon, and Hyeon-Tae Kim. 2021. "Deep-Learning-Based Automatic Monitoring of Pigs’ Physico-Temporal Activities at Different Greenhouse Gas Concentrations" Animals 11, no. 11: 3089. https://doi.org/10.3390/ani11113089

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop