Next Article in Journal
Bovine C-X-C Motif Chemokine Ligand 14 Expression Is Regulated by Alternative Polyadenylation and MicroRNAs
Previous Article in Journal
Efficacy of Edible and Leisure Reinforcers with Domestic Dogs
Previous Article in Special Issue
Opportunities for Regulatory Authorities to Assess Animal-Based Measures at the Slaughterhouse Using Sensor Technology and Artificial Intelligence: A Review
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Detection of Pig Movement and Aggression Using Deep Learning Approaches

State Key Laboratory for Pig Genetic Improvement and Production Technology, Jiangxi Agricultural University, Nanchang 330045, China
*
Author to whom correspondence should be addressed.
Animals 2023, 13(19), 3074; https://doi.org/10.3390/ani13193074
Submission received: 1 September 2023 / Revised: 25 September 2023 / Accepted: 29 September 2023 / Published: 30 September 2023

Abstract

:

Simple Summary

In this study, a deep learning-based detection and identification method is proposed to detect and identify the movement duration and aggressive behavior of pigs under on-farm conditions by using computer vision technology and electronic identity cards. The performance of different target detection algorithms for individual pig and aggressive behavior detection is also evaluated. The aim of this study is to establish an automated system for detecting pig aggressive behavior and energy expenditure, which may be able to provide reliable data and technical support for the study of the social hierarchy of pigs, as well as the selection and breeding of pig health and aggression phenotypes.

Abstract

Motion and aggressive behaviors in pigs provide important information for the study of social hierarchies in pigs and can be used as a selection indicator for pig health and aggression parameters. However, relying only on visual observation or surveillance video to record the number of aggressive acts is time-consuming, labor-intensive, and lasts for only a short period of time. Manual observation is too short compared to the growth cycle of pigs, and complete recording is impractical in large farms. In addition, due to the complex process of assessing the intensity of pig aggression, manual recording is highly influenced by human subjective vision. In order to efficiently record pig motion and aggressive behaviors as parameters for breeding selection and behavioral studies, the videos and pictures were collected from typical commercial farms, with each unit including 8~20 pigs in 7~25 m2 space; they were bred in stable social groups and a video was set up to record the whole day’s activities. We proposed a deep learning-based recognition method for detecting and recognizing the movement and aggressive behaviors of pigs by recording and annotating head-to-head tapping, head-to-body tapping, neck biting, body biting, and ear biting during fighting. The method uses an improved EMA-YOLOv8 model and a target tracking algorithm to assign a unique digital identity code to each pig, while efficiently recognizing and recording pig motion and aggressive behaviors and tracking them, thus providing statistics on the speed and duration of pig motion. On the test dataset, the average precision of the model was 96.4%, indicating that the model has high accuracy in detecting a pig’s identity and its fighting behaviors. The model detection results were highly correlated with the manual recording results (R2 of 0.9804 and 0.9856, respectively), indicating that the method has high accuracy and effectiveness. In summary, the method realized the detection and identification of motion duration and aggressive behavior of pigs under natural conditions, and provided reliable data and technical support for the study of the social hierarchy of pigs and the selection of pig health and aggression phenotypes.

1. Introduction

Feed costs typically account for about 60% of the total cost of meat hogs. In recent years, as feed prices have continued to rise, more and more hog farms have begun to use feed equipment to evaluate the return on feed for their hogs and to improve the feed utilization of hogs using optimal linear unbiased estimation or genomic selection breeding [1,2]. Each pig typically wears a tag with an RFID electronic ear tag, and feed measurement equipment recognizes these electronic ear tags to record information such as the time of entry, weight, and feed weight for each pig. Parameters such as feed intake, body weight, and entry/exit time allow traits such as feed intake time, number of feed intakes, feed intake per meal, and feed conversion efficiency to be obtained, but the behavior and movements of the pig outside of the measurement equipment cannot be monitored. Recording the pig’s movement behavior in the whole activity area can accurately assess its daily movement trend and physical condition, which helps to select and breed excellent breeds with low energy consumption more accurately. In addition, pigs are herd animals with a stable social hierarchy within them. In general, the social hierarchy of pigs is determined by the strengths and weaknesses of group members through fights between them, and unfamiliar piglets that meet after weaning will form a social order within 48~72 h after grouping [3,4,5]. Most studies have also focused on the 48~72 h period, but the occurrence of aggressive behaviors among pigs can be observed from time to time at times greater than 72 h. Little research has been conducted in this area. Monitoring pig aggression and fighting behavior can provide insight into the social order of the herd, and because aggression consumes more energy and is more likely to result in injury, the monitoring of pig fighting has also been emphasized.
In the pig industry, farms want to select pigs with fast growth and high health; however, health is affected by pathogens and the environment, and the health status of pigs can be grasped in real-time by recording their movement attributes every day, which provides extremely detailed data for high-quality breeding pig selection. At the same time, aggression between pigs can greatly affect pork production [6], including damage to the animal’s body surface, reduced body weight and poor meat quality, and even fatal injuries [7]. In addition, stress from aggression reduces the reproductive performance of surrounding sows [8], which has a huge impact on the economic efficiency of pig farming. Therefore, aggression is considered as one of the most important health, welfare, and economic problems in modern production systems [9,10]. Studies have shown that factors such as herd management, living environment, and genetic factors are determinants of pig aggression [11]. Nevertheless, an in-depth study of pig aggression and an understanding of the factors involved will help to promote the establishment of social hierarchies in herds and reduce the daily exposure to injuries and stress, creating maximum economic value.
Currently, the behavioral identification of pigs mainly relies on manual observation in pens or under surveillance video. However, it is obvious that these methods cannot be used for long-time observation, which is not only time-consuming and laborious, but also has many limitations. In recent years, many algorithms based on deep learning techniques [12] have been developed and successfully applied to object detection tasks. Many of these algorithms use convolutional neural networks (CNNs) such as YOLOv5 and Mask R-CNN. Deep learning-based computer vision techniques are able to extract image features better and accomplish more complex tasks than traditional image-processing methods. As a result, these techniques are widely used for various detection tasks in agriculture. For example, Li et al. used the improved YOLOv5 model to recognize and count corn seedlings in a complex background and achieved 90.66% precision [13]. Li et al. proposed a lightweight convolutional neural network-based cow recognition method to train and recognize side-view images of cows, and the final recognition rate reached 97.95% [14]. Shen et al. used the YOLO model to detect cow targets in a series of side-view images of cows, classify each cow by fine-tuning the convolutional neural network model, and achieve 96.65% precision in individual cow recognition [15]. Li et al. reviewed deep learning-based methods for classification, target detection, segmentation, pose estimation, and tracking of different species of animals such as cows, goats, pigs, and poultry [16]. Guo et al. have investigated three state-of-the-art automated multi-object tracking methods on two pig datasets; the experimental results of evaluation metrics demonstrate the effectiveness and robustness of the three proposed methods on multi-object tracking systems. FairMOT, with the proposed weighted-association strategy, achieves the best tracking performance for individual pigs in a real farm [17]. Zhang et al. proposed an automated multi-target detection and tracking method for individual pigs under daytime and nighttime conditions. Overall, the evaluation resulted in a precision of 94.72%, recall of 94.74%, and MOTA of 89.58%, which shows that our method can robustly detect and track multiple pigs under challenging conditions [18]. Wutke et al. proposed a framework for the automatic detection of social contacts. By applying keypoint-based body part detection and a subsequent pig tracking algorithm, they were able to determine the time, the animals involved, and the type of a social contact [19]. The above study shows that deep learning-based computer vision technology has a wide range of promising applications in agricultural science applications: for example, it can bring more possibilities in agricultural animal production. At present, the detection and recognition of movement characteristics and aggressive behaviors of pigs are still in the beginning stage of research, and there are relatively few related research reports. One of the main reasons is that the aggression of pigs is a complex interactive behavior and can last from a few seconds to a few minutes [20]. Another feature is that aggression does not just have one form of expression. It can appear as escalated fighting, unilateral biting, pushing, non-contact assessment, etc., and animals transition between these forms of aggression rapidly. Some of these are likely to be much easier to record using deep learning than others.
We found that the geometries and displacements of two pigs in an attacking state always remain attached or at a small distance from each other, although there are abrupt changes. Therefore, we can analyze the motion of the fighting pigs as a whole [21], and identify the attacking behavior of the pigs by the overall motion characteristics. In addition, the electronic ear tags in the feed determination equipment can be effectively captured by the RF equipment, and the ID of the pig coming out of the determination equipment can be directly given to the computerized image recognition system, thus realizing the identification of the pig in the case of target loss. Therefore, this study utilizes computer vision technology in combination with an electronic ID card, adopts the improved GAM-YOLOv8-based algorithm to detect pigs and aggression, and combines it with the tracking algorithm ByteTrack [22] to track and automatically record the movement duration and aggressive behavior of pigs. Finally, the detection model and recording method were evaluated and tested by using videos and images as a test set, aiming to build a system for the automated detection of pig aggressive behavior and energy consumption.

2. Materials and Methods

2.1. Data Acquisition and Pre-Processing Methods

The picture and video data analyzed in this study were mainly collected from the research pig farm of the State Key Laboratory for Pig Genetic Improvement and Production Technology, Jiangxi Agricultural University. We installed a camera 3 m from the ground for filming, with a display resolution of 1920 × 1080 pixels, including a 5 m × 5 m fence, a 2 m × 5 m pen, and a 2.1 × 3.6 m farrowing bed with a leaky manure board installed on the ground. Each unit included 8~20 pigs and some of them were not familiar with each other. A smartphone, with a display resolution of 1920 × 1080 pixels, was used to collect videos and images of the pigs in the farm from different angles. To ensure the diversity of the dataset, we also collected part of the data from the web (see https://www.bilibili.com/ (accessed on 3 February 2023) and https://aistudio.baidu.com/aistudio/datasetoverview (accessed on 3 February 2023) for links). When collecting data in the network, we chose videos with lower stocking densities and higher clarity as a next step because the lack of clarity and the fact that pigs live in dense environments are not conducive to labeling. The construction and processing of the dataset are shown in Figure 1. For each video in the detection dataset, we extracted an image at every 1-frame interval. The definition of pig aggression was determined by the behavioral processes of head-to-head knocking, head-to-body knocking, neck biting, body biting, and ear biting during fighting, as determined by morphological veterinary specialists. Additionally, we need to emphasize that we define aggression when there is an obvious fight between two parties, and that an obvious fight in this case does not include situations such as a pig biting an opponent and the opponent not retaliating. On this basis, we manually labeled the aggressive behaviors in consecutive frames using LabelImg software (v1.8.6.) to produce a reference dataset of pigs and their aggressive behaviors. Ultimately, we labeled 110,701 individual pigs and 14,836 pig attacks in 15,148 images. To evaluate the model accuracy, we divided all labeled images into three datasets according to the division in Figure 1 for training, validating, and testing the detection model. An example of the data processing flow and data enhancement is shown in Figure 2. During the training process, we applied data augmentation operations such as Pan, Rotate, Flip, Blur, Add Noise, Change Contrast, Random Scaling, Random Cropping, Mosaic, etc., to prevent the model from overfitting in order to improve the generalization ability of the model, and Mosiac augmentation was turned off in the last 10 epochs, which can effectively improve the accuracy.

2.2. Training for Individual Identification of Pigs

In this study, the YOLOv8 deep learning model was used for the detection of individual pigs. The initial model of YOLO had many successors, including YOLOv4, YOLOv5, YOLOv6, and YOLOv7. In 2023, YOLOv8 was released by Ultralytics [23]. YOLOv8 is the eighth generation version of the YOLO family of models, based on the latest advances in the field of deep learning and computer vision, and is recognized as the state of the art for its speed and accuracy, as it is the leading model of its kind. YOLOv8 contains five different configurations, YOLOv8n, YOLOv8s, YOLOv8m, YOLOv8l, and YOLOv8x, which gradually increase according to the depth and width of the network. The model backbone uses CSPDarknet53 [24], the head uses Decoupled Head, and the neck uses Path Aggregation Network (PANet network) [25] to maintain accuracy while realizing a lightweight design in line with advanced detection framework design concepts. In addition, it has been shown that incorporating visual attention mechanisms into deep learning models improves the recognition accuracy of small objects [26] and maintains high accuracy while being lightweight. Therefore, we introduced the multi-scale attention (EMA) module [27], the structure of which is shown in Figure 3. This module can effectively capture the information of different scales in the image, thus improving the performance of the model in multi-scale scenes. Figure 4 illustrates the structure of the improved version of EMA-YOLOV8n proposed in this study. In addition, we also use commonly used deep learning models such as Faster R-CNN, SSD, and YOLOv5 for pig-only individual recognition and attack behavior research. Faster R-CNN is an improved two-stage target detection algorithm, which has been widely used in tasks such as human pose recognition and target tracking [28]. SSD is a classical single-stage fast target detection model, which synthesizes the regression idea of YOLO and the anchor box mechanism of Faster R-CNN, and is able to achieve a good balance between detection accuracy and speed [29].

2.3. Tracking of Pig Motion

Dynamic objects are more difficult to track compared to static objects, especially when situations such as overlapping and occlusion occur. Compared to other tracking algorithms such as deep sort [30], ByteTrack shows significant advantages in occlusion situations.
ByteTrack is a tracking method based on the tracking-by-detection paradigm, which employs a simple and efficient data association method called BYTE. Compared with deep sort tracking algorithms, the biggest difference of ByteTrack is that instead of simply removing low-scoring detections, it utilizes the similarity between the detection frames and tracked trajectories to reduce missed detections and improve trajectory coherence. The similarity between the detection frame and the tracked trajectory, while retaining high-scoring detection results, mines the real objects (e.g., difficult samples such as occlusion and blurring) from the low-scoring detection results, thus reducing the leakage of detections and improving the consistency of the trajectory. The tracking effectiveness of the ByteTrack algorithm is heavily dependent on the accuracy of the recognition, i.e., if the detection is good, the tracking results will be improved, but if the detection is poor, the tracking results will be severely affected. Specifically, the flow of the BYTE data association method is as follows:
  • Separate the detection frames into high- and low-scoring frames based on the detection frame score.
  • The first time, the high score box is used to match the previous trace.
  • The second time, we use the low-scoring frame to match the track that did not match the high-scoring frame the first time (e.g., objects that were heavily occluded in the current frame that caused the score to drop).
  • Create a new track for frames that do not match the track but have a high enough score. Tracks that do not match a frame are kept for 30 frames and matched when they appear again.
In addition to this, the method uses Kalman filtering to predict the position of the tracking trajectory of the current frame in the next frame, and the IoU (Intersection over Union) between the predicted frames and the actually detected frames is used as the similarity between the two matches when the matching is carried out via the Hungarian algorithm. Figure 5 shows a schematic diagram demonstrating how the tracking system detects the pigs and uses the bounding box to track their positions. The IoU metric is used to measure the overlap between the predicted frames of the tracker and the detector, and is computed as shown in Equation (1), where SEMCN, SABCD, and SEFGH denote the areas of the rectangles in Figure 5, respectively.
IoU = s EMCN s ABCD + S EFGH S EMCN

2.4. Detection and Tracking of Aggressive Behavior and Movement Trajectories in Pigs

In actual production, each pig has a unique electronic ear number and can be recognized by feed determination equipment. During the tracking process, the ID of each pig obtained using video recognition is matched with the digital ID of its electronic ear tag, which facilitates the correspondence between the feeding phenotype and the pig’s ear number, and, at the same time, if the video recognition loses the target, the association can be re-established by the feed determination equipment. For each recognized pig, the corresponding digital ID, category, and coordinates of the detection frame in each frame are extracted, and the position of the center point of the detection frame is calculated. Then, lines are drawn between the center points of the detection frames with the same digital ID, and the distance between the current frame and the center point position of the previous frame is calculated based on the coordinates and accumulated to obtain the motion distance of the pig with the corresponding ID, as shown in Figure 6 and Supplementary Video S1.
When the pig attack behavior detection box appears, the current point in time is noted as T1; when the attack behavior detection box disappears, the current point in time is again noted as T2. Setting up the output of T1, T2, and the current ID number given to the background file realizes the recording of the time of the pig fights for the subsequent analysis of the pig’s behavior. Figure 7 shows the detection box of the attack behavior.

2.5. Model Training and Test Precision Evaluation

In order to evaluate the recognition and detection performance of the model, we evaluated the detection performance of the model in terms of precision, recall rate, mean average precision (mAP), and floating point operations (FLOPs) as per the following metrics:
P r e c i s i o n = T P T P + F P
R e c a l l = T P T P + F N
m A P = 1 n 0 1 P r e c i s o n ( R e c a l l ) d ( R e c a l l ) n
where TP, FP, and FN are the number of true positives, false positives, and false negatives, respectively. In Equation (4), AP is the area under the exact recall curve (P–R curve) and mAP is the average of different categories of AP. mAP@0.5 represents the mean value of mAP when the IOU threshold is 0.5. The operating system used for model training and testing in this study is Windows 10; the versions of Python and Pytorch used for deep learning are 3.9 and 2.0.0, respectively; the CPU and GPU used are Inter I7-13700K and Nvidia GeForce RTX 4070Ti, respectively; the CUDA (Compute Unified Device Architecture) and CUDA deep neural network library are 11.8 and 8.7.0, respectively; the CPU and GPU (Graphics Processing Unit) used are Inter I7-13700K and Nvidia GeForce RTX 4070Ti, respectively; and the CUDA (Compute Unified Device Architecture) and CUDA deep neural network libraries are 11.8 and 8.7.0, respectively. During the training process, the batch sizes and epochs were 32 and 100, respectively, and all other parameters were recommended by the official website.

3. Results

3.1. Setting of Parameters of the YOLOV8 Model

In order to select a suitable model for pig detection, we trained and tested three configurations of YOLOv8 (n, s, and m series), while the l and x series models were not taken into account due to the excessive number of parameters. The results of the comparison of each model on the test set are shown in Table 1. From the table, it can be observed that as the complexity of the YOLOv8 model increases, the mAP@0.5 for both the pig class and the pig_fighting class shows an upward trend, but the corresponding number of parameters and floating-point operations (FLOPs) also increases. Specifically, YOLOv8n has a slightly lower mAP@0.5 of 0.6% for the pig class relative to YOLOv8s and YOLOv8m; the mAP@0.5 for the pig_fighting class is only slightly lower than YOLOv8m’s 0.7%. In addition, the number of parameters of YOLOv8n is reduced by 8.12 M and 22.83 M compared to YOLOv8s and YOLOv8m, respectively; meanwhile, its FLOPs are reduced by 20.3 G and 50.5 G compared to YOLOv8s and YOLOv8m, respectively. Therefore, under the comprehensive consideration of the detection accuracy and the model parameters, we chose YOLOv8n as the detection model and further improved it on this basis.

3.2. Improvements in Different Attention Mechanisms in Model Training

In order to improve the detection accuracy while achieving a light weight, we improved the YOLOv8n model. Meanwhile, in order to verify the performance advantage of the EMA (Exponential Moving Average) module in this experiment, we combined EMA with other attention mechanism modules, such as Global Attention Mechanism (GAM) [31], Squeeze-and-Excitation (SE) [32], and Convolutional Block Attention Module (CBAM) [33]. They were each combined at the same location and evaluated on the same test set. The comparative results of the improved models are shown in Table 2. The model incorporating the EMA module demonstrated higher accuracy for detecting pig identity and pig aggression compared to the other attention mechanisms. Relative to the previous YOLOv8m model with the best performance in detection accuracy, EMA-YOLOv8n was only slightly lower by 0.1% in mAP@0.5 for pig classes, while the number of parameters and FLOPs remained consistent with the smallest YOLOv8n model. Therefore, we chose the EMA-YOLOv8n model for the detection and identification of pig identities and aggressive behaviors.

3.3. Evaluation of Different Models for Detection of Pig and Aggressive Behavior

In order to validate the ability to detect pig aggression, we evaluated each model using images from the test dataset. Table 3 shows the results of different training models in the evaluation. As shown in the table, the mAP@0.5 of EMA-YOLOv8n is much better than that of Faster R-CNN, and its number of parameters and FLOPs is much smaller than that of Faster R-CNN. The reason for the lower mAP@0.5 of Faster R-CNN may be due to the presence of occlusion during pig detection, while Faster R-CNN is not amenable to occluded objects. Compared to SSD, the mAP@0.5 of EMA-YOLOv8n in detecting pig class is 2.0% higher, and its number of parameters and FLOPs are reduced by 20.86 M and 335.7 G, respectively. In addition, the mAP@0.5 of YOLOv5n in detecting pig class and pig_fighting class is slightly lower than that of EMA-YOLOv8n by 0.2% and 1.7%, respectively, which indicates that EMA-YOLOv8n has a higher detection accuracy. Therefore, considering the detection accuracy and model parameters, we chose the EMA-YOLOv8n model for the detection and identification of pig identities and aggressive behaviors in practical applications.

3.4. Evaluation of Model Generalization Capability

To evaluate the generalization ability of the model, we selected 18 video clips with different angles and that were completely different from those of the pigs in the training set, and compared the recognition results of the model algorithm with those of manual recognition. We calculated the number of frames in which the algorithm correctly identified pigs and pig aggression versus the number of frames correctly identified manually, and performed a regression analysis. Figure 8A shows that the results of the algorithmic identification of pigs were highly similar to the manual identification of pigs (R2 = 0.9804). Figure 8B also shows the same results for the algorithmic recognition of pig aggression versus the manual recognition of pig aggression (R2 = 0.9856), which suggests that the detection and recognition results of the model algorithm have potential applications in pig and aggression detection.

4. Discussion

In order to efficiently detect the motion behaviors of pigs, this study adopts a deep learning target detection algorithm and tracking algorithm to construct a model for detecting the motion behaviors of pigs, and realizes the tracking of the motion trajectory and the statistics of the motion duration of pigs by assigning a fixed electronic numerical ID to the pigs. Currently, the study of social hierarchies in pigs and the improvement in their welfare has attracted a lot of attention. It has been found that when weaned piglets are mixed, intense fighting among piglets occurs due to changes in group membership to establish a new social hierarchy [3]. Stookey et al. showed that fighting behavior after mixing may reduce food conversion efficiency and affect piglet weight gain [6]. Li and Johnston et al. found that social hierarchy re-establishment affects weaned piglets’ fighting behavior and productive performance [34]. In pig farming, aggression is considered to be one of the most important health and welfare issues in modern production systems, and may lead to adverse effects including damage to the animal’s body surface, weight loss, and even fatal injuries. However, current research on social hierarchy focuses on 48 to 72 h after mixing, and there are fewer studies on the interaction behaviors among pigs after 72 h. Monitoring pig aggression for a longer period of time can provide a more in-depth study of the social order of the herd, but it is currently usually carried out using video footage or manual observation. At the same time, if pigs can be selected for less fighting by the phenotypic detection of pig aggression, then animal welfare will potentially improve.
In this study, we propose a deep learning-based method for detecting and recognizing pig motion durations and aggressive behaviors, and evaluate the performance of different target detection algorithms for individual pig identification and aggressive behavior detection using computer vision techniques and electronic identity cards, combined with video and image datasets. Subsequently, we adopted the improved EMA-YOLOv8n model and combined it with the tracking algorithm ByteTrack to achieve the real-time and efficient detection and recognition of pig movement and aggressive behavior. Notably, the results of the model generalization ability test show that our proposed detection method is highly similar to the manually recorded data in recognizing pig identity and aggressive behaviors (R2 values of 0.9804 and 0.9856, respectively). We also hoped that our method would be able to detect less obvious (i.e., less escalating) forms of aggression, such as single bites that do not result in obvious bilateral grappling; however, our model is much stricter in its determination, and there are ambiguous behaviors that we do not determine as fights. We are well aware that this type of less obvious aggression can also lead to long-term social stress, which can affect, among other things, productivity and well-being, and we are therefore keen to see our method help other researchers to better address this issue as well.

5. Conclusions

In summary, in this study, we proposed a deep learning-based detection and recognition method for pig motion duration and aggressive behavior, and evaluated the performance of different target detection algorithms for individual pig and aggressive behavior detection by using computer vision techniques and electronic identity cards, combined with video and image datasets. Meanwhile, we proposed a novel EMA-YOLOv8n model and combined it with the tracking algorithm ByteTrack to realize the real-time and efficient detection and recognition of pig motion and aggressive behaviors, as well as the tracking of pig motion trajectories, which led to the statistics of pig motion duration. In addition, the results of the model generalization ability test show that our proposed detection method is highly similar to the manually recorded data in recognizing pig and aggressive behaviors (R2 values of 0.9804 and 0.9856, respectively). Therefore, the proposed modeling method provides an effective way to achieve the detection and identification of pig motion and aggressive behaviors. In addition, the detection and annotation images used in this study can provide a useful reference for other researchers to further explore methods for recognizing, recording, and analyzing pig behaviors.

Supplementary Materials

The following supporting information can be downloaded at https://www.mdpi.com/article/10.3390/ani13193074/s1, Supplementary Video S1. Pigs were detected, tracked, and assigned an artificially assigned fixed numeric ID, in a video sequence comprised of successive frames. A red bounding box represents a pig that was detected in the current frame. The red line represents the trajectory, and, beyond a certain distance, the front part of the track line disappears. In the upper left corner of the video is the motion distance of the pig. For demonstration, we recorded the motion distances of the pigs with ID 1002 and 1004.

Author Contributions

Conceptualization, Z.Z.; methodology, J.W. and X.T.; software, J.W.; validation, J.W., J.L. and X.T.; data curation, J.W. and J.L.; visualization, J.W; writing—original draft, J.W.; writing—review and editing, Z.Z.; supervision, Z.Z.; funding acquisition, Z.Z. All authors have read and agreed to the published version of the manuscript.

Funding

This study was supported by the National Key Technology in Agricultural Project (NK2022110601).

Institutional Review Board Statement

All procedures involving animals followed the guidelines for the care and use of experimental animals (GB/T 27416-2014, Laboratory animal institutions—general requirements for quality and competence) and were approved by the National Standard of the People’s Republic of China, and also the Ethics Committee of Jiangxi Agricultural University.

Informed Consent Statement

Not applicable.

Data Availability Statement

The data presented in this study are available on request from the corresponding authors.

Acknowledgments

We sincerely thank all the people from the State Key Laboratory for Pig Genetic Improvement and Production Technology (Jiangxi Agricultural University) for their help. Special thanks to L.S. Huang for his support in this study.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. Wang, K.; Wang, S.; Ji, X.; Chen, D.; Shen, Q.; Yu, Y.; Xiao, W.; Wu, P.; Yuan, J.; Gu, Y.; et al. Genome-wide association studies identified loci associated with both feed conversion ratio and residual feed intake in Yorkshire pigs. Genome 2022, 65, 405–412. [Google Scholar] [CrossRef]
  2. Miao, Y.; Mei, Q.; Fu, C.; Liao, M.; Liu, Y.; Xu, X.; Li, X.; Zhao, S.; Xiang, T. Genome-wide association and transcriptome studies identify candidate genes and pathways for feed conversion ratio in pigs. BMC Genom. 2021, 22, 294. [Google Scholar] [CrossRef]
  3. Fels, M.; Hartung, J.R.; Hoy, S. Social hierarchy formation in piglets mixed in different group compositions after weaning. Appl. Anim. Behav. Sci. 2014, 152, 17–22. [Google Scholar] [CrossRef]
  4. Meese, G.; Ewbank, R. The establishment and nature of the dominance hierarchy in the domesticated pig. Anim. Behav. 1973, 21, 326–334. [Google Scholar] [CrossRef]
  5. Biswas, C.; Pan, S.; Ray, S. Agonistic ethogram of freshly regrouped weaned piglets. Indian J. Anim. Prod. Manag. 1995, 11, 186–188. [Google Scholar]
  6. Stookey, J.M.; Gonyou, H.W. The effects of regrouping on behavioral and production parameters in finishing swine. J. Anim. Sci. 1994, 72, 2804–2811. [Google Scholar] [CrossRef] [PubMed]
  7. Turner, S.P.; Farnworth, M.J.; White, I.M.S.; Brotherstone, S.; Mendl, M.; Knap, P.; Penny, P.; Lawrence, A.B. The accumulation of skin lesions and their use as a predictor of individual aggressiveness in pigs. Appl. Anim. Behav. Sci. 2006, 96, 245–259. [Google Scholar] [CrossRef]
  8. Kongsted, A.G. Stress and fear as possible mediators of reproduction problems in group housed sows: A review. Acta Agric. Scand. 2004, 54, 58–66. [Google Scholar] [CrossRef]
  9. D’Eath, R.B.; Turner, S.P. The Natural Behaviour of the Pig; Springer: Amsterdam, The Netherlands, 2008. [Google Scholar]
  10. Turner, S.P.; Roehe, R.; D’Eath, R.B.; Ison, S.H.; Farish, M.; Jack, M.C.; Lundeheim, N.; Rydhmer, L.; Lawrence, A.B. Genetic validation of postmixing skin injuries in pigs as an indicator of aggressiveness and the relationship with injuries under more stable social conditions. J. Anim. Sci. 2009, 87, 3076–3082. [Google Scholar] [CrossRef]
  11. Verdon, M.; Hansen, C.F.; Rault, J.-L.; Jongman, E.; Hansen, L.U.; Plush, K.; Hemsworth, P.H. Effects of group housing on sow welfare: A review1. J. Anim. Sci. 2015, 93, 1999–2017. [Google Scholar] [CrossRef]
  12. Qi, J.; Liu, X.; Liu, K.; Xu, F.; Guo, H.; Tian, X.; Li, M.; Bao, Z.; Li, Y. An improved YOLOv5 model based on visual attention mechanism: Application to recognition of tomato virus disease. Comput. Electron. Agric. 2022, 194, 106780. [Google Scholar] [CrossRef]
  13. Li, Y.; Bao, Z.; Qi, J. Seedling maize counting method in complex backgrounds based on YOLOV5 and Kalman filter tracking algorithm. Front. Plant Sci. 2022, 13, 1030962. [Google Scholar] [CrossRef] [PubMed]
  14. Li, S.; Fu, L.; Sun, Y.; Mu, Y.; Chen, L.; Li, J.; Gong, H. Individual dairy cow identification based on lightweight convolutional neural network. PLoS ONE 2021, 16, e0260510. [Google Scholar] [CrossRef] [PubMed]
  15. Shen, W.; Hu, H.; Dai, B.; Wei, X.; Sun, J.; Jiang, L.; Sun, Y. Individual identification of dairy cows based on convolutional neural networks. Multimed. Tools Appl. 2020, 79, 14711–14724. [Google Scholar] [CrossRef]
  16. Li, G.; Huang, Y.; Chen, Z.; Chesser, G.D., Jr.; Purswell, J.L.; Linhoss, J.; Zhao, Y. Practices and Applications of Convolutional Neural Network-Based Computer Vision Systems in Animal Farming: A Review. Sensors 2021, 21, 1492. [Google Scholar] [CrossRef] [PubMed]
  17. Guo, Q.; Sun, Y.; Orsini, C.; Bolhuis, J.E.; Vlieg, J.d.; Bijma, P.; With, P.H.N.d. Enhanced camera-based individual pig detection and tracking for smart pig farms. Comput. Electron. Agric. 2023, 211, 14. [Google Scholar] [CrossRef]
  18. 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]
  19. Wutke, M.; Heinrich, F.; Das, P.P.; Lange, A.; Gentz, M.; Traulsen, I.; Warns, F.K.; Schmitt, A.O.; Gültas, M. Detecting Animal Contacts—A Deep Learning-Based Pig Detection and Tracking Approach for the Quantification of Social Contacts. Sensors 2021, 21, 7512. [Google Scholar] [CrossRef]
  20. Mcglone, J.J. A Quantitative Ethogram of Aggressive and Submissive Behaviors in Recently Regrouped Pigs. J. Anim. Sci. 1985, 3, 556–566. [Google Scholar] [CrossRef]
  21. Chen, C.; Zhu, W.; Liu, D.; Steibel, J.; Norton, T. Detection of aggressive behaviours in pigs using a RealSence depth sensor. Comput. Electron. Agric. 2019, 166, 105003. [Google Scholar] [CrossRef]
  22. Zhang, Y.; Sun, P.; Jiang, Y.; Yu, D.; Weng, F.; Yuan, Z.; Luo, P.; Liu, W.; Wang, X. Bytetrack: Multi-object tracking by associating every detection box. In Proceedings of the European Conference on Computer Vision, Tel Aviv, Israel, 23–27 October 2022; pp. 1–21. [Google Scholar]
  23. Ultralytics YOLOv8. Available online: https://docs.ultralytics.com/ (accessed on 21 June 2023).
  24. Wang, C.Y.; Liao, H.Y.M.; Wu, Y.H.; Chen, P.Y.; Yeh, I.H. CSPNet: A New Backbone that can Enhance Learning Capability of CNN. In Proceedings of the 2020 IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops (CVPRW), Seattle, WA, USA, 14–19 June 2020. [Google Scholar]
  25. Liu, S.; Qi, L.; Qin, H.; Shi, J.; Jia, J. Path aggregation network for instance segmentation. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, Salt Lake City, UT, USA, 18–23 June 2018; pp. 8759–8768. [Google Scholar]
  26. Yang, G.; He, Y.; Yang, Y.; Xu, B. Fine-Grained Image Classification for Crop Disease Based on Attention Mechanism. Front. Plant Sci. 2020, 11, 600854. [Google Scholar] [CrossRef] [PubMed]
  27. Ouyang, D.; He, S.; Zhang, G.; Luo, M.; Guo, H.; Zhan, J.; Huang, Z. Efficient Multi-Scale Attention Module with Cross-Spatial Learning. In Proceedings of the ICASSP 2023—2023 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP), Rhodes Island, Greece, 4–10 June 2023; pp. 1–5. [Google Scholar]
  28. Ren, S.; He, K.; Girshick, R.B.; Sun, J. Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks. IEEE Trans. Pattern Anal. Mach. Intell. 2015, 39, 1137–1149. [Google Scholar] [CrossRef] [PubMed]
  29. Liu, W.; Anguelov, D.; Erhan, D.; Szegedy, C.; Reed, S.E.; Fu, C.-Y.; Berg, A.C. SSD: Single Shot MultiBox Detector. In Proceedings of the European Conference on Computer Vision, Santiago, Chile, 7–13 December 2015. [Google Scholar]
  30. Wojke, N.; Bewley, A.; Paulus, D. Simple online and realtime tracking with a deep association metric. In Proceedings of the 2017 IEEE International Conference on Image Processing (ICIP), Beijing, China, 17–20 September 2017; pp. 3645–3649. [Google Scholar]
  31. Liu, Y.; Shao, Z.; Hoffmann, N. Global attention mechanism: Retain information to enhance channel-spatial interactions. arXiv 2021, arXiv:2112.05561. [Google Scholar]
  32. Hu, J.; Shen, L.; Sun, G. Squeeze-and-Excitation Networks. In Proceedings of the 2018 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), Salt Lake City, UT, USA, 18–23 June 2018. [Google Scholar]
  33. Woo, S.; Park, J.; Lee, J.-Y.; Kweon, I.S. Cbam: Convolutional block attention module. In Proceedings of the European Conference on Computer Vision (ECCV), Munich, Germany, 8–14 September 2018; pp. 3–19. [Google Scholar]
  34. Li, Y.Z.; Johnston, L.J. Behavior and performance of pigs previously housed in large groups. J. Anim. Sci. 2009, 87, 1472–1478. [Google Scholar] [CrossRef]
Figure 1. Composition of dataset.
Figure 1. Composition of dataset.
Animals 13 03074 g001
Figure 2. Example of data processing flow and data enhancement. Here ’0’ represents class ’pig’ in the training set and ’1’ represents class ’pig_fighting’ in the training set.
Figure 2. Example of data processing flow and data enhancement. Here ’0’ represents class ’pig’ in the training set and ’1’ represents class ’pig_fighting’ in the training set.
Animals 13 03074 g002
Figure 3. The Structure of EMA module. Avg Pool, average pooling; Conv, convolution; Sigmoid, activation function; Softmax, normalized exponential function.
Figure 3. The Structure of EMA module. Avg Pool, average pooling; Conv, convolution; Sigmoid, activation function; Softmax, normalized exponential function.
Animals 13 03074 g003
Figure 4. The structure of the EMA-YOLOV8n model. Conv, convolutional; BN, batch normalization; SiLU, sigmoid linear unit.
Figure 4. The structure of the EMA-YOLOV8n model. Conv, convolutional; BN, batch normalization; SiLU, sigmoid linear unit.
Animals 13 03074 g004
Figure 5. A detection box and a tracker for a pig.
Figure 5. A detection box and a tracker for a pig.
Animals 13 03074 g005
Figure 6. The schematic diagram of pig movement recording.
Figure 6. The schematic diagram of pig movement recording.
Animals 13 03074 g006
Figure 7. Example of a pig attack detection box.
Figure 7. Example of a pig attack detection box.
Animals 13 03074 g007
Figure 8. Results of artificial recognition algorithm and regression analysis. (A) Regression analysis to identify pigs. (B) Regression analysis to identify pig aggression.
Figure 8. Results of artificial recognition algorithm and regression analysis. (A) Regression analysis to identify pigs. (B) Regression analysis to identify pig aggression.
Animals 13 03074 g008
Table 1. The comparison results of the YOLOV8 (n, s, and m series) modes.
Table 1. The comparison results of the YOLOV8 (n, s, and m series) modes.
ModelsClassmAP@0.5 (%) 1ParametersFLOPs (G)
YOLOV8nPig 295.63.01 M8.1
pig_fighting 395.9
YOLOV8spig96.211.13 M28.4
pig_fighting95.9
YOLOV8mpig96.225.84 M78.7
pig_fighting96.6
1 Mean average precision; 2 the object of detection in the datasets is pig; 3 the object of detection in the datasets is the aggressive behavior of pigs.
Table 2. The comparison results of adding different attention mechanisms.
Table 2. The comparison results of adding different attention mechanisms.
ModelsClassmAP@0.5 (%) 1ParametersFLOPs (G)
YOLOV8nPig 295.63.01 M8.1
pig_fighting 395.9
SE-YOLOV8npig95.83.01 M8.1
pig_fighting95.8
CBAM-YOLOV8npig96.0 3.01 M8.1
pig_fighting95.9
EMA-YOLOV8npig96.1 3.02 M8.1
pig_fighting96.6
GAM-YOLOV8npig96.1 4.65 M12.5
pig_fighting96.2
1 Mean average precision; 2 the object of detection in the datasets is pig; 3 the object of detection in the datasets is the aggressive behavior of pigs.
Table 3. The posed detection model and comparison results of pigs and aggressive behavior.
Table 3. The posed detection model and comparison results of pigs and aggressive behavior.
ModelsClassmAP@0.5 (%) 1ParametersFLOPs (G)
SSDPig 294.123.88 M343.3
pig_fighting 396.4
Faster R-CNNpig52.441.13 M193.78
pig_fighting46.5
YOLOV5npig95.9 1.76 M4.1
pig_fighting94.9
EMA-YOLOV8npig96.13.02 M8.1
pig_fighting96.6
1 Mean average precision; 2 the object of detection in the datasets is pig; 3 the object of detection in the datasets is the aggressive behavior of pigs.
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Wei, J.; Tang, X.; Liu, J.; Zhang, Z. Detection of Pig Movement and Aggression Using Deep Learning Approaches. Animals 2023, 13, 3074. https://doi.org/10.3390/ani13193074

AMA Style

Wei J, Tang X, Liu J, Zhang Z. Detection of Pig Movement and Aggression Using Deep Learning Approaches. Animals. 2023; 13(19):3074. https://doi.org/10.3390/ani13193074

Chicago/Turabian Style

Wei, Jiacheng, Xi Tang, Jinxiu Liu, and Zhiyan Zhang. 2023. "Detection of Pig Movement and Aggression Using Deep Learning Approaches" Animals 13, no. 19: 3074. https://doi.org/10.3390/ani13193074

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