A Livestock Monitoring System for an Agricultural Startup
- Embedded Raspberry Pi software with a cloud backend
- Image recognition algorithm of up to 98% accuracy
- A multi-screen PWA with data visualization
Discover how Iflexion helped an agricultural startup redesign their livestock monitoring system that now processes images at a 10x higher frequency, uses much less mobile data, and allows farmers to significantly cut costs.
Context
Our customer is an agricultural startup based in Israel. With the globally growing demand for animal protein and the highly competitive market, the company recognized that it needs a more cost-efficient approach to meat production. Given that herd health directly correlates with farming resource-efficiency, the company decided to go for a livestock monitoring system. Since connected sensors for livestock management are too costly to install and maintain, the company opted for an AI-powered image recognition solution.
After starting developing the system on their own, the startup faced the following challenges:
- The software part of their single-board computers (SBCs), responsible for image capturing, needed considerable improvement, as it caused malfunctions and was hard to update.
- The software lacked the data visualization feature.
- In case the internet connection is disrupted, valuable data gets lost forever.
- The image recognition software consumed too much mobile data.
Based on our proven track record of computer vision software development and technology consulting, the customer turned to Iflexion to develop this custom livestock monitoring system.
Solution
The delivered solution is a robust livestock monitoring application that enables real-time identification of pigs’ health. The application monitors pigs’ weight fluctuations with the help of full-HD cameras mounted on the ceiling of every pigpen, Raspberry Pi SBCs, and ML algorithms, and visualizes the received data via an implemented progressive web app (PWA). The customer was developing the application’s backend, while our team was responsible for the frontend part, the image recognition solution, and the software part of the Raspberry Pi single-board computers.
Single-Board Computers
Raspberry Pi SBCs capture pig images at a certain frequency, process them, put them in the queue, and send them to the cloud using mobile data. The customer emphasized the importance of the app’s reliability, meaning that images should be continuously sent to the cloud regardless of internet connectivity issues. Moreover, our team was asked to minimize mobile traffic usage.
To overcome these challenges, our team reworked the software part of the Raspberry Pi SBCs, which allowed for taking images at a frequency of up to one image per second and sending them through regardless of the connection quality, without losing any data.
SBCs ensure sufficient image quality by autonomously editing images in real time. This is especially important in the context of machine learning, as badly-lit images can’t be correctly processed by the algorithm.
By applying the compression algorithm to MPEG4 files, we’ve managed to reduce the size of data sent to the cloud tenfold. As the stream of images is kept compressed, it ensures that each SBC will be able to work productively and accumulate images for several days even with the internet disconnected.
In case the connection is lost, the Raspberry Pi computer starts buffering images. With the cache overflow being the standard issue for video sensors, we implemented the solution — cache looping. If there is no storage left for new images, the oldest ones are getting deleted. We also made sure that video sensors are staying updated by implementing an automatic software update module.
Image Recognition
First, an SBC sends images to the cloud, where our ML algorithm annotates them, highlighting and identifying objects and their parts based on the two colored tags attached to pigs’ ears. The annotations provide information on the number of pigs and their weight. Then this information is processed for generating the final statistics.
However, animals periodically undergo weighing, which can significantly skew the analysis. Stressing the importance of the continuous improvement of data quality, Iflexion’s team implemented a correction mechanism, which allows for comparing annotations with actual data.
The delivered image recognition engine is a Python-based web solution that accesses the recognition pipeline via a REST API. The engine operates two models, one for detecting and cropping tags on pigs’ ears and the other for receiving particular cropped parts of the images and determining the color of the tags.
The first model is a YOLO v3 real-time object detection system trained to identify various categories of objects. Using the customer’s existing dataset, we had to retrain the model from scratch for it to be able to recognize small fragments at a high resolution, which is crucial for accurate identification of tag locations. Our team of Python developers managed to increase the input tensor size, achieving a 92% detection accuracy on average. The second model is a two-layer perceptron trained on six colors, which correctly identifies tag colors in 98% of cases.
The Progressive Web App
To visualize collected statistics, our team enhanced the livestock monitoring system with a progressive web application consisting of three main screens for farm, pen and pig data respectively. Via the screens, a user can instantly access information about the average weight of pigs in each pen or the entire farm, the number of pigs, and the average weight gain per day for the last three days. For each of the indicators, there is initial information on pigs’ weight entered by farm staff, as well as data predicted by a built-in neural network based on the images taken with the SBC camera.
- The farm screen displays the list of all pens as well as general statistics for the entire farm.
- The pen screen provides statistics for all pigs in a particular pen.
- The pig screen provides detailed information about each pig in charts, shows a pig’s latest image, displays its weight fluctuations, and compares it with the pen average.
Most importantly, we implemented an alert system as part of data visualization development, which can detect underweight or missing pigs. This enables farmers to quickly identify potentially ill animals and treat illnesses before they escalate. Alerts can be shown for the pigs of the entire farm, particular pens or pigs depending on the screen that alerts were requested from.
Technologies
The suite of the developed solutions was based on the following technologies:
- The backend was written in C#, leveraging the ASP.NET framework.
- The PWA frontend was created with JavaScript, React, Redux, Material UI, Recompose, Formik + Yup, and nivo. We also employed the i18next internationalization framework for localization purposes.
- Raspberry Pi SBCs work on Python, utilizing the OpenCV library for image processing. The server side uses AWS (ElasticSearch, Amazon S3, Amazon Simple Queue Service (SQS), Lambda) and .NET services.
- The image recognition solution is written in Python using Keras and TensorFlow libraries, and deployed on Amazon SageMaker. Alternatively, the solution can also be deployed on-premises on top of the Nvidia GPU Cloud (NGC) software stack.
Results
Iflexion’s team delivered a custom 24/7 autonomous livestock monitoring system, which allows farmers to proactively adjust pig feeding plans and medication. This sufficiently cuts farming costs, boosts pig growth, and provides actionable data about herd wellbeing in real time. Enhanced by our developers, the Raspberry Pi SBC software now processes images at a 10x higher frequency and uses much less mobile data.
Screenshots
WANT TO START A PROJECT?
It’s simple!