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.
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.
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.
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.