Services on Demand
Article
Indicators
Related links
- Cited by Google
- Similars in Google
Share
SAIEE Africa Research Journal
On-line version ISSN 1991-1696
Print version ISSN 0038-2221
SAIEE ARJ vol.115 n.4 Observatory, Johannesburg Dec. 2024
Prediction of Oestrus Cycle in Cattle Using Machine Learning in Kenya
Pascal O. AlooI; Evan W. MurimiI; James M. MutuaII; John M. KagiraIII; Mathew N. KyaloII
IDepartment of Mecha-tronic Engineering, Jomo Kenyatta University of Agriculture, Juja, Kenya (email: aloo.pascal@students.jkuat.ac.ke, murimi.evan@eng.jkuat.ac.ke)
IIDepartment of Mechanical Engineering, Jomo Kenyatta University of Agriculture, Juja, Kenya (email: mutuajay@eng.jkuat.ac.ke, mnkyalo@jkuat.ac.ke)
IIISchool of Natural Resources and Animal Resources, Jomo Kenyatta University of Agriculture, Juja, Kenya (email: jkagira@jkuat.ac.ke)
ABSTRACT
Livestock farms in Kenya face pressure to increase productivity amid rising global population. Cattle farming dominates, but small to medium-sized farms struggle with cattle insemination. Currently, visual observation is used for heat detection, with farmers maintaining farm journals. Modern methods utilizing sensors to improve estrus prediction are time-consuming, costly and need constant internet connection. This research proposes a novel approach-the use of an on-controller machine learning algorithm- for estrus prediction in cattle. Motion and temperature data was collected from two zero-grazed multiparous Holstein Friesian cows in Kiambu County, Kenya for 11 months. The data was cleaned and stored. Movement intensity profiles were derived by root-mean-squaring directional accelerometer values and averaging this over time. Validation was performed by observing cow behavior for indicators such as restlessness, mounting, and vulva swelling, with farmer predictions documented in their records. The collected data was then used to train a machine learning algorithm, with several models tested, and a neural network emerged as the best fit. The TensorFlow library facilitated the implementation of the algorithm on a microcontroller, allowing for the development of an animal tag featuring the ML algorithm. Results demonstrated 83.9% sensitivity, 89.0% specificity and 89.5% accuracy in detecting estrus, compared to farmer's visual observation, which had only 37% sensitivity. These findings underscore the potential to integrate machine learning into Precision Livestock Farming for estrus prediction, with prediction occurring directly on the animal tag offline. This integration holds promise for farmers, notably heightened insemination success rates, without necessitating significant financial investment.
Index Terms: Estrus prediction, livestock, machine learning, neural networks, zero hunger.
I. INTRODUCTION
LIVESTOCK forms a significant part of Kenya's economy with food products contributing up to 27% of total agricultural output [1]. Of the 4.7 million Kenyan households that rear livestock, 939,916 rear dairy exotic cattle, 167,625 rear beef exotic cattle, and 2,260,439 rear indigenous cattle, accounting for more than 71% of all livestock [2]. Cattle produce a wide variety of consumable products such as meat, milk, ghee, and other forms of butter, as well as non-food products such as skins, fiber, fertilizer and fuel. In many communities, cattle are also used as a means for capital accumulation, as animals grow in weight and value over time. With world population growing to more than 10 billion in the next 3 decades, and a significant amount of this growth happening in developing countries like Kenya [2], there is increasing demand for cattle products.
Cattle farmers rely on successful insemination to increase their herd sizes and improve quality of the breeds. Successful reproduction requires the insemination of the cow during a defined window related to a period of sexual receptivity (known as estrus) [3]. Detecting estrus is extremely important for any farm as it increases the chances of successful impregnation. This leads to an improvement of herd performance. This metric (herd performance) is evaluated using a metric called the calving interval (CI), that is the period between subsequent calving, measured in months [4]. Cattle farms in Kenya are typically small to medium scale with herd sizes of between 1 and 50 animals. Currently, most processes within the farm are conducted manually, except for milking and slaughtering of animals, which are increasingly getting mechanized [5].Farmers still visually observe and inspect their animals to observe any changes in behavior that may indicate estrus and thereafter call the inseminators or serve the cow with bulls. Veterinary officers and livestock extension officers are widely utilized to further determine whether cattle are on heat. Tail-painting, chin ball markers, use of teaser animals and progesterone tests are also used to get an indication of estrus. Visual observations involve monitoring of the cow by the farmer or a trained observer to try and recognize signs of heat. These signs could include mounting other animals, standing to be mounted, smelling, or following other animals, nervous or excitable behavior and mucous discharge. Furthermore, in some farms, cattle records are maintained where insemination dates, animal cycles and projected calving dates are recorded and monitored. The failure to inseminate their livestock at the right time, or the failure to detect diseases within their herd might lead to significant losses for the farmer. This is because farmers enjoy minimal profit per animal in livestock farming [6] and as such, without precision in livestock monitoring, the little margins that they enjoy are further squeezed.
Several studies have examined the efficiency of prediction of estrus by manual observation. Here, efficiency (also known as sensitivity) is defined as the percentage of possible estruses that were observed over a given period [7]. At-taras et al [8] examined the extent to which estrus could be detected by visually observing cows for climbing behavior. Observations from this study demonstrated that the method was time consuming and achieved an efficiency of 54.7%. In a similar study, Liu and Spahr [9] studied herders detecting estrus by observing for signs during feeding, milking, breeding, and cleaning times. In this study, the manual methods showed an average of 57.6% sensitivity in the prediction of estrus. Miciakova et al [10] and Kastelic [11] both presented that visual observation led to recognition of less than 50% of estrus cycles.
The efficiency arising from visual observation is further affected by the fact that animals are mostly monitored twice daily in typical farm operation. Sometimes, the animal might demonstrate signs of heat at night without the presence of the observer. Research shows that the likelihood of cows demonstrating heat signs between 6 pm and 6 am (night-time) is a staggering 68% [12].
Tail painting and chin ball markers are techniques that involve the use of a pigment applied on the tail of the animal, or on the bottom of the halter of a teaser animal. An attempt to mount another animal would leave a resulting mark on the animal, which can be taken as an indicator of estrus [13]. Teaser animals are male animals that have been vasectomized to prevent their ability to reproduce. These animals are allowed to mingle with the herd. By observation, the animals which they mount can be perceived to be on heat. These methods possess cannot be utilized where the farmer has a single animal or employs a zero grazing system where animals do not interact with each other. In these cases, there is no opportunity for animals to mount each other, and therefore no indicators would appear.
Precision livestock farming (PLF) is defined as the use of information and communication technologies for improved control of fine-scale animal and physical resource variability to optimize economic, social, and environmental dairy cattle farm performance [11]. PLF technologies have developed significantly as a means of ensuring increased output and reduction of losses in livestock agriculture. Methods that utilize technology to varying extents have emerged in recent years. An example is the HeatWatch™ that comprises of a small digital radio transmitter glued to the animal's tail. The system utilizes a LoraWAN [14] network to transmit data each time there is a mount to a small radio receiver in the proximity of the animal. Data is generated on each mount and can be analyzed to derive meaning. Pedometers have also been used to determine estrus in animals. The number of steps taken by a cow in estrus is reported to be about two to four times its regular activity [15]. The use of these pedometer systems coupled with storage and processing technology has allowed the ability to create a benchmark of normal activity against which variations can be observed. These variations are analyzed alongside other factors to determine whether the animal is on estrus. One such example is the Heatime™ system [16] which utilizes a three-dimensional accelerometer on an animal tag. The tag monitors the animal's movement and movement intensity and produces a dimensional activity index. This index is stored or transmitted and can be further analyzed.
Collecting this data is critical as the number of independent readings made by a sensor system can affect the quality of data collected. Excessive readings lead to a bloated dataset, which makes data transmission expensive and leads to increased use of resources such as battery life and transmission costs. The number of readings obtained per unit time are affected by the nature of the specific parameter being measured. For animal motion, multiple readings are required per second to generate an accurate profile of the motion of an animal [17]. For temperature measurement, a few readings a minute may suffice [18].
Most sensors give readings in the form of a range of analog values between a minimum and maximum value. These readings are converted into understandable values that make sense through conversion. For a temperature sensor for example, a look up table can be used to match analog sensor values to the corresponding temperature values [19]. However, in most PLF systems, the trend of change of the value being measured is more consequential than the actual values recorded. Furthermore, the end user is mostly concerned with the prediction derived from the system and does not care about the specific temperature of the animal at any time. Therefore, it may be prudent to avoid doing the laborious conversion and utilize the raw values obtained from the sensor. This reduces on processing time and leads to increased battery capacity. Another example can be seen in Heatime's application. Rather than translate accelerometer readings into understandable metrics, for example, number of head bobs, the sensor readings are simply measured in their raw form and a metric called movement intensity is derived. This is the amount of movement recorded per unit time, irrespective of its direction or nature [20]. By averaging over extended periods of time, the effect of abnormal values such as spikes, errant readings or jerked animal movements on the data can be minimized.
PLF systems are often low power remote systems due to their areas of application. Transmission of the data collected from sensor systems is critical to the success of these systems. However, due to the limited battery capacity and the need to reduce on transmission costs, PLF systems are seeing more and more use of edge computing. Intflow™ for example, utilizes on-site cameras and an on-site AI capable device. The cameras record eating and motion habits of the animals being monitored. Rather than transmit this information to an internet-based server, the information is transmitted to a local device. The device then generates prediction based on the input parameters. This prediction is what is transmitted to the output and farmer's devices [21].
The use of Machine Learning (ML) in livestock management has grown significantly in recent years. This technology allows for better inferencing and prediction of animal conditions based on raw data. ML allows for the identification of patterns (that would otherwise be missed) and association of these patterns with different conditions. Milan et al [22] demonstrated the usefulness of ML algorithms in the detection of animal behavior. This research shows that even in the same environment, different animals will demonstrate different characteristics due to biological differences. As such the learning characteristic of ML applications makes it easy to analyze each animal individually and derive a prediction.
Typical animal monitoring systems that exist utilize a cloud-based infrastructure to generate a prediction. Animal tags can be used to collect data, and relay this through a gateway or directly to the internet, where analysis of the data happens. The output is published on a dashboard visible to the farmer [23]. For the farmer, this necessitates the purchase of not only the animal tag, but the communication infrastructure, an internet connection as well as access to the specialized dashboards, all of which are costly. Manufacturers will also often impose high minimum order quantities, sometimes as high as 100 tags, rendering it inaccessible for small-scale farmers. Manual approaches currently utilized in the detection of estrus are time-consuming and labor intensive yet lack sufficient accuracy to be reliable. There is need to employ PLF solutions in the detection of estrus for local farms. However, the technological solutions available in the market are expensive and inaccessible to most farmers especially in developing nations. This research aims to address these gaps by proposing a cost-effective alternative solution that utilizes an ML algorithm in the prediction of estrus. It explores a novel approach by implementing an on-controller algorithm aimed at ensuring minimal cost of technology while greatly improving the sensitivity and accuracy of predicting the estrus period of cattle, effectively increasing the profitability of livestock farmers. This study is part of a larger research on the overall prediction of health of animals using ML and the Internet of Things (IOT).
II. METHODOLOGY
A. Overview
This section presents an account of the methodology employed in the study. Due to a fundamental scarcity of publicly accessible datasets related to livestock health that could be used to train ML algorithms, it was necessary to develop an initial data collection system to facilitate the collection of initial data that could be used for training of ML algorithms. This collected data was then processed into a machine-learning dataset. Several algorithms were tested, and based on several design criteria, a functioning ML algorithm was selected. A new system was designed with the ML algorithm incorporated within the microcontroller system. This system was deployed on the cattle and estrus predictions obtained. These results were compared with other currently utilized methods of estrus detection. An overview of these steps is shown in Figure 1.
Observations for this study were conducted in a dairy farm in Kiambu County, Kenya. Due to financial and time constraints, data was collected from two multiparous (5 counts, 4 counts) Holstein Friesian cows aged 7 and 8 years respectively. The cows were enrolled in the study between July 2022 and August 2023. The cows were housed in a covered common free stall pen with grooved concrete alleys for waste and water direction. This protected the animals from extreme wind or weather. Both animals had continuous access to water in each pen and shared a feeding area. Both cows were fed and milked daily, with milking happening twice a day between 06:00 HRS - 08:00 HRS and between 16:00 HRS - 18:00 HRS. Both animals were fed on the same food and diet throughout the study. Similarly, both animals were examined by a veterinary officer to exclude pregnancy or any major ailments before the study began. During the entire duration of the study, the animals were not inseminated or allowed access to a male for purposes of mating. Only after adoption of the technology would the animals be served when they came on heat. All experimental activities undertaken in the study were non-intrusive in nature and did not cause any pain, distress, prolonged discomfort, or bodily harm to the animals. The study was conducted in accordance with the Prevention of Cruelty to Animals Act (Cap. 360) of the Laws of Kenya.
B. System Design
An initial system was developed to collect animal data. It was observed that several parameters could be collected from the cattle that could predict estrus [24]. These parameters were compared and scored based on several factors including ease and cost of measurement, possibility of continuous monitoring of the parameter and how intrusive the measurement would be. This scoring is shown in Table 1.
By merit, body temperature and activity level were settled on as the parameters to be studied in this study. An animal tag system was then designed, to be placed on the animal, to measure and record this data. The key design considerations that the system needed to meet included:
1) Design consideration 1: The system must be able to read temperature and movement data continuously on the animal.
2) Design consideration 2: The system must be cheap enough to be economically viable in a livestock farm setting.
3) Design consideration 3: The tag must be light and comfortable enough to be carried by the animal without significant stress.
4) Design consideration 4: The system must be able to remain powered for a sufficient duration to allow for continuous monitoring.
5) Design consideration 5: The system must be dirt and rust resistant and should have an animal-friendly design.
To achieve these design considerations, an animal tag was built on top of Arduino Pro Micro™, a miniature microcontroller system preferred due to its small size(18mm by 48mm), cheap cost (around 8 USD) as well as function-ability. The tag utilized the LM35 temperature sensor [25] to obtain temperature readings from the animal, and an ADXL ultra-low power, 3-axis accelerometer to record the animal's motion. A local SD card shield was utilized with a memory card housed on the tag. A real time clock (RTC) system was included to ensure the system kept record of time. The various components were assembled as shown in Fig. 2.
C. Power Calculations
As per design considerations 1 and 4, it was necessary that the system could remain powered continuously to provide uninterrupted data. A worker on the farm was present at the cow-pen twice a day for milking, feeding and cleaning, and as such, could change the batteries once on the device within this interval. A safety factor of 2 was applied, and the system was therefore designed to stay on for 2 days (48 hours) before recharging or replacing the battery pack. The power consumption of the tag was tabulated from the consumption of the individual components as shown in Table II.
Battery capacity, C (mAh) was calculated as shown in (1)
where P was power consumption (mW), T was the time the system needed to stay on, N was the number of batteries and V was the voltage of each cell. For a 2 - cell battery pack, each 3.7 volts, 3900 mAh was the required capacity to sufficiently run the system. 5000 mAh batteries were therefore selected to power the tag.
D. Tag Positioning
It was imperative to appropriately position the tag to ensure that sufficient data was collected. Various positions were tested and compared based on the following criteria:
• Level of comfort to the animal.
• The presence of a thermal window [26] that would allow for accurate temperature measurements.
• Attachment of temperature sensor to the animal body.
• Exposure to dirt and possible microbial contamination.
• Accuracy of movement data obtained.
Temperature measurement at a thermal window allowed for the concise measurement of body temperature. At these windows, there would be minimal influence of external factors on the temperature measurement obtained [27].
Due to availability, tag position testing was done on a herd of Zebu cattle of similar size and stature as the animals under study. Three body positions were tested. These were: the cow's neck (collar), the cow's hind leg, and the cow's head and nasal area (halter). Casings were designed for each of these positions using Computer Aided Design (CAD) software and later printed using 3D printing technology. Overall, each tag cost around 50 USD. For the neck position, a simple cuboid design of 100 mm (length) by 100 mm (width) by 50 mm (height) was realized for the tag casing. A groove was inserted at the bottom for a collar to pass through and hold the tag in place. A slot was designed for the temperature sensor. This was designed to be in contact with the cow's skin to ensure valid temperature readings can be obtained. The accelerometer was placed within the compartment on the circuit board. Fig. 3a. shows the positioning of the tag on the cow's neck.
It was observed within this position that the tag could not be tightened extremely as it would hinder the food passage (oesophagus) and airway (trachea) of the animal. As such, the tag remained loosely hanging on the neck of the cow. This hindered the ability to collect temperature data as the sensor failed to properly adhere to the skin of the cow. For the hind leg position, a curved design was realized. This created a more ergonomic fit for the animal, with the tag taking the natural shape of the cow's hind leg. Similar to the neck design, the temperature sensor was wedged within the portion of the system that maintained physical contact with the cow. The accelerometer also retained its position within the compartment on the circuit board. The tag was printed in Thermoplastic Polyurethane (TPU) material which is flexible, to allow for the design and subsequent positioning as shown in Fig. 3b. With the halter position, a more flexible design approach was adopted. The length of the halter allowed for spacing out of the tag components. The temperature sensor was placed on the tip of a nose ring fixture such that it maintained constant contact with the nasal passage. TPU material was used to ensure the tag did not injure the cow's nose. The battery pack was also positioned further back on the halter, so the tag did not weigh too much at a single point. The positioning is shown in Fig. 3c.
Table III shows the results obtained from these positioning tests. These were graded on a scale of 1 - 5 with 1 representing the least ideal situation and 5 representing a perfect fit. These ratings were made by means of subjective observation by the authors of the study. The particularly low score in comfort at the hind leg was due to the resting position of the animal. When the animal assumed a sternal recumbent position, the placement of the tag would create discomfort as it was pressed up against the cow's abdomen. Attachment of the sensor was particularly poor at the neck area due to the constant falling of the sensor due to the narrow width of the animal's neck ridge. The halter was selected as the final positioning for the data collection system due to its overall merit as shown.
E. Data Collection
Data related to body temperature and motion was collected from the sensor system. X, Y and Z positions were collected from the accelerometer, and instantaneous acceleration values in the three axes (labelled as 'Ax', 'Ay' and 'Az') respectively. These values were obtained by an accelerometer placed at a fixed position on the halter. Two temperature values were obtained: the body temperature (named tempi) obtained through a temperature sensor attached to a nose ring within the nasal cavity of the cow, and ambient temperature (named tempi) obtained through a temperature sensor exposed to the environment. Both temperature sensors had ensured accuracies of 0.5°C at ambient temperatures. An Arduino program was written that performed conversion of the values received from the analog temperature sensor into values of temperature by applying (2)
where tempi was the temperature value desired and val was the analog value obtained from the sensor. The raw value was divided by 1024 and multiplied by 5 to convert it from an analog reading (from 0 - 1023) to a voltage reading (0 - 5V). The selected sensor had a 500-mV offset to allow for negative temperature readings. This offset was compensated for by subtracting 0.5. The value was then multiplied by 100 to obtain a temperature value in degrees Celsius. This reading was comparable to the reading obtained by a digital thermometer with an accuracy of 0.1°C (Mendy™ Handy TMP-02 Digital Thermometer). Environmental temperature was obtained directly from an onboard temperature measurement unit on the Inertial Measurement Unit. The trends in change of ambient temperature were used to observe for any erratic readings or spikes in body temperature measurement due to wind or other weather factors.
The time and date stamp were collected from an onboard real-time clock (RTC). This gave a date-time value in the format YYYY-MM-DD HH-MM-SS. Data was obtained at a resolution of 10 readings per second to allow enough resolution for the accelerometer to indicate the animal's head movement. This data was saved into a text file located on an on-board SD card. Data was collected over an 8-month period. As the cows were located in the same pen, it was possible to observe visual estrus cues demonstrated during interaction.
F. Data Analysis
Data was periodically collected from the on-board SD card and assembled into a collection of CSV files. A python program was written to store this data in a MySQL™ database. First, the accelerometer direction values were averaged out to obtain an overall value for acceleration. Due to the immense amount of data being written at a go, queueing was executed to ensure that no values were lost, and the database connection was maintained without any data loss. The data was then visualized using Python bokeh plots. Here, erratic values were observed and removed. The gaps created were filled by interpolation to ensure a continuous dataset. Erratic values occurred to a number of factors including the temperature sensor dislodging, system shut down in the event of battery depletion or falling off as well, errors in the RTC system and system reset at the point of battery changeover.
Once cleaned, acceleration data was further averaged to obtain second, minute, hourly and daily averages of acceleration. This was used to develop movement intensity profiles, similar to Heatime's application. The data was then loaded onto a Python data-frame from the SQL database using the Pandas "read_sql" function. The data was then split into training and test data. The overall dataset used contained 10,457,267 rows. This was split into 7,000,000 values for training data (around 67%) and 3,457,367 values for test data (around 33%). It was observed that the training data had at least 7 distinct periods of estrus Various ML models were applied to the training data, and then tested on the rest of the dataset. The standard inputs for the models were the date-time values, acceleration and position values, and the temperature variables. The outputs were the "mens" values derived from prediction based on value averaging. The test data had four periods of estrus.
G. ML Algorithm Selection
Various ML algorithms were explored to select an optimal ML algorithm based on the available dataset and deployment conditions. This would be done by evaluating the performance of each algorithm on the test dataset as well as evaluating running time, resource consumption as well as portability of each model. The different algorithms considered are discussed below:
1) Linear Regression: Linear regression was applied on the data using the LinearRegression() function from the sMeam.Unear_model Python library. From this application, an output data set containing predictions was generated. This was compared to the provided dataset. The accuracy, A of the prediction was then obtained by utilizing (3).
where MSE was the Mean Squared Error and y_range was the difference between the maximum and minimum values of the dependent variable. The results obtained are shown in Table IV.
2) Random Forest Classifier: The random forest classifier is an extension of decision tree classifiers that uses multiple decision 'trees' to improve prediction accuracy. It can handle both continuous and categorical variables [28]. The data was split into four datasets:
X_train: A subset of the training dataset that included the input variables of acceleration, position, body and ambient temperature.
X_test: A subset of the dataset containing input values of acceleration, position, body and ambient temperature that was used to test the algorithm.
Y_train: A subset of the training dataset that included data on whether the animal was undergoing oestrus.
Y_test: A subset of the dataset containing oestrus data that was used to test the algorithm.
The model was applied to the dataset, and a dataset of predicted outcomes was generated. This dataset was compared to the true labels of the test set. The ratio of the number of matches to the total number of elements was computed as the accuracy score. This algorithm gave an accuracy score of 85.3%.
3) Logistic Regression: Similar to the Random Forest classifier, the data was split into four datasets X_train, X_test, Y_train and Y_test. The logistic regression algorithm was applied to the training datasets in order to develop the model. Once trained, the model was run on the test data to produce predictions. The algorithm gave an average accuracy of 96.2%
4) Neural Networks (Multi-layer Perceptron (MLP) Classifier): A neural network algorithm with multiple layers from the scikit-learn library was tested on the dataset. The model was constructed with the inputs being the acceleration, position and temperature values. Various parameters were varied including the number of hidden layers, nodes in each layer, and the maximum iterations permitted.
It was observed that an increase in number of nodes per layer led to an increase in accuracy to an extent after which there was a gradual and substantial decrease in accuracy. The same effect was observed with time, with computing time reducing first before exponentially increasing as shown in Fig. 4a. It was observed that a change in the maximum number of iterations allowed for the solver to converge led to no significant change in accuracy, despite an increase in time taken by the model to run as shown in Fig. 4b. At optimal parameters (2 layers, 40 nodes per layer and a max iteration value of 3000), this algorithm yielded an accuracy of 93%.
5) Neural Networks (Sequential with Binary Classification): The neural network algorithm was improved by using a sequential (fully connected) neural network. The TensorFlow library was used, which provided for more flexibility. This algorithm allowed for more tuning of hyper parameters with better management of each layer. The results of this algorithm were much better with an accuracy of 99.36%. From this, neural networks were considered as the model of choice.
H. Implementation of ML-Enabled Controller
The suitable model was then converted to a TensorFlow Lite™(TF Lite) model by using the TFLiteConverter module from the TensorFlow library. The TF Lite model is a more compact and efficient model that allows for deployment on resource - constrained devices [29]. The model occupied disk space of only 2172 bytes, roughly the equivalent size of a basic Arduino sketch. The model file was then converted into a C source file using the xxd tool from the vim-common package. The resultant file contained a C array that held TF Lite model's binary data making it possible to embed the module on the microcontroller. The Arduino Nano BLE Sense microcontroller unit was used. This board was an ideal choice as it intrinsically supports ML applications. Further, with 1 MB of program storage and extensive RAM, the microcontroller unit could run the ML algorithm. The board has an integrated Inertial Measurement Unit (IMU) and an internal temperature sensor [30], significantly reducing the circuit footprint needed to realize the animal tag. The system arrangement is as shown in Fig. 5.
An Arduino program was written for the microcontroller. The TensorFlow Lite model was loaded into the interpreter within the program, with tensors for input and output data were defined. These tensors were assigned acceleration and temperature for input, and a "mens" reading indicative of estrus for output. Acceleration data was then obtained from the onboard accelerometer while temperature data was collected from the body temperature sensor. Acceleration magnitude was obtained from the raw readings by averaging. An inference of the ML algorithm was run after every loop iteration and a prediction was generated. This prediction was 0 if the animal is not predicted to be in estrus, and 1 if the animal is predicted to be in estrus. To avoid erratic predictions, the number of positive predictions were counted over hourly periods, and a positive output was only registered when this value surpassed a trigger threshold. This threshold was varied, and the results studied.
I. Model Retraining
To ensure continued improvement of the model, a retraining schedule was maintained. New collected motion and temperature data was pre-processed like the original training data monthly. The previously deployed TensorFlow lite model was loaded, and the new data appended to the existing dataset. The model was then retrained with the updated dataset maintaining the same architecture and similar hyper parameters. The models' weights were then updated with the new results, and the model was converted back into a TensorFlow Lite format before being uploaded back into the microcontroller. The results were observed over the duration of the validation phase.
III. Results and Discussion
The study involved the accumulation of training data over an 8-month period, followed by validation tests spanning 3 months between March 2023 and July 2023. Throughout the initial 8-month phase, both cow temperature and motion intensity data were captured using an animal tag affixed to the cow's halter. The data was sampled at a frequency of 10 Hz, allowing for the collection of a substantial volume of raw accelerometer data. This high resolution facilitated the creation of comprehensive motion intensity profiles, which, in turn provided a foundation for categorizing the amount of cow movement.
Each data reading was accompanied by a corresponding timestamp obtained from the RTC module. The captured data was stored locally on an onboard SD card and retrieved manually on a weekly basis through a swapping process to support the training of the ML algorithm. To ensure continuous operation, the system was sustained by changing the batteries daily whenever the farm worker was present in the cowshed. It was ensured that the change-over period was under 1 minute to minimize blank data within the dataset. The data in these periods was filled in by interpolation from neighbouring data points. since predictions were averaged out over hourly periods, the effect of this change-over period on the accuracy of the data was observed to be minimal.
A sample of the data collected over a specific 24-hour period is shown in Fig. 6. A farmer's record was maintained concurrently. During instances when the cow exhibited visual signs of estrus i.e. restlessness, attempts to mount or redness and swelling on the vulva, a veterinary officer was called to determine the status of estrus based on physical examination. These findings were then correlated with sensor data collected by the animal tag. observation of the raw data demonstrated noticeable differences in motion intensity between the periods of estrus and similar periods compared outside estrus. outside of estrus, the average value of movement intensity during the day was observed to be 0.4 m/s-2 /s while this reduced to an average of 0.28 m s-2 s during the night. During estrus, it was observed that the average movement intensity was slightly higher, with this value rising to about 0.6 m/s-2 /s as shown in Fig. 7. Further, there were also clear variations in body temperature. It was observed that there was temperature deviated by an average of 1.85% during periods of estrus in comparison with periods of no estrus as shown in Fig. 8. The combined changes in motion intensity as well as temperature variations were used as a basis for classification of estrus windows. The study effectively established the adequacy of temperature and motion data in accurately predicting estrus in cattle. Notably, these parameters can be measured through cost-effective and non-intrusive methods, which opens up substantial possibilities for enhancing estrus prediction. This gains credence from the observed correlation between significant shifts in motion intensity and body temperature and the initiation of estrus. Similar variations have been reported in several studies across literature. Wang et al [31] observed body temperature increases of up to 3% in cows during estrus observed by thermal infrared imaging. Suthar et al [32] also observed that cows housed in a tie stall demonstrated higher fluctuations in body temperature during estrus. The study hypothesized that this was attributed to higher activity and increased blood flow demonstrated during estrus.
Sensor positioning was also observed to be critical to the assurance of reliable data. To achieve successful prediction, it was observed that it was critical to ensure firm contact of the temperature sensor with the animal's skin. Better motion profiles were observed from capturing head movement data as compared to capturing movement data from the neck or leg area. This could be attributed to the various activities carried out that can be translated into head movement including eating, movement and restlessness.
Once validated by veterinary examination, this data was marked for periods of estrus and used as a basis for the classification of the dataset used to train the ML algorithm. It was observed that peak estrus most often occurred between 20:00 and 04:00. There were minimal occurrences of peak estrus between 04:00 and 08:00 and 16:00 and 20:00, the times when the farm worker was likely to be observing the cow as shown in Fig. 9. This is comparable to studies such as Parish et al [12] and demonstrates the need to advance estrus detection by use of technology.
Several ML algorithms were applied on the training data as discussed in the methodology section. The performance of these algorithms is shown in Table V.
The sequential neural network approach stood out as the preferred choice due to its high accuracy for the given dataset. The choice was further reinforced by the model's compatibility with the TensorFlow and TensorFlow Lite frameworks that provided the platform for deployment of the ML algorithm on the microcontroller device. Once deployed, the microcontroller-enabled animal tags remained on the animals for a period of three months. During this period, an additional data point was recorded to indicate whether the ML algorithm had predicted estrus. The acquired data was stored on the onboard SD card and collected manually on a weekly basis. In cases where the tag signalled a positive estrus event, an on-board LED lit up to give the farmer an indication of estrus. A veterinary officer was notified, and estrus was verified through physical examination. The results of the algorithm were compared to observations from a farmer's journal maintained concurrently, as well as with manual data analysis from the raw data collected from the sensor system. During the validation period, there were four observed estrus cycles for cow 1 and five observed cycles for cow 2. The estrus windows within these cycles were observed and verified by a veterinary officer and marked by correlation with the raw dataset. The ML algorithm deployed was evaluated based on several performance metrics. These are: Sensitivity, (Sn) which was calculated as TP/(TP+FN) x 100; Specificity (Sp) calculated as TN/(TN+FP) x 100 and Accuracy (Acc) calculated as (TP+TN)/(TP+TN+FP+FN) x 100 where TP = true positive, TN = true negative, FP = false positive, and FN = false negative. The results were as shown in Table VI. TP, FP, TN, and FN values were obtained from sensor data and divided by 3600 to obtain hourly values. The algorithm demonstrated an increase in sensitivity across subsequent cycles for both cow1 and cow2 as shown in Fig. 10.
Estrus occurs for a relatively short duration, typically around 8 to 24 hours, whereas for most of the rest of the cycle, which spans approximately 18 to 24 days, cows are not in estrus [33]. This high ratio of non-estrus to estrus periods is a contributing factor to the relatively stable and high specificity values observed in the results. Overall, the algorithm had an average accuracy of 89.50% in the prediction of estrus.
The values obtained were compared to the farmer's prediction of estrus through farm records. Here the farmer maintained a record of visual cues of estrus observed during milking and cleaning. The parameters of the farmer's predictions were marked as:
• True Positives (TPs) - Periods within estrus when the farmer observed and recorded corresponding visual cues.
• True Negatives (TNs) - Periods outside of estrus when the farmer recorded a lack of any corresponding cues.
• False Positives (FPs) - Periods outside of estrus when the farmer observed and recorded visual cues.
• False Negatives (FNs) - Periods within estrus when the farmer recorded a lack of any corresponding cues.
FPs occurred due to a possible number of reasons including cow sickness, abrupt movements from disturbances or abnormal shifts in ambient temperature. In one notable instance, the farmer noticed other signs of sickness on one of the animals including a lack of appetite and restlessness. Upon inspection, a veterinary officer confirmed that the animal was ill and prescribed a remedy for it. At around that time, the sensors pushed out a high concentration of FPs on estrus prediction. Similar to the ML algorithm, the farmer's prediction efficiency was calculated for each cycle period and for each cow. The results were averaged out and it was observed that the farmer was able to predict estrus with an average efficiency of 37.29%. The developed ML-enabled tag demonstrated far better prediction of estrus than visual observation. These results were further compared with other experiments conducted on dairy animals of similar breed and husbandry as shown in Table VII [34].
It can be observed that the on-controller ML algorithm developed in this study realized results that were better than most available commercial methods. Further, a discernible time lag was observed between the commencement of estrus (as per raw data) and the initiation of ML prediction, as well as between the conclusion of estrus and the cessation of ML prediction. This lag was graphed over time as shown in Fig. 11.
Notably, this overlap displayed a noticeable reduction over successive cycles for both observed animals. This progressive diminish demonstrated advancement in the performance of the ML algorithm. Findings of the current study show that the ML algorithm had a lower accuracy operating on live data as compared to the accuracy achieved on the training dataset. This can be attributed to the cleaning and pre-processing activities which ensured that training data was of a suitable nature for the ML algorithm. In live operating conditions on the microcontroller, the ML algorithm was met by raw data including spikes, aberrant data points and gaps. This affected prediction while under deployment. Further, the improvement in sensitivity in subsequent cycles could be attributed to the retraining of the model. Through iterative training, the ML algorithm continued to adapt to the evolving patterns and dynamics within the data. Retraining holds immense significance in ML as it enables the algorithm to adjust and refine its internal representations, adapting to the dataset better over each iteration. In the prediction of estrus, the concept of model retraining is relatively new and has not been extensively explored. The implications of this work extend beyond estrus prediction. The successful implementation of ML algorithms to predict estrus showcases the potential to scale into applications in prediction of overall animal health. The correlation between various physiological parameters and health conditions has over time been well established, and the adaptation and finetuning of ML algorithms similar to this study can be implemented for early disease detection, timely intervention and overall animal welfare. Zhou et al [35], for example, combined variables from physical activity with milk yield, rumination time and electrical conductivity of milk to predict common health disorders such as clinical mastitis and lameness. The novel implementation of on-controller ML algorithms as demonstrated by this research is a powerful contribution to the area of animal health prediction. This approach addresses the efficiency concerns associated with the current approaches that involve data transmission to the cloud. This method drastically cuts down on the need for constant data streaming, leading to reduced transmission costs, minimized latency and near real time prediction. By processing the data locally on an embedded device, the system can significantly reduce the reliance on high-bandwidth connections and costly cloud infrastructure.
IV. CONCLUSION
This study clearly identified correlations between body temperature and movement intensity with estrus in cows. As was noted, there was an average deviation of 1.85% in body temperature during periods of estrus in comparison with non-estrus periods. Similar deviations were also observed in motion intensity, giving a good basis for the classification of estrus.
The accuracy of the temperature sensors used was considered a limitation in this study. To increase the reliability of the readings obtained, the study relied on observation of the trend of change of temperature rather than individual readings. This proved satisfactory in the identification of variations due to estrus. Further iterations would help to improve the overall design of the experiments used and the rate of erroneous values.
This study also demonstrated that it is possible to utilize ML techniques in the prediction of estrus cycles in animals with significantly higher performance than existing methods. Further, the study successfully demonstrated the novel implementation of an on-the-controller ML algorithm to generate prediction real-time and without the need to transmit any data. This implementation presents an opportunity for significant cost reduction for farmers employing PLF systems.
Further work can be done to extend the study to a larger group of animals, as well as more human experts, in order to observe the results obtained from running on-controller algorithms for estrus detection. The implementation of long range, low-power communication protocols such as LoRaWAN can provide a more robust means of notification than is detailed in this study, and can provide real-time tracking of estrus conditions for the farmer.
Research can also be done to refine algorithms designed to run offline on lean microcontroller systems designed for such applications as estrus detection. This could involve exploring advanced ML techniques; or feature engineering to ensure the deployed algorithms are as lean as possible. Future endeavors could also explore expanding the algorithm's capabilities to broader monitoring of general animal health and behavior. Multi-modal sensor data could be integrated to enable comprehensive real-time or near real-time monitoring of animal health, thus allowing farmers to make quick informed decisions on their farms. The retraining of ML models for improved performance is also an area that could benefit from more research as the iterative retraining of models is pivotal to sustain their effectiveness within dynamic environments. More work can be done to explore the possibilities of performing iterative training in edge environments. By virtue of the enhanced success rates in estrus prediction, farmers stand to benefit significantly from this technology through optimized insemination practices, leading to improved reproductive outcomes.
References
[1] Food and Agriculture Organisation of the United Nations, "Africa sustainable livestock 2050 - Country Brief Kenya," Food and Agriculture Organization of the United Nations, techreport, Jan. 2017. [Online]. Available: http://www.fao.org/3/a-i7348e.pdf
[2] M. Roser, H. Ritchie, and E. Ortiz-Ospina, "World population growth," Our World in Data, 2013, https://ourworldindata.org/world-population-growth.
[3] L. Senger P., Pathways to pregnancy and parturition. Current Conceptions, 2003.
[4] R. S. Youngquist, Current therapy in large animal theriogenology, 2nd ed., R. S. Youngquist and W. R. Threlfall, Eds. Saunders Elsevier, 2007.
[5] D. Njarui et al, "A comparative analysis of livestock farming in smallholder mixed crop-livestock systems in kenya: 1. livestock inventory and management," Livestock Research for Rural Development, vol. 28, no. 4, Apr. 2016. [ Links ]
[6] Pica-Ciamarra, U., Baker, D., Morgan, N., Zezza, A., Azzarri, C., Ly, C., Nsiima, L., Nouala, S., Okello, P. and Sserugga, J. 2014. Investing in the livestock sector: Why good numbers matter: A sourcebook for decision makers on how to improve livestock data. Rome, Italy: FAO [ Links ]
[7] G. Heersche and R. L. Nebel, "Measuring efficiency and accuracy of detection of estrus," Journal of Dairy Science, vol. 77, no. 9, pp. 27542761, sep 1994. [ Links ]
[8] E. At-Taras and S. Spahr, "Detection and characterization of estrus in dairy cattle with an electronic heatmount detector and an electronic activity tag," Journal of Dairy Science, vol. 84, no. 4, pp. 792-798, apr 2001. [ Links ]
[9] X. Liu and S. Spahr, "Automated electronic activity measurement for detection of estrus in dairy cattle," Journal ofDairy Science, vol. 76, no. 10, pp. 2906-2912, oct 1993. [ Links ]
[10] M. Miciakova, P. Strapak, I. Szencziova, E. Strapakova, and O. Hanusovsky, "Several methods of estrus detection in cattle dams: A review," Acta Universitatis Agriculturae et Silviculturae Mendelianae Brunensis, vol. 66, no. 2, pp. 619-625, may 2018. [ Links ]
[11] J. P. Kastelic, "Computerized heat detection," Advances in Dairy Technology, vol. 13, pp. 393-402, 2001. [ Links ]
[12] R. C. V. Jane Parish, Jamie E. Larson, "Estrus (heat) detection in cattle," Mississipi State Univesity Extension Service, no. 01, 2016. [Online]. Available: https://extension.msstate.edu/sites/default/files/publications/publications/p2610_0.pdf
[13] K. L. Macmillan and R. J. Curnow, "Tail painting - a simple form of oestrus detection in new zealand dairy herds," New Zealand Journal of Experimental Agriculture, vol. 5, no. 4, pp. 357-361, dec 1977. [ Links ]
[14] A. Augustin, J. Yi, T. Clausen, and W. Townsley, "A study of LoRa: Long range & low power networks for the internet of things," Sensors,, vol. 16, no. 9, p. 1466, sep 2016. [ Links ]
[15] J. B. Roelofs, F. J. van Eerdenburg, N. M. Soede, and B. Kemp, "Pedometer readings for estrous detection and as predictor for time of ovulation in dairy cattle," Theriogenology, vol. 64, no. 8, pp. 1690-1703, nov 2005. [ Links ]
[16] P. Gillund, T. B0rsheim, P. Groseth, and K. Karlberg, "Heatime (tm) activity monitoring for heat detection in beef cattle in norway," 08 2012, pp. 68-68.
[17] J. Kamminga, L. M. Jansen, N. Meratnia and P. J. M. Havinga, "Horsing around - a dataset comprising horse movement, Data, vol. 4, no. 4, p. 131, 2019
[18] N. Mansbridge, J. Mitsch, N. Bollard, K. Ellis, G. Miguel-Pacheco, T. Dottorini, and J. Kaler, "Feature selection and comparison of machine learning algorithms in classification of grazing and rumination behaviour in sheep," Sensors, vol. 18, no. 10, p. 3532, oct 2018. [ Links ]
[19] L. E. Bengtsson, "Lookup table optimization for sensor linearization in small embedded systems," Journal of Sensor Technology, vol. 02, no. 04, pp. 177-184, 2012. [ Links ]
[20] A. G. Bonomi, A. H. Goris, B. YIN, and K. R. Westerterp, "Detection of type, duration, and intensity of physical activity using an accelerometer," Medicine and Science in Sports and Exercise, vol. 41, no. 9, pp. 1770-1777, sep 2009. [ Links ]
[21] E. Wu, "Edge AI at the farm: precise livestock management helps farmers optimize livestock productivity," June 2022. [Online]. Available: https://www.seeedstudio.com/blog/2022/07/01/edge-ai-at-the-farm-precise-livestock-management-helps-farmers-optimize-livestock-productivity/
[22] H. F. Milan, K. M. Perano, and K. G. Gebremedhin, "Survey and future prospects in precision dairy farming," in 10th International Livestock Environment Symposium (ILES X). American Society of Agricultural and Biological Engineers, 2018.
[23] U. S. Abdullahi, M. Nyabam, K. Orisekeh, S. Umar, B. Sani, E. David, and A. Umoru, "Exploiting iot and lorawan technologies for effective livestock monitoring in nigeria," 04 2020.
[24] S. Reith and S. Hoy, "Review: Behavioral signs of estrus and the potential of fully automated systems for detection of estrus in dairy cattle," Animal, vol. 12, no. 2, pp. 398-407, 2018. [ Links ]
[25] Texas Instruments, "LM35 Precision Centigrade Temperature Sensors," SNIS159H datasheet, Aug. 1999 [Revised Dec. 2017]
[26] Mota-Rojas, D., Pereira, A., Wang, D., Martínez-Burnes, J., Ghezzi, M., Hernandez-Avalos, I., Lendez, P., Mora-Medina, P., Casas, A., Olmos-Hernandez, A., Domínguez, A., Bertoni, A. & Geraldo, A. Clinical Applications and Factors Involved in Validating Thermal Windows Used in Infrared Thermography in Cattle and River Buffalo to Assess Health and Productivity. Animals. 11, 2247, 2021. [ Links ]
[27] J. Akin, "Homeostatic Processes for Thermoregulation," Nature Education Knowledge, vol. 3, no. 10, p.7, 2011. [ Links ]
[28] L. Breiman, "Random forests," Machine Learning, vol. 45, no. 1, pp. 5-32, 2001. [ Links ]
[29] F. Zaman, "Why Use TensorFlow Lite," in TensorFlow Lite for Mobile Development, Apress, 2020
[30] A. Kurniawan, IoT Projects with Arduino Nano 33 BLE Sense: Step-By-Step Projects for Beginners. Apress, 2021.
[31] Z. Wang, S. Wang, C. Wang, Y. Zhang, Z. Zong, H. Wang, L. Su, and Y. Du, "A non-contact cow estrus monitoring method based on the thermal infrared images of cows," Agriculture, vol. 13, no. 2, p. 385, feb 2023. [ Links ]
[32] V. Suthar, O. Burfeind, J. Patel, A. Dhami, and W. Heuwieser, "Body temperature around induced estrus in dairy cows," Journal of Dairy Science, vol. 94, no. 5, pp. 2368-2373, may 2011. [ Links ]
[33] M. Crowe, "Reproduction, events and management | estrous cycles: Characteristics," in Encyclopedia ofDairy Sciences. Elsevier, 2011, pp. 428-433.
[34] L. Mayo, W. Silvia, D. Ray, B. Jones, A. Stone, I. Tsai, J. Clark, J. Bewley, and G. Heersche, "Automated estrous detection using multiple commercial precision dairy monitoring technologies in synchronized dairy cows," Journal ofDairy Science, vol. 102, no. 3, pp. 2645-2656, mar 2019. [ Links ]
[35] X. Zhou, C. Xu, H. Wang, W. Xu, Z. Zhao, M. Chen, B. Jia, and B. Huang, "The early prediction of common disorders in dairy cows monitored by automatic systems with machine learning algorithms," Animals, vol. 12, no. 10, p. 1251, may 2022. [ Links ]
This work was supported by Jomo Kenyatta University of Agriculture and Technology and the Kenya Education Network under the KENET CS/IS mini-grants program (2020). The authors also acknowledge the support given by the IEEE Africa Council towards the Article Processing Charge (APC).
Pascal O. Aloo received the B.Sc. degree in Mecha-tronic Engineering from the Jomo Kenyatta University of Agriculture and Technology in Nairobi, Kenya in 2018. He is currently pursuing his M.Sc. degree in Mechatronic Engineering at the same institution and is a graduate assistant at the Technical University of Kenya. His research interests include robotics, machine learning and their applications.
Evan Murimi received the Ph.D. degree in Electrical Engineering (Energy Efficiency and demand side management) from the University of Pretoria in 2017 and holds Masters and Bachelors in Mecha-tronic Engineering from Jomo Kenyatta University of Agriculture and Technology. He currently serves as a University Energy Manager and a Lecturer in the Department of Mechatronic Engineering at Jomo Kenyatta University of Agriculture and Technology. His areas of specialisation include energy transition modelling and control.
James Mutua received the Ph.D degree in Mechanical Engineering from Tottori University in Tottori, Japan. He currently serves as a lecturer in the Mechanical Department in Jomo Kenyatta University of Agriculture and Technology in Nairobi, Kenya. His research interests are in composite material development, high performance materials engineering, computational materials modelling, recycling of waste plastics, and additive manufacture of metal materials and biomedical materials for medicare.
Mathew Kyalo Ndeto is a lecturer at Jomo Kenyatta University of Agriculture and Technology. He is a registered Professional Engineer in the Engineers Board of Kenya (EBK) and the Institution of Engineers of Kenya (IEK). His areas of specialization are in material Science and engineering.
John Kagira (Ph.D) is a senior lecturer and veterinarian . He is the Dean School of Natural Resources and Animal Resources (SONRAS) at the Jomo Kenyatta University of Agriculture and Technology in Nairobi, Kenya. His area of specialization is animal health with research interests in epidemiology, diagnosis and management of livestock and zoonotic diseases