Journal of Animal Science and Technology
Korean Society of Animal Sciences and Technology

A computer vision-based approach for behavior recognition of gestating sows fed different fiber levels during high ambient temperature

Payam Hosseinzadeh Kasani1,#, Seung Min Oh2,#, Yo Han Choi3,#, Sang Hun Ha1, Hyungmin Jun4, Kyu Hyun Park1, Han Seo Ko1, Jo Eun Kim3, Jung Woo Choi1, Eun Seok Cho3,*, Jin Soo Kim1,5,*
1College of Animal Life Sciences, Kangwon National University, Chuncheon 24341, Korea
2Gyeongbuk Livestock Research Institute, Yeongju, 63052, Korea
3Swine Division, National Institute of Animal Science, Rural Development Administration, Cheonan 31000, Korea
4Division of Mechanical System Engineering, Jeonbuk National University, Jeonju 54896, Korea
5Department of Bio-Health Convergence, Kangwon National University, Chuncheon 24341, Korea
*Corresponding author: Eun Seok Cho, Swine Division, National Institute of Animal Science, Rural Development Administration, Cheonan 31000, Korea. Tel: +82-41-580-3451, E-mail:
*Corresponding author: Jin Soo Kim, College of Animal Life Sciences, Kangwon National University, Chuncheon 24341, Korea. Tel: +82-33-250-8614, E-mail:

#These authors contributed equally to this work.

© Copyright 2021 Korean Society of Animal Science and Technology. This is an Open-Access article distributed under the terms of the Creative Commons Attribution Non-Commercial License ( which permits unrestricted non-commercial use, distribution, and reproduction in any medium, provided the original work is properly cited.

Received: Dec 07, 2020; Revised: Dec 30, 2020; Accepted: Dec 30, 2020

Published Online: Mar 31, 2021


The objectives of this study were to evaluate convolutional neural network models and computer vision techniques for the classification of swine posture with high accuracy and to use the derived result in the investigation of the effect of dietary fiber level on the behavioral characteristics of the pregnant sow under low and high ambient temperatures during the last stage of gestation. A total of 27 crossbred sows (Yorkshire × Landrace; average body weight, 192.2 ± 4.8 kg) were assigned to three treatments in a randomized complete block design during the last stage of gestation (days 90 to 114). The sows in group 1 were fed a 3% fiber diet under neutral ambient temperature; the sows in group 2 were fed a diet with 3% fiber under high ambient temperature (HT); the sows in group 3 were fed a 6% fiber diet under HT. Eight popular deep learning-based feature extraction frameworks (DenseNet121, DenseNet201, InceptionResNetV2, InceptionV3, MobileNet, VGG16, VGG19, and Xception) used for automatic swine posture classification were selected and compared using the swine posture image dataset that was constructed under real swine farm conditions. The neural network models showed excellent performance on previously unseen data (ability to generalize). The DenseNet121 feature extractor achieved the best performance with 99.83% accuracy, and both DenseNet201 and MobileNet showed an accuracy of 99.77% for the classification of the image dataset. The behavior of sows classified by the DenseNet121 feature extractor showed that the HT in our study reduced (p < 0.05) the standing behavior of sows and also has a tendency to increase (p = 0.082) lying behavior. High dietary fiber treatment tended to increase (p = 0.064) lying and decrease (p < 0.05) the standing behavior of sows, but there was no change in sitting under HT conditions.

Keywords: Convolutional neural network; Dietary fiber; Heat stress; Machine learning; Sows


Heat stress (HT) has become a frequent and serious problem for swine productivity and welfare in the swine industry [1]. Pig thermoregulation relies on heat dissipation through the respiratory pathway (gasping) rather than via the sweat glands due to the thick subcutaneous fat, which inhibits sensible heat loss [2,3]. Various strategies such as behavioral and metabolic changes are initiated to minimize heat generation when it is difficult for pigs to maintain euthermia in response to high ambient temperatures [1]. In general, one of the major adaptations for correcting metabolic heat production in response to high ambient temperature is reducing voluntary feed intake (VFI), which minimizes metabolic heat production [4]. However, in commercial farms, reduction in VFI, induced by high ambient temperature, of the pregnant sows may not help maintain euthermia throughout the regulation of metabolic heat production owing to the limited VFI for preventing obesity. Moreover, limited VFI can trigger certain behaviors induced by hunger, and restrictions on behavior due to the stall can increase sow stress as well as heat stress. To prevent this problem, studies have been conducted on the level of fiber in sow feed. Dietary fiber is related to the physicochemical properties of diets and increases the bulk and water-holding capacity of feed, thereby allowing it to expand in the gastrointestinal tract of the sow [5]. Dietary fiber can be used to prevent constipation and increase the satiety of sows [5,6]. The satiety of sows is reflected in stereotypic behaviors such as non-feeding oral activities and physical activities [7]. Long periods of sitting or standing inactive could indicate poor welfare, whereas lying may reflect improved wellbeing [8]. Therefore, the assessment of behavioral characteristics is used to evaluate the stress and welfare of sows [5]. The productivity and welfare of swine are adversely affected by heat stress, but manual observation and classification of animal stress-related behaviors are laborious, invasive, time-consuming, and dependent on expert scorers. Automated monitoring and recognition of swine behavior can be a more effective way to overcome these hindrances and improve farm animal management compared with manual observations.

The classical approaches to pose estimation are based on manual visual observation by the farmer, based on behavioral patterns as swine typically show a variety of behavioral responses to environmental stimuli and stress. This management method may contribute to improved welfare when appropriate measures are taken [9]. However, traditional manual observation methods are time- and labor-consuming and rely heavily on the operator. Computational analysis for evaluating behavior data is an area of increased research interest because of its importance in health-related diagnosis issues and management planning.

Recently, with the rapid development of deep learning, automated and non-intrusive animal monitoring systems have drawn attention to the potential of significantly reducing labor consumption and improving the collection and classification of behavioral information to support management decisions. In a study by Yang [10], the performance of a fully convolutional network (FCN) [11] was evaluated to automatically recognize the nursing behaviors of sows. They proposed a method that exploits Spatio-temporal relations using FCN and oriented optical flow to automatically recognize nursing behaviors from daily behavioral videos of lactating sows [10]. Zheng et al. [12] introduced a deep learning detector, with faster regions and a convolutional neural network (R-CNN) [13] to automatically identify five postures of sows in loose pens. Chen et al. [14] proposed a deep learning method based on convolutional neural networks (CNNs) [15,16] and long short-term memory for the early detection of aggressive episodes of pigs.

In this study, we constructed a swine image dataset under real farm conditions. The acquisition of real farm images is influenced by conditions and parameters such as variable distances, poor resolution, and non-ideal illumination. The quality of images depends on several factors such as shadows, noises, artifacts, and reflections, which hinder data acquisition with reliability and robustness for swine posture analysis. Therefore, a computer-aided diagnosis system that can analyze real farm condition images may be considered for swine behavioral pattern classification. Therefore, the objectives of this study were to evaluate the effect of the automatic classification system of eight well established and state-of-the-art artificial intelligence techniques using a swine image dataset to predict behaviors by applying an appropriate classifier to the pre-processed data and to apply the derived result in investigating the effect of dietary fiber level on the behavioral characteristics of the pregnant sow under high ambient temperatures during the last stage of gestation.


The protocol for the current study was approved by the Institutional Animal Care and Use Committee of Kangwon National University, Chuncheon, Korea (KW-170519-1).

Animals and management

The experiment was conducted at a swine farm located at Kangwon National University (Chuncheon, Korea). During the last days of gestation (days 90 to 114), a total of 27 crossbred sows (Yorkshire × Landrace; average body weight [BW], 192.2 ± 4.8 kg) were assigned to three treatment groups, in a randomized complete block design, based on the body weight (kg). Each treatment had 10 replicates with one sow. The sows in group 1 were fed diets containing 3% fiber (LF) under neutral ambient temperature (NT); the sows in group 2 were fed diets containing 3% fiber under HT; and the sows in group 3 were fed diet containing 6% fiber (HF) under HT. Two isoenergetic and isonitrogenous diets in a mash were formulated for gestation period (Table 1). Diets weighing 2.2 kg were provided to each sow per day at 08:00 and 16:00 until farrowing. The sows were given ad libitum access to water throughout the gestation period. They were housed in gestation stalls (2,000 × 600 × 1,000 mm) from 90 to 100 d of gestation. At day 100 of gestation, the sows were moved into two types of conventional farrowing houses: farrowing house A was an open house with facilitated farrowing crates (2,000 × 600 × 1,000 mm); farrowing house B was a closed house with facilitated farrowing crates (2,000 × 600 × 1,000 mm) and a cooling pad. The average temperatures in the gestation house (days 90 to 100 of gestation), farrowing house A (days 100 to 114 of gestation), and farrowing house B (days 100 to 114 of gestation) were 29.7 ± 2.4°C, 28.2 ± 1.1°C, and 21.4 ± 1.8°C, respectively.

Table 1. Formula and chemical composition of lactation sow diets (as-fed basis)
Items Control High fiber
Ingredients (%) 100.00 100.0
 Corn 68.77 28.97
 Wheat 4.00 4.00
 Soybean meal 14.06 1.32
 Animal fat - 7.53
 Wheat bran 5.83 34.53
 DDGS 4.00 20.00
 Salt 0.50 0.50
 TCP 1.36 0.92
 Limestone 0.86 1.25
 DL-methionine (98%) 0.02 0.03
 Lysine (78.8%) 0.08 0.34
 Tryptophan (10%) 0.07 0.17
 Threonine (98.5%) 0.11 0.08
 Choline-Liquid (50%) 0.10 0.10
 Vitamin premix1) 0.10 0.10
 Mineral premix2) 0.10 0.10
 Phytase 0.05 0.05
Chemical composition (%)
 Dry matter 87.5 88.4
 Crude protein 14.00 14.00
 Ether extract 2.77 10.96
 Crude fiber 3.00 6.00
 Ca 0.82 0.82
 P 0.69 0.81
 Available P3) 0.38 0.38
 Lysine 0.68 0.71
 MET + CYS 0.50 0.53
 Threonine 0.62 0.56
 Tryptophan 0.15 0.16
ME (kcal/kg)3) 3,140 3,140

Supplied per kilogram of vitamin premix: 12,000,000 IU vitamin A, 2,400,000 IU vitamin D3, 132,000 IU vitamin E, 1,500 mg vitamin K3, 3,000 mg vitamin B1, 11,250 mg vitamin B2, 3,000 mg vitamin B6, 45 mg vitamin B12, 36,000 mg pantothenic acid, 30,000 mg niacin, 600 mg biotin, 4,000 mg folic acid.

Supplied per kilogram of mineral premix: 80,000 mg Fe, 170 mg Co, 8,500 mg Cu, 25,000 mg Mn, 95,000 mg Zn, 140 mg I, 150 mg Se.

Calculated values.

DDGS, dried distiller’s grains with solubles; TCP, tricalcium phosphate; MET, methionine; CYS, cysteine; ME, metabolizable energy.

Download Excel Table
Video acquisition

To build image datasets for the behavioral observation of sows, the videos were recorded and collected as top-down view images. Cameras were installed above the center of the swine pen on the ceiling at a height of 2.20 m, relative to the floor. The lens on the camera pointed directly downwards the pen to monitor their activity over time. The videos were recorded in JPEG format with 1,920 × 1,080 pixels at 30 fps, between 11:00 am and 1:30 pm during the last gestation period in the natural state, without special preparations to enhance the lighting or to improve the distinguishability of the animals from the background. Videos were converted to image sequences, and the images were used for the development of digital image processing. Only one image per second was captured for substantial savings in storage space.

Datasets and labeling

The dataset contained 11,850 images, and the data were split into 7,556 training images, 2,517 validation images, and 1,776 testing images. The images were categorized into four classes including 2,439 images which were created for lying left, 2,650 for laying right, 4,458 for sitting, and 2,277 for standing. The computations were performed using a Python 3.7 on an Intel(R) Core (TM) i7-8700 K CPU @ 3.70 GHz, 16 GB RAM, NVIDIA GeForce RTX 2080 with 8GB RAM on a 64-bit Windows 10 operating system. The CNN and long short-term memory (LSTM) architectures were implemented in TensorFlow 1.13.1 and Keras 2.2.4, respectively.

Definition of the sow behaviors

In this study, four postures were defined for the behavior classification. The sows’ behaviors covered in this analysis included lying left, lying right, sitting, and standing. The definitions of the four classes of sow postures are shown in Table 2, and their corresponding examples are shown in Fig. 1.

Table 2. Definition and description of different sow behaviors recorded in a farrowing crate
Behaviors Classification description
Lying left Resting with her left side in contact with the farrowing crate floor.
Laying right Resting with her right side in contact with the farrowing crate floor.
Sitting Sitting on her hip or stretched front legs with caudal end of body contacting the floor.
Standing Upright body position on extended legs with hooves only in contact with the floor.
Download Excel Table
Fig. 1. Representation of swine posture categorization in four classes.
Download Original Figure

Here, we used four deep learning architectures: InceptionV3, DenseNet, MobileNet, and VGG net models. InceptionV3 is the third generation of Google’s Inception CNN and consists of 159 layers in total. The prominent feature of the inception module is the use of three convolution sizes of filters (1 × 1, 3 × 3, and 5 × 5) instead of using one type of kernel, and a bottleneck layer for nonlinear dimensionality reduction. Moreover, the presence of a pooling layer is used for dimension reduction within the module. DenseNet is one of the recent discoveries in neural networks for visual object recognition that, by summation operations, connect each layer to every other layer in a feed-forward fashion. DenseNet is able to achieve maximum information flow between layers in the network. Feature maps extracted from each layer are reused as inputs for the subsequent layers. Compared with the previous image recognition network, it solves the problem of gradient disappearance of a deep network, strengthens the propagation of features, encourages feature reuse, and reduces model parameters. The MobileNet architecture, designed by the Google research team for object recognition on mobile devices, consists of a depth-wise separable convolution and 1 × 1 point-wise, convolution layer. The performance was evaluated on the ImageNet dataset [17] and achieved the same level of accuracy as VGG16 [18] with 32 times fewer parameters and was 27 times less computationally intensive. Depth-wise convolution uses a single spatial filter for each input feature map, and pointwise convolution (1 × 1) is applied to cross-channel patterns. The VGG network architecture is the CNN model introduced by Simonyan and Zisserman [18] for the ILSVRC-2014 challenge. This network is characterized by its simplicity, using only 3 × 3 convolutional layers stacked on top of each other in increasing depth. Reducing the volume size is handled by max pooling. Two fully connected layers, each with 4,096 nodes, are then followed by a softmax classifier.

Evaluation criteria

To estimate the prediction performance of individual models, four commonly used evaluation metrics were applied: accuracy, sensitivity, specificity, and F1-score. Sensitivity is the measure of swine posture labels that are correctly classified and expressed in the form as:

Sensitivity = TP TP + FN × 100 ,

where true positive (TP) is the number of images that are correctly predicted and false-negative (FN) is the number of images that are incorrectly predicted.

Specificity is the measure of swine posture labels that are successfully classified and is expressed as:

Specificity = TN TN + FP × 100 ,

where true negative (TN) is the number of negative images that are correctly predicted and false positive (FP) is the number of negative images that are incorrectly predicted.

Accuracy is used to show the number of correctly classified swine postures divided by the total number of swine postures and is defined as:

Accuracy = TP + TN TP + TN + FP + FN × 100.

F1-score, known as F-measure, is defined as the weighted average of precision and recall and is obtained by

F1-Socre = 2 × Re call ×  Pr ecision Re call +  Pr ecision .
Statistical analysis

The percentage of the number of image results classified by architectures from individual sows was pulled and was considered the experimental unit in all statistical analyses to compare sow behavior classification. Analysis of variance (ANOVA) was performed using the SAS program (SAS 2012; SAS Institute, Cary, NC, USA), and the differences among the treatments were determined using Tukey’s test. Probability values less than 0.05 were considered significant.


Loss and accuracy comparison

Total loss and accuracy are two indicators routinely used to evaluate the fitting effect and the convergence of training and validation processes when using deep learning methods. A learning curve can be used to visualize a cumulative evaluation of a classifier’s learning performance over time (epochs) when using training and validation datasets. It noticeably signifies how well fitted (under-fit or over-fit) a particular classifier or any machine learning model is during the model training phase.

A comparative assessment was conducted to determine the training behavior of different models. Fig. 2 illustrates the learning curves (loss and accuracy plots) for the eight individual networks that were evaluated using training and hold-out validation datasets. The results from the training and validation loss for various classifiers ensured the learning and generalization ability of the classifiers on training and hold-out validation datasets. Fig. 2 shows that all eight individual algorithm models converged in the training and validation processes of the rock structure classification. Additionally, a minimum loss value signifies the best results, which means that the training and validation datasets were learned by the classifier with fewer errors (Figs. 2a, b). In contrast, a maximum accuracy value signifies the best results, indicating more learning ability by the classifier model. This kind of dual learning curve helps in evaluating and selecting a suitable classifier model with an optimized loss and maximum classification accuracy in both the training and validation sets. Fig. 3 illustrates the relationship between the prediction accuracy and the total loss, which shows that the training and validation loss remains very close, indicating that the model is not overfitting to the training data. These graphs illustrate the deep architectures of how and what happened during these phases.

Fig. 2. Loss function and accuracy curves of individual architectures. a) DenseNet121, b) DenseNet201, c) InceptionResNetV2, d) InceptionV3, e) MobileNet, f) VGG16, g) VGG19, and h) Xception.
Download Original Figure
Fig. 3. Confusion matrix of swine behavior image classification. a) DenseNet121, b) DenseNet201, c) InceptionResNetV2, d) InceptionV3, e) MobileNet, f) VGG16, g) VGG19, and h) Xception.
Download Original Figure
Behavior classification by deep convolutional neural network (CNN) architectures

Deep feature extraction based on transfer learning started by investigating the effect of eight different deep CNN architectures in extracting deep features from input images and achieving optimal prediction on the unseen test data. The swine posture dataset was trained on eight different CNN architectures, including DenseNet121, DenseNet201, InceptionResNetV2, InceptionV3, MobileNet, VGG16, VGG19, and Xception, individually. DenseNet121 significantly outperformed the other individual architectures on the provided dataset with an accuracy of 99.83%, a sensitivity of 100%, a specificity of 100%, and an F1_score of 99.83% (Table 3). Compared with the remaining network models, the DenseNet201and MobileNet architectures individually provided better performance classification with accuracies of 99.77% and 99.77%, respectively. However, VGG16 is the only model that obtained the lowest accuracy of 99.54% (Table 3). The VGG16 also had poor performance (99.55%) on the F1-score. Therefore, the DenseNet family and MobileNet CNN architectures achieve high performance in terms of accuracy in the detection and classification of swine posture as compared to the other five architectures. It also shows that the DenseNet family network model can extract more distinguishing features with better robustness and generalization than the other models.

Table 3. Classification results from pre-trained deep CNN models
Method Model performance indicators
Accuracy (%) Sensitivity Specificity F1_score
DenseNet1211) 99.83 100 100 99.83
DenseNet2012) 99.77 100 100 99.77
InceptionResNetV2 99.71 100 100 99.71
InceptionV3 99.71 100 100 99.71
MobileNet2) 99.77 100 100 99.77
VGG16 99.54 100 100 99.55
VGG19 99.71 100 100 99.71
Xception 99.71 100 100 99.71

The best result.

Represents the second-best result of the respective category.

Download Excel Table
Confusion matrix

In multi-class classification tasks, most of the evaluation metrics are computed based on a “confusion matrix”. The confusion matrices can be used to precisely sum up the performance of the proposed classification model. In addition to the comparison of accuracy and loss, for a more detailed analysis, the quantitative results for eight individual architectures were compared in the form of confusion matrices (Fig. 3). The confusion matrix demonstrates the performance of the classifier in terms of the number of swine posture images that have been correctly classified as well as the misclassified cases for each class. Densenet121 was able to correctly classify 1,773 images out of 1,776 images and hence provided a better classification of swine posture than the others. In conclusion, DenseNet121 is the best learner, and its counterpart, DenseNet201, and MobileNet, are the second-best learners. It is clear that these three architectures surpass other architecture models in terms of accuracy, sensitivity, specificity, and F1_score, which implies that these models are able to extract more discriminatory features from the swine posture images, resulting in a higher detection rate (Table 3). In swine posture image classification on the test set, however, Vgg16 incorrectly recognized eight images, in which seven images of “sitting” were misclassified as “lying right”. In the confusion matrix of swine behavior classification using different deep CNN models, the values on the main diagonal represent all correctly classified instances. The row under each confusion matrix shows the rate of accuracy achieved for each predicted class and misclass predictions.

Sow behavior

The processed results of behavior classification using the Densenet121 model are shown in Table 4. When comparing the ambient temperature (neutral vs. high) with the same dietary treatment (CF 3%), the frequency of standing of the sows in the HT treatment group was higher (p < 0.05) than that of sows in the NT treatment group and the frequency of lying behavior of sows tended to increase (p = 0.082) under the HT. However, the ambient temperature did not significantly affect the frequency of sitting and lying on the right.

Table 4. Effect of ambient temperature and dietary fiber levels on sow’s behavior frequency (%) classified by Densenet121
Items NT + LF HT + LF HT + HF SEM p-values
NT + LF vs HT + LF HT + LF vs HT + HF NT + LF vs HT + HF
% of observation
 Lying1) 45.43 49.48 53.80 0.97 0.082 0.069 <0.001
  Left lying 22.51 24.69 27.07 0.55 0.079 0.081 <0.001
  Right lying 22.93 24.79 26.73 0.47 0.174 0.123 0.002
 Standing 13.08 9.26 5.31 0.80 0.009 0.012 <0.001
 Sitting 41.48 41.26 40.89 0.41 0.998 0.936 0.909

Sum of left and right lying.

NT, neutral ambient temperature; LF, low dietary fiber (3%); HT, high ambient temperature; HF, high dietary fiber (3%).

Download Excel Table

Under the HT, the increase in dietary fiber significantly decreased (p < 0.05) the frequency of standing of the sows and tended to increase (p = 0.064) the lying behavior, whereas the frequency of sitting was not affected by the dietary treatment. Comparing the NT + LF and HT + HF treatments, the frequency of lying of sows in HT + HF treatment was higher (p < 0.05) than that of sows in HT + HF treatment. However, the frequency of standing of sows in HT + HF treatment was lower than that of sows in NE + LF treatment.

In this study, the behavioral analysis was performed during the last stage of the gestation of sows, and the frequency of lying behavior in all treatments occupied a larger proportion of time as compared to that of sitting and standing. Zhang et al. [19] evaluated the behavior in sows of different parities and the welfare of sows in intensive farming systems and reported that the lying behavior increased in the latter stages of pregnancy and decreased before farrowing. Improving the confined environment would improve the comfort of sows and reduce physiological and mental stress [20]. Sitting or standing for long periods of time indicates poor welfare, whereas lying reflects improved well-being [8]. However, considering the increase in lying behavior of sows under HT conditions as a parameter would be controversial as it may not adequately reflect the welfare of sows. The HT in our study reduced the standing behavior of sows and had the tendency to increase lying behavior. Our results were contrary to previous reports on the sow’s comfort under HT conditions. The sows’ behavioral changes at HT were decreased and sows spent most of their time lying due to the heat increment resulting from their movement [21]. However, HT and metabolic heat increment of sows increase with the presence of some facility (floor or crate) in contact with sow’s skin. This increases the sow’s temperature regulation characteristics (emitting metabolic heat through the skin) so that the frequency of posture change increases due to the instinct to find a cool place [22]. These conflicting results disprove the need for more research into investigating sow behavior under HT.

In our study, the high dietary fiber treatment tended to increase the lying and decrease the standing behavior of sows, but there was no change in sitting. In the present study, the ventral lying was included in sitting, and ‘lying’ represented only lateral lying (left and right side); thus, sitting behavior might not have been affected by the treatments. Changes in the frequency of the sows’ behavior regarding the level of dietary fiber can be associated with satiety. Dietary fibers are composed of plant polysaccharides and lignin that are not hydrolyzed by endogenous enzymes in the gastrointestinal tract, increasing the passage rate and altering the digestion and absorption times of nutrients [23]. The dietary fiber increases the concentration of non-esterified fatty acids in the blood by supplying a constant concentration of glucose to the pregnant sows for a long time, thereby increasing satiety [23]. Our findings reflect the satiety of the sows, and the integrated results show its positive effects on sows before farrowing. However, dietary fiber increases the internal body temperature due to fermentation in the gut [24]. It is hypothesized that high dietary fiber induces additional heat stress in pregnant sows. However, in our study, the sows were fed the same amount of feed with adequate nutrients, using restricted feeding, and there was no additional supply other than the suggested fiber. Therefore, a possible explanation for our overall behavioral results could be the hypothesis that the sows reduced metabolic heat generation by minimizing movement to adapt to the HT. Further studies are required to evaluate the occurrence of heat stress and sows’ health due to the fermentation of fiber during late stages of pregnancy.


In this paper, a comparative study was presented for swine posture classification during the last stage of gestation, generating a farm image dataset containing various poses of swine. Pre-processing methods such as illumination correction, contrast enhancement, and artifact removal were used to improve image quality and obtain a better generalization ability. Due to the limitation of the behavioral pattern of sows during the late stages of gestation, four behavior patterns—lying left, lying right, sitting, and standing—were applied for classification. Various standard evaluation metrics such as specificity, sensitivity, accuracy, and F1-score were employed to evaluate the obtained results. The diagnostic accuracy of several deep-learning models was tested in this work, and it was observed that the DenseNet neural network model gave excellent results regarding the accuracy and was superior to other structural models in classification performance, thus achieving a more accurate classification of the swine image dataset. The results of this study suggest that the application of CNN-based computer-aided diagnostic methods integrated with image processing and machine learning methods can reliably classify different behavioral postures under different commercial farm conditions and therefore assist in the interpretation of swine behavioral patterns and that this has the potential to become a key approach in commercial swine farming. A new strategy for the investigation of sow’s behavior was successfully applied in our study to determine how ambient temperature and dietary fiber levels affected the behavior of sows during the last stage of gestation. The HT in our study reduced the standing behavior of sows and had a tendency to increase lying behavior. High dietary fiber tended to increase lying and decrease the standing behavior of sows, but there was no change in sitting under HT condition. Therefore, standing behavior can be presented as an influential indicator of heat stress in sow welfare.

Competing interests

No potential conflict of interest relevant to this article was reported.

Funding sources

This research was funded by Rural Development Administration, Korea (grant number: PJ014796012020).


This study was supported by 2021 the RDA Fellowship Program of National Institute of Animal Science, Rural Development Administration, Korea.

Availability of data and material

Upon reasonable request, the datasets of this study can be available from the corresponding author.

Authors’ contributions

Conceptualization: Kasani PH, Oh SM, Choi YH, Choi JW, Kim JS.

Data curation: Kasani PH, Kim JS.

Formal analysis: Kasani PH.

Methodology: Kasani PH, Oh SM.

Software: Kasani PH.

Validation: Kasani PH, Jun H.

Investigation: Kasani PH, Oh SM, Ha SH, Ko HS, Kim JE.

Writing - original draft: Kasani PH, Park KH, Cho ES, Kim JS.

Ethics approval and consent to participate

The project underwent proper ethical standards and the experiments (KW-170519-1) were approved by the Institutional Animal Care and Use Committee of Kangwon National University, Chuncheon, Korea.



Mayorga EJ, Renaudeau D, Ramirez BC, Ross JW, Baumgard LH. Heat stress adaptations in pigs. Anim Front. 2019; 9:54-61


Collier RJ, Gebremedhin KG. Thermal biology of domestic animals. Annu Rev Anim Biosci. 2015; 3:513-32


Lucy MC, Safranski TJ. Heat stress in pregnant sows: thermal responses and subsequent performance of sows and their offspring. Mol Reprod Dev. 2017; 84:946-56


Kim KY, Choi YH, Hosseindoust A, Kim M, Hwang S, Bu MS, et al. Evaluation of high nutrient diets and additional dextrose on reproductive performance and litter performance of heat-stressed lactating sows. Anim Sci J. 2019; 90:1212-9


Sun HQ, Tan CQ, Wei HK, Zou Y, Long G, Ao JT, et al. Effects of different amounts of konjac flour inclusion in gestation diets on physio-chemical properties of diets, postprandial satiety in pregnant sows, lactation feed intake of sows and piglet performance. Anim Reprod Sci. 2015; 152:55-64


Oliviero C, Kokkonen T, Heinonen M, Sankari S, Peltoniemi O. Feeding sows with high fibre diet around farrowing and early lactation: impact on intestinal activity, energy balance related parameters and litter performance. Res Vet Sci. 2009; 86:314-9


De Leeuw JA, Bolhuis JE, Bosch G, Gerrits WJJ. Effects of dietary fibre on behaviour and satiety in pigs. Proc Nutr Soc. 2008; 67:334-42


Zverina LR, Kane J, Crenshaw TD, Salak-Johnson JL. A Pilot study: behavior and productivity of gestating sows in width-adjustable stalls. Austin J Vet Sci Anim Husb. 2015; 2:1012


Matthews SG, Miller AL, 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


Yang A, Huang H, Yang X, Li S, Chen C, Gan H, et al. Automated video analysis of sow nursing behavior based on fully convolutional network and oriented optical flow. Comput Electron Agric. 2019; 167:105048


Long J, Shelhamer E, Darrell T. Fully convolutional networks for semantic segmentation. arXiv. 2015


Zheng C, Zhu X, Yang X, Wang L, Tu S, Xue Y. Automatic recognition of lactating sow postures from depth images by deep learning detector. Comput Electron Agric. 2018; 147:51-63


Ren S, He K, Girshick R, Sun J. Faster r-cnn: towards real-time object detection with region proposal networks. Neural Inf Process Syst. 2015; 39:91-9


Chen C, Zhu W, Steibel J, Siegford J, Wurtz K, Han J, et al. Recognition of aggressive episodes of pigs based on convolutional neural network and long short-term memory. Comput Electron Agric. 2020; 169:105166


Behnke S. Hierarchical neural networks for image interpretation. Boston, MA: Springer. 2003


Simard PY, Steinkraus D, Platt JC. Best practices for convolutional neural networks applied to visual document analysis.In Proceedings of the Seventh International Conference on Document Analysis and Recognition. 2003 Edinburgh, Scotland.


Deng J, Dong W, Socher R, Li LJ, Li K, Fei-Fei L. Imagenet: a large-scale hierarchical image database.In 2009 IEEE conference on computer vision and pattern recognition. 2009; Miami, FL. p p. 248-55


Simonyan K, Zisserman A. Very deep convolutional networks for large-scale image recognition. arXiv. 2014


Zhang MY, Li X, Zhang XH, Liu HG, Li JH, Bao J. Effects of confinement duration and parity on behavioural responses and the degree of psychological fear in pregnant sows. Appl Anim Behav Sci. 2017; 193:21-8


MeGlone JJ, Morrow T. Produetivity and behaviour of sows in level vs sloped farrowing pens and crates. J Anim Sci. 1990; 68:82-7


Hicks TA, McGlone JJ, Whisnant CS, Kattesh HG, Norman RL. Behavioral, endocrine, immune, and performance measures for pigs exposed to acute stress. J Anim Sci. 1998; 76:474-83


Parois SP, Cabezón FA, Schinckel AP, Johnson JS, Stwalley RM, Marchant-Forde JN. Effect of floor cooling on behavior and heart rate of late lactation sows under acute heat stress. Front vet sci. 2018; 5:223


Sapkota A, Marchant-Forde JN, Richert BT, Lay DC. Including dietary fiber and resistant starch to increase satiety and reduce aggression in gestating sows. J Anim Sci. 2016; 94:2117-27


Ramonet Y, van Milgen J, Dourmad JY, Dubois S, Meunier-Salaün MC, Noblet J. The effect of dietary fibre on energy utilisation and partitioning of heat production over pregnancy in sows. Brit J Nutr. 2000; 84:85-94