Using wireless sensor nodes and machine learning
By Gota Morota and Sook S. Ha
According to the United Nations, the global population is estimated to reach 9 billion by 2050. To meet the growing demand for food, animal agriculture has been intensified over the past several decades.
Production efficiency is achieved by frequent visits to farms or manual reviews of recorded videos to monitor adverse behaviors in pigs. However, these approaches can be subjective and laborious. Further, pigs are social animals and are managed increasingly as large groups. Careful monitoring of individual pigs is even more challenging.
We developed a wireless sensor node (WSN) system for monitoring pigs. The WSN attached to a pig senses acceleration and angular velocity in three axes, and wirelessly transmits the sensed data to a nearby personal computer (PC). The PC uploads the data to a cloud server for the classification of pig behaviors.
The sensor node is placed inside a plastic box and then attached to the pig’s back using a harness. There is a space between the harness and the pigskin, so that the pig would not be annoyed to behave naturally. One camera is mounted at the ceiling, and the other at the side of the pigpen. The video recordings provide ground truth for data analysis. Figure 1 shows the sensor node attached to the pig.
We collected data from four pigs of different sizes and ages for 131 hours over two months. We reviewed the video recordings for 13 hours after the first two days of data collection and classified pigs’ behaviors into seven different behaviors: eating, lying, walking, standing, playing, drinking and sitting. When a pig was out of sight, it was labeled as “unknown.”
Among the seven behaviors, eating and lying activities are the majority with 83%, while drinking and sitting only accounted for 0.73 %. We excluded rare behaviors, such as sitting and drinking as well as unknown ones from the analysis.
We preprocessed the collected dataset to remove outliers, interpolation and standardization. Then, we extracted 224 features from the preprocessed data in time and frequency domains. To evaluate the performance of classification algorithms, we split the dataset into two subsets, 70% of the dataset for training and 30% for testing.
We selected five classification algorithms under various window sizes: support vector machine, k-nearest neighbor, decision tree, naive Bayes and random forest (RF).
The RF algorithm achieved the highest F1 score for four major behaviors consisting of 92.36% in total. The F1 scores of the RF algorithm were 0.98, 0.99, 0.93 and 0.91 for eating, lying, walking and standing, respectively. The optimal window size was 7 seconds for the first two behaviors and 3 seconds for the remaining two.
Analysis of pig behaviors provides great insight into animal welfare and health. Our system demonstrates that automatic, continuous and remote behavior monitoring of pigs is feasible, which can improve the production efficiency in the swine industry.
Morota is an associate professor of quantitative genetics in the School of Animal Sciences and Ha is an assistant professor in the Department of Electrical and Computer Engineering, both at the Virginia Polytechnic Institute and State University.