Leveraging AI in Agriculture: A Focus on Ugandan Coffee

In Uganda coffee is a major part of the economy, with over 1.8 million households growing it, contributing to almost a third of the country's export earnings. Given these factors, it is essential for both the private and public sectors to explore technological solutions that leverage data and artificial intelligence to increase crop yield. 

In this piece, we explore the pain points around growing coffee in Uganda, analysing how predictive analytics and deep learning tools like Machine Learning (ML) and image classification models provide a solution. We investigate the importance of quality data collection practices, a major hindrance to the success of these solutions. 

In addition, we assess the feasibility of a hardware or software solution being integrated into the BAU (Business As Usual) processes for farmers in developing countries like Uganda. This article was inspired by discussions within the JEPA technology research desk around creating a minimum viable product for an agri-data solution (currently in the works) for crop disease detection. 

Challenges 

Uganda ranks as the world's 7th largest coffee exporter, with an annual output of approximately 393,900 tonnes. Despite its significant role in the global coffee market, the industry faces numerous challenges that impact both yield and quality. These include pests and diseases, poor farming practices, erratic weather patterns and economic pressure. With over 1.8 million farms, the industry consists largely of smallholder operations producing 99% of the coffee on an average farm size of just 0.5 hectares. This fragmented nature of production exacerbates the difficulties faced by the sector. 

In 2021, the Ministry of Agriculture Animal Industry and Fisheries (MAAIF) investigated pests and diseases affecting the coffee trees of farmers in the Toro, Buganda and Busoga regions. The ministry concluded that coffee farmers were vulnerable and had been exposed to three prominent pests: Coffee berry disease (CBD) and Coffee Leaf Rust (CLR) in Arabica and Black Coffee Twig Borer (BCTB) in Robusta. Pests like BCTB can destroy up to 50% of a farmer's crop yield if not properly managed. 

Poor processing and handling practices negatively affect the quality of coffee produced as well, which has most likely been a symptom of the low productivity among Ugandan coffee farmers evidenced by the average yield in Uganda being 500 kilograms per hectare, while global competitors, Brazil, have been able to triple that value at 1500 kilograms per hectare.  

Economic factors also play a significant role in the challenges faced by Ugandan coffee farmers. Fluctuating coffee prices create financial instability making it difficult for farmers to maintain consistent incomes. This price volatility, coupled with exploitative practices by middlemen, compounds the issue. Middlemen often purchase coffee from farmers at low prices, cheating them out of fair compensation, and then sell the coffee at much higher prices further up the supply chain, reaping substantial profits. This exploitation leaves farmers with minimal earnings despite their efforts. Additionally, the situation is aggravated by Uganda’s low investment in agriculture research and development (R&D), which stands at a mere 0.31%. This minimal R&D intensity means there are limited resources allocated to improving agricultural practices and enhancing data management, further hindering the ability of farmers to improve their production methods and manage their crops effectively. 

Climate change is set to become the most significant factor challenge for  coffee production in Uganda in the coming years. Recent research by Makerere University undergraduates, analysing climate patterns from 2010-2021, reveals a positive correlation between average annual rainfall and coffee exports, indicating that increased rainfall historically boosted coffee production. Historically, farmers expected to witness increased yields for their coffee beans between the months of April through June, however as Uganda faces increasingly drier and hotter conditions - projected to rise by approximately 1.3 degrees by 2060-  farmers are likely to encounter severe challenges. These include heightened risks of pests, diseases, and soil erosion, which could degrade soil quality and disrupt coffee flowering. The predictability of weather patterns, once a reliable guide for farming practices, is diminishing. As a result, farmers will have to confront the dual threats of flooding and drought, making it  increasingly difficult to sustain consistent and high-quality coffee yields. 

These challenges collectively impact the coffee sector, which contributes to almost a third of Uganda's export earnings. The total cultivated area for coffee in Uganda is 469,364 hectares, but productivity and quality issues persist due to these various factors. 

Predictive Analytics - A Solution 

A significant challenge in coffee farming in East Africa is the prevalence of diseases such as berry disease, leaf rust, and wilt disease. Leaf rust, in particular, directly impacts both the yield and quality of the coffee crop due to premature defoliation, where infected leaves shed early, resulting in substantial crop losses. Therefore, controlling leaf rust is crucial to maintaining the productivity and quality of coffee farming in the region. 

Coffee Leaf rust is recognised by yellow or blotchy orange pustules. Visual changes or symptoms are key factors to consider when deciding which AI/ML solution to implement for detecting these legions earlier on to enact necessary mitigation strategies. The typical AI solution for image classification is convolutional neural networks. CNN’s are a type of deep learning algorithm typically effective for analysing images/slices of a visual dataset in fine detail. Within the context of detecting coffee diseases like coffee leaf rust (see the image below), CNNs use convolutional layers to hierarchically extract the most relevant features from all images within a dataset including, colour, texture and any other anomalies.  

These features are then processed by fully connected layers (fully connected layers act like the decision-making part of the network, combining all the learned features to determine the output, such as classifying an image or making a prediction) which will help classify the presence and the type of disease present within the crops with very high accuracy (subject to the data quality input into the training model). The amount of data required for accurate training is a major consideration in coffee disease detection. Techniques such as data augmentation during pre-processing and the use of open-source datasets with labeled coffee samples can help increase the dataset's size and variability. 

 At a high level, the implementation of Convolutional Neural Networks to detect diseased coffee crops is as follows: 

Data Collection

Identifying suitable farms to capture images of healthy and diseased plants to label them.

Labelling these images using image annotation tools of disease types to create a labelled dataset.  

Data Preprocessing

Data Cleaning to remove images that do not fit the standard. 

Data augmentation to increase the datasets’s size and variability.  

Normalisation of image pixels to improve model training stability.  

Model Development

Choosing a CNN architecture which provides the best accuracy (ResNet, VGG or a custom model). This may need further experimentation to assess which model best fits the use case. 

Training the model with a split dataset alongside hyper-parameter tuning.  

Evaluating the model.

  • Deployment - integrating the CNN model within hardware infrastructure that fits into a farmer's “business as usual” activities to decrease the amount of physical labour associated with locating and segregating diseased crops.  

    • A mobile software application which serves as a detection tool may not be most effective for some East African farmers used to traditional methods, therefore a well-thought-out hardware solution may best fit this use case.  

    • Perhaps a combination of both a software solution like Plant Village AI and a hardware solution like drones is best to tackle this problem. 

    • Deploy drones equipped with high-resolution cameras to capture detailed photos of coffee crops from multiple angles, ensuring comprehensive coverage of the farm. 

    • Create software capable of running CNN models on the images captured by drones in real-time, automatically tagging and identifying diseased crops. 

    • Utilise drones to continuously monitor the farm, taking regular photos and feeding them into a central database. This ensures a continuous feedback loop for improving and retraining the model. GPS tagging helps identify the precise location of diseased crops. 

    • Develop a dashboard that aggregates data from drone imagery, providing farmers with key performance indicators (KPIs). This dashboard should monitor the spread and development of crop diseases across the entire farm, offering actionable insights and timely alerts. 

Precision Farming 

Precision farming consists of finding the optimal parameters required to grow crops in which the right aggregate of these parameters will lead to increased crop yield. The challenge farmers within Uganda face is integrating a data-first approach that is directly applicable to their use case. Before finding an optimal AI or machine learning model to train, a farmer or group of data specialists need to think of a sustainable way to collect data on soil PH, soil moisture levels, Fertiliser and amount, weather conditions and pest presence, etc. continuously to optimise for the greatest crop yield. The use of an IoT device can be considered, akin to the air quality device currently being used by AirQo. AirQo is a low-cost air quality sensor that was produced to tackle air pollution within Uganda. 

With the assumption that an IoT device is available to farmers to reduce the time required for data scientists to manually collect the data for these parameters: 

The initial step involves collecting a comprehensive dataset that includes historical weather data, crop yield records, soil test results, and fertiliser usage. This data is combined with real-time inputs to create an optimal dataset for analysis. 

  1. Implement a combination of regression models, classification models, and time series analysis to support precision farming. Regression models, which showcase the relationship between input and output variables, are useful for predicting crop yield over time given soil quality, while time series models are essential for forecasting weather conditions that favour coffee growth. 

  2. Specific models to be used include the Random Forest Regressor for yield prediction and Long Short-Term Memory (LSTM) networks for weather forecasting.  

  3. Random forest regressor models take in multiple decision trees comparing relationships of data to incorporate into a final prediction decision. This is suitable for precision farming which takes in multiple parameters to pinpoint the most suitable environments for increased crop yield. 

  4. An LSTM network is a special type of neural network designed to remember information for long periods, which is useful for predicting sequences, such as weather patterns over time. 

  5. Implement an IoT device, similar to an Arduino equipped with various sensors, to gather and monitor data in real-time. The trained models can be integrated into this IoT device, allowing for continuous data collection and analysis. The device can upload data to the cloud, providing easy access and real-time decision-making using visualisation dashboards. 

Further Challenges 

The success of leveraging AI and predictive analytics in Uganda's coffee farming is heavily reliant on the availability and quality of data. However, data collection remains a significant challenge in Uganda's agricultural sector. Many farming communities lack the necessary infrastructure and resources to systematically collect, store, and process data. This absence of high-quality data undermines the effectiveness of AI models, which depend on accurate and comprehensive datasets to deliver reliable predictions and insights. 

Additionally, existing data often suffers from inconsistencies and inaccuracies, making it difficult to derive actionable insights. Poor processing and handling practices further degrade the quality of data available for analysis and model training. Farmers may not have access to modern tools and technologies required for precise data collection, such as Internet of Things (IoT)  sensors and mobile applications. Additionally, there is a lack of awareness and understanding among farmers about the benefits of data-driven farming, which hinders the adoption of advanced technologies. 

Investments in technology are crucial to equip farmers with the tools needed for efficient data collection. IoT sensors, for example, can be deployed to continuously monitor soil moisture, temperature, and other critical parameters, feeding real-time data into the machine learning systems. Training programs, educational initiatives and campaigns can help farmers understand the importance of data quality and how their data can assist them leverage technology for better farming outcomes. 

Collaborative efforts between the public and private sectors are essential to bridge the data gap. Government agencies, agricultural organisations, and tech companies can work together to develop and implement data collection frameworks tailored to the specific needs of Ugandan coffee farmers. By enhancing data collection practices and ensuring data quality, Uganda can maximise the potential of AI and predictive analytics to revolutionise its coffee industry, improving crop yields, sustainability, and economic stability for farmers. 

Previous
Previous

Kenya’s Crucial Crossroad for its Unbounding Debt Burden: An Interrogation of Kenya’s Concerning Debt Situation

Next
Next

Adapting Agriculture to Climate Change: Energy Solutions for Sustainable Farming in East Africa