Edge Impulse logo
Blog Post

When Pigs AI: Monitoring Livestock Health with Edge ML

TinyML, Machine LearningThis device combines off-the-shelf hardware and Edge Impulse machine learning to detect respiratory disease in pig populations at a very early stage.

Nick Bild

March 17, 2022

    Throughout modern history, as human populations have increased, technological innovations have kept pace and helped those increasing numbers of people to flourish.  Particularly important have been advances in agriculture and livestock production, which have been instrumental in feeding the growing population of our planet. The pace of these innovations is showing no sign of slowing down in a world where once fantastic technologies are now commonplace and in the hands of everyday hardware hackers like Clinton Oduor.

    In a very clever move, Oduor combined some inexpensive, off-the-shelf hardware with the Edge Impulse platform to develop a device capable of detecting respiratory disease in pig populations at a very early stage. By detecting infected animals very early, it is possible for them to be isolated before they spread their sickness to others and cause a much larger problem.  Failure to contain an outbreak can lead to large financial losses for livestock owners, as well as the possibility of widespread food shortages. Additionally, in the case of viral infections, the more the pathogen spreads, the greater the number of opportunities for mutations to occur that may allow for the species barrier to be breached, which could be bad news for all of us

    Solution architecture

    So, how do you tell a pig with a respiratory infection from a healthy pig? It turns out, the initial symptoms are not so different from what would happen to you and I — a cough is a telltale sign. Unfortunately, picking a small number of pigs coughing out of a cacophony of hundreds of pigs squealing and snorting is no simple task. Fortunately, though, building a machine learning-powered device to do the job for us is not particularly challenging.

    Oduor selected the tiny, but capable, Arduino Nano 33 BLE Sense development board to handle running inferences with the machine learning model, and also to collect audio samples from pigs with the onboard microphone.  An Arduino MKR FOX 1200 was also a part of the build to enable low-power wireless notifications to be sent over the wide range of the Sigfox network. The two boards were hooked together via I2C, then placed in a custom plastic casing that can be mounted in a pigsty.

    The finished product 

    To train a neural network, example data was needed, so Oduor tracked down audio clips of pigs coughing, and also of the normal sounds of healthy pigs. This data was uploaded to Edge Impulse via the data acquisition tool so that further analyses could be conducted. The impulse consisted of an MFCC preprocessing block to extract important features from the audio data, which were then passed into a neural network classifier in the learning block.

    The classifier was trained on the uploaded data after tweaking a few model parameters.  Validation of the model showed an excellent classification accuracy of 99.7%. Such a good result meant that the model was ready for deployment to the physical hardware of the cough detection device. The model was downloaded as an Arduino library that had been optimized by the EON Compiler. The EON Compiler is capable of greatly reducing the RAM and ROM usage of the model, such that it fits comfortably on a highly resource-constrained device, without reducing accuracy.

    Classifying pigs sound with 99.7% accuracy

    After assembling the final device, it was deployed to a pig farm for real world testing.  Oduor has big plans for the future of this cough detector. He plans to collect more data, representing different pig species, and at different developmental stages to make the model more robust in a variety of applications. He is also considering doing some additional work in an attempt to classify different patterns of coughing to determine if specific respiratory diseases can be identified. Slip into your overalls and head over to the project page for all the information you need to build your own pig cough detector.

    Want to see Edge Impulse in action? Schedule a demo today. 


    Are you interested in bringing machine learning intelligence to your devices? We're happy to help.

    Subscribe to our newsletter