Skip to content

Latest commit

 

History

History
291 lines (193 loc) · 19.8 KB

README.md

File metadata and controls

291 lines (193 loc) · 19.8 KB

CADI AI - Cashew Disease Identification with Artificial Intelligence

This is the main repository for CADI AI, a desktop application for identifying disease, abiotic stress and pest infestations in cashew plants.

Table of Contents

Introduction

CADI AI - Cashew Disease Identification with Artificial Intelligence - is a demo-application that uses the technology Artificial Intelligence (AI). It looks at drone images of cashew trees and informs users whether cashew trees suffer from:

  • pest infection, i.e. damage to crops by insects or pests
  • disease, i.e. attacks on crops by microorganisms
  • abiotic stress caused by non-living factors (e.g. environmental factors like weather or soil conditions or the lack of mineral nutrients to the crop).

CADI AI shall support farmers as an early warning system to quickly identify problems in their cashew farms and to keep their crops healthier and more yielding. KaraAgro AI developed CADI AI for the initiatives “Market-Oriented Value Chains for Jobs & Growth in the ECOWAS Region (MOVE/Comcashew)” and FAIR Forward - Artificial Intelligence for All. Both initiatives are implemented by the Deutsche Gesellschaft für Internationale Zusammenarbeit (GIZ) on behalf of the German Federal Ministry for Economic Cooperation and Development (BMZ).

CADI AI is based on the following resources:

The training data, AI model and CADI AI demo-application are available under the GNU Affero General Public License v3.0 that requires projects that work with the resources to apply the same licensing to their projects.

Problem Statement

The threat of pests and diseases to the agricultural sector in Ghana is a constant concern, with climate change contributing to the potential for new and more damaging types of outbreaks (Yeboah et al., 2023). Based on multi-stakeholder engagements conducted by KaraAgro AI, also with women smallholder cashew farmers, stakeholders have identified pest and disease detection and yield estimation as critical concerns.

However, the existing methods of identifying agricultural pest and disease outbreaks, such as land surveys and on-site observations by individuals, are limited in their effectiveness and efficiency. Thus, there is a need for more innovative and efficient solutions to improve the monitoring and management of crop health. This highlights a gap in the existing tools and resources, which can be addressed through the use of technologies such as machine learning and image analysis.

Project Description

  • Data Collection

    Dataset images were captured with the P4 multispectral drone at image resolution of 1600 x 1300 pixels. The images consist of close up shots and distant shots of the cashew plant abnormalities. The total number of images collected were 4,736.

    You can access the dataset via Kaggle and HuggingFace.

    The data collection process was conducted in two separate trips at cashew farms in the Bono Region of Ghana to accommodate seasonal variations for the diversity of the data. The collection process spanned six days in total. While more continuous data collection across various regions during the cashew blooming cycle could have been beneficial, we still consider the dataset to be sufficiently diverse. This is due to the inclusion of different maturity stages, camera angles, time of capture, and various types of stress morphology in the data collected.

    For more information on the dataset, its collection and annotation, please view the accompanying datasheet.

  • Image Pre-processing

    Pre-processing of the data involved removing crop images in which human figures or faces were accidentally captured. Also blurry images were deleted.

  • Annotation

    The collected dataset annotation consisted of drawing bounding boxes on the collected images using MakeSense dataset annotation tool. The three classes that were annotated in the process include:

    • Disease
    • Abiotic stress
    • Pest infection
  • Model Training

    YOLO v5X architecture was employed to construct the model. To enhance the image quality and facilitate efficient processing, the resolution of the images was adjusted to 640 pixels, while maintaining a batch size of 56. The resulting model achieved an overall mAP of 0.648 and a size of 173.1 MB.

    You can access the model and a more detailed description via HuggingFace.

  • Software Development

    CADI AI is a local flutter desktop application. It requires internet connection for the setup and intermittently to refresh cached data. Otherwise, it is mostly local.

    To keep it local, the application spins up a local python server using the Flask framework through which scans are then made by making local http requests.

    The python server code can be found in the app.py file. The server accepts POST requests with a file path as parameter. The file_path tells where selected images for scans are located on the user's device, and passes the same to the model for inferencing.

    It is our understanding that not every user of the application would have python installed on their device; especially for Windows users, the Operating System does not come bundled with python.

    For this reason, the application features a Setup page where all required missing software is installed before the application starts.

    The Setup stage can take some amount of time. We ask all users to be patient while that step is in progress.
    

    We are constantly looking into ways to improve this process in the application or to remove it entirely. Once we find a better solution that works, we will swap it out.

    The folder structure for the project is as below:

      ├── assets
      ├── lib
      │   ├── adapters
      |   ├── controllers
      |   ├── entities
      |   ├── generated
      |   ├── layouts
      |   ├── pages
      |   ├── services
      |   ├── themes
      |   ├── utils
      |   ├── widgets
      ├── macos
      ├── test
      ├── windows
      ├── app.py
      ├── pubspec.yaml
    
    • The asset directory contains images and icons that are used in the application. The application icon is also located in this directory.

    • The lib directory contains most of the code written in the dart language.

    • The lib/pages directory contains dart files that define the widget look-and-feel of each of the pages in the application.

    • The lib/layouts directory contains dart files that define the structure of the major widgets of the application. For example, the HomeLayoutState.dart files defines the various sections i.e Side Panel and an expanded area for content widgets.

    • lib/services holds service files that define API for communicating with the trained model, for instance, and saving scan results and images to Isar database

    • lib/utils contains helper functions that are re-used across several other widgets. All extractable functions that can be separated so as to be re-used or simplified can be found in this directory

    • lib/widgets is where custom and re-usable widgets are defined.

    • app.py file is the python script that spins up the local python flask server.

    • macos and windows directories contain configuration files for MacOs and Windows respectively. Configurations like application icon and build targets when changed in Xcode are written directly to the Podfile in the macos directory.

    Note: Due to the size of the trained cashew model as described in the Model Training section above, the total size of the project files exceeded the Github repository file size limit.

    As a result, the model was not included in the repository. The model can be accessed via HuggingFace..

    It is required that the model file be downloaded and added to the project on your local device before tests can be run. If you run flutter run without the model file available in the project directory, you will not be able to run scans.

    Note: CADI AI only runs scans on images that are having GPS coordinates in their Exif metadata (Exchangeable Image Format).

    The Exif specifications define a pair of file types, mainly intended for recording technical details associated with digital photography exif-format

    Exif is a metadata standard that defines formats for sharing metadata related to images, sound, and ancillary tags used by digital cameras, scanners and other systems that handle image recorded by digital cameras.

    In this case, it is required that images selected for scan in CADI AI must have metadata following the Exif standard, and must have GPS coordinates in their metadata before they can be scanned.

    This is because the application shows location pins on a satellite map that enables farmers to locate the region of the farm where a disease, abiotic stress or pest is found present. Without GPS coordinates this would not be possible.

  • Software Release and Deployment

    CADI AI builds and releases are available on the repository.

    The application is built into a Windows msi package and uploaded with a tag to the repository. Builds for MacOs are also available. There is currently no support for Linux Systems and no future plans to support them.

    At the right side panel on the CADI AI repository, releases with tags can be found and can be downloaded and installed on users' devices.

    Semantic versioning (Semver) is used to name each build. Latest builds are better and more robust and should be preferred over older builds.

Contributing

Contributions are invited to fix issues and improve the application.

There are some rules, though, that we believe must be observed in contributing to the application. Find more information on these rules and related ones below.

  • Technologies & Tools

    CADI AI is a flutter-based local desktop application. The following technologies and tools are used in the development of the application. These technologies are also pre-requisite in order to contribute to the improvement of the application.

    1. Flutter<=3.3.0
    2. Dart
    3. Isar Database
    4. GetX Controller
    5. Python 3.0 and later
    6. Python Libraries( Flask=>2.3.2, Flask-cors=>3.0.10, ultralytics=>8.0.106, torchvision=>0.15.2, torch=>2.0.1, opencv-python=>4.7.0.72, pandas=>2.0.1, psutil=>5.9.5, pyyaml=>6.0, tqdm=>4.65.0, matplotlib=>3.7.1, seaborn=>0.12.2 )
    7. Visual Studio Code (Recommended IDE)
    8. Xcode (Required only for MacOs X)
  • Workflow & Branch Rules

    Semantic branch names and semantic commit messages are the format to be used for branches and commits to this repository. Anything else deviated from these standards would be rejected.

    The branching workflow also follows the rules below:

    • master/main: The master branch should always have stable code that can be picked for release at any time. Pull requests (PR) to the master branch only come from the QA branch.

    • QA/test/staging (Quality Assurance): The QA branch is where code that has gone through review from contributors can be tested. Then merged to main after testing.

    • Dev: The dev branch accepts pull requests (PR) for contributions. Code reviews are done against PR’s to the Dev branch

  • Issues

    Before you submit an issue, please search the issue tab. An issue for your problem might already exist and reviewing the related discussions could provide valuable insights and solutions.

    If you want to add improvements or suggest new features, you should first create an issue. This will let us discuss and agree on the proposed changes before you start working on them. After the proposal is accepted, the accepted label will be added to the issue and implementation can begin.

    If you just want to fix a bug or typo, you can directly create a pull request with a clear description of the bug or typo you are fixing.

  • Pull Requests

    To contribute to the project, follow the steps below:

    1. Fork karaagro/cadi-ai. Uncheck the Copy the main branch only option to ensure you get the dev branch.

    2. Create a new branch from the dev branch in your forked repository.

      git checkout -b <branch-name> dev
    3. Add your changes and commit them with a descriptive commit message.

    4. Push your changes to github.

    5. Create a pull request to the dev branch of karaagro/cadi-ai and request a review from @atamino

  • Support

    The team at KaraAgro AI will keep supporting the software indefinitely. We will be fixing issues, making improvements and adding new features as and when they are needed.

Build CADI AI

Currently, CADI AI build process for Windows has been tried and tested. The process for MacOs also works but has some suspicious behaviour due to the use of python and the setup process not being designed for MacOs. KaraAgro investigates this behaviour.

Below are the steps to build for Windows and MacOs. Linux devices are not supported.

  • Building for Windows

    This is a general outline on how to package the app into a single msi package. We will be using Advanced installer to generate the msi build.

    First, make sure the app has been built with flutter

    flutter build windows

    Select generic installer project in Advanced Installer and click on Create new project. You will need the professional version or above of the app to do this.

    Step 1

    On the Product details tab, Enter the name, version and publisher of the application. Scroll down and select an icon to be shown on the control panel.

    Step 2

    Click on the Files and Folders tab. Here we are going to provide the files that will actually be packaged. Click on Add Files and navigate to the directory with the flutter project. Here select app.py, python-installer.exe and yolov5_exp11_best.pt

    Step 3

    Click on Add Files again and (Assuming you are in the project root directory) navigate to /build/windows/runner/Release. Select all the files.

    Now click on Add Folder and (Again assuming you are in the project root directory) navigate to /build/windows/runner/Release. Select the data folder.

    Click on the application folder in the target machine to see all the added files.

    Step 4

    Right click on the cadi executable and select New shortcut To - Installed file. Enter a custom name and for the shortcut folder, we will select Desktop. Select an icon for the shortcut and click OK.

    Step 5

    You can create multiple shortcuts with the same process and just changing the shortcut folder.

    Click on the Install Parameters tab. Here we are going to set the application folder to [ProgramFilesFolder][ProductName]. Set the packet type to 64-bit package for x64 processors (AMD64, EM64T). Also, check Run as administrator

    Step 6

    Click on the Builds tab. Here we will select the Single MSI (resources inside) option. Select a folder where the package will be placed after build and enter a name for the msi.

    Step 7

    Finally go to the Dialogs tab. Here we will customise the installation dialogs. Click the Exit dialog and at the bottom, scroll till you find the Launch Application section. Check the Launch application at the end of installation checkbox and select the executable(Not the python executable). Also check the Run as administrator and Option checked by default options.

    Step 8

    On the title bar, click the build icon to build the msi package.

    Step 9

    This is just a simple build without proper certificates and all that. For more information about building packages with Advanced installer, checkout their guide here

  • Building for MacOs X

    MaxOs X build process not perfected yet. Coming soon.

Conclusion

Overall, CADI AI offers a promising solution for cashew farmers to enhance disease and pest detection, by combining AI and drone imagery. With ongoing support and contributions, the application can continue to improve and contribute to the well-being and productivity of cashew farms.

While CADI AI provides valuable assistance, it should be noted that it does not provide specific disease or pest identification or treatment recommendations. Users are advised to exercise caution and verify the diagnoses by consulting trained agronomists or extension officers before taking any action based on the application's results.