AaronOnosala/Cocoa-Object-Detection

1

stars

37

commits

Python

primary language

Oct 15, 2024

updated

README

Cocoa-Object-Detection Project

Screenshot 2024-08-12 at 11 29 06 Screenshot 2024-08-13 at 19 20 29 Screenshot 2024-08-12 at 11 28 05

Background

The Cocoa Object Detection project aimed to create a robust model for identifying cocoa fruit at various stages

  1. Mature_Unripe - Images with mature but not yet ripe cocoa pods
  2. Immature - Images with Cocoa pods that are still growing.
  3. Ripped - Images with ripe mature cocoa pods.
  4. Spoilt - Images with Spoilt cocoa pods.

cocoa

from images. The original dataset provided by Makerere Artificial Intelligence Lab was in PASCAL VOC XML format, the dataset contains objects in cocoa trees under 4 classes Spoilt, Immature, Mature_Unripe and Ripped. It has been split into 3 subsets.

  • Train with 4550 images.
  • Validation with 1262 images.
  • Test with 318 images. The dataset can be downloaded as a single zip file of ~370MB from here. cocoa_annotated

The dataset has 2 types of labels. The first type is PASCAL VOC XML files for every image with the label information (see picture below) and these are found in the respective train and validation folders alongside the images. The second type of label is a CSV file named labelmap.csv that is found in the train and validation folders. A row in the CSV represents an object in the image and has 10 columns;

  • Image id - The filename of the image in the respective folder. Note that this is repeated for images with multiple objetcs
  • Actual Label - The class label of the objects of interest in the image.
  • xmin, ymin, xmax, ymax - The bounding box cordinates of the objects in the image.
  • xmin_norm, ymin_norm, xmax_norm, ymax_norm - The normalized bounding box coordinates of the objects in the image.

Image shows a sample PASCAL VOC annoation in XML format cocoa_xml_label

Image shows a sample of the labels in a CSV file for Cocoa cocoa_csv_label

The challenge was to convert this data into a format suitable for training a YOLO (You Only Look Once) object detection model.

Approach

AI Framework Used In This Project

Screenshot 2024-08-12 at 11 46 01

Data Preparation

  1. Conversion: The original dataset annotations were in PASCAL VOC XML format. To train a YOLO model, we needed to convert these annotations into the YOLO format. This required writing a script to parse the XML files and convert bounding box coordinates and class labels into the YOLO format, which consists of normalized coordinates and class IDs. Successfully converted over 4,000 XML annotation files to YOLO format, ensuring accurate bounding box and class label translation.

  2. Dataset Organization: The dataset was split into training, validation, and test subsets. The conversion script handled XML files in the train and validation folders, outputting YOLO-formatted text files, and managed the dataset split into training (4,550 images), validation (1,262 images), and test (318 images) subsets.

Model Building and Training:

  1. Model Selection: YOLOv10 was selected for its efficiency and effectiveness in object detection tasks. The model configuration was adjusted to match the dataset's specifics.

  2. Training: The model was trained on the converted dataset using the YOLO framework, with careful monitoring of performance metrics throughout the training process. The YOLOv10 model, achieving an 99,8% accuracy rate on the validation dataset.

Detection and Evaluation:

  1. Inference: The trained model was applied to both images and videos to detect cocoa pods at various stages. Results were evaluated to ensure the model's accuracy and reliability in real-world scenarios.

  2. Results Visualization: Detected objects were highlighted in the output video to visually assess the model's performance.

YOLO v10 Network Structures

Screenshot 2024-10-11 at 08 48 49

Challenges

Data Conversion:

The primary challenge was converting the dataset from PASCAL VOC XML format to YOLO format. This required accurately translating bounding box coordinates and class labels while maintaining data integrity. I faced challenges in converting data formats, but i successfully processed and formatted over 4,000 XML files into YOLO-compatible text files.

Resource Constraints:

Limited computational resources and time constraints were significant hurdles. Training complex models on limited hardware often leads to extended training times and necessitates careful resource management. I managed limited computational resources effectively, optimizing the training process to fit within available hardware constraints.

Model Performance:

Despite the challenges, the final model achieved an 99,8% accuracy rate. This was a notable accomplishment considering the constraints faced during the project.

Outcomes

  • Accuracy Improvement: The YOLOv10 model achieved an 99,8% accuracy rate in detecting various stages of cocoa fruit, demonstrating a significant improvement in detection capabilities.

  • Successful Conversion: Efficiently converted over 4,000 XML annotations to YOLO format, enabling seamless application of the YOLOv10 model.

  • Resource Optimization: Managed to train and deploy the model within stringent resource and time limitations, showcasing efficient resource utilization.

  • Practical Impact: The model's application provides automated detection of cocoa fruit stages, offering valuable insights for enhancing cocoa farming practices in Uganda.

  • Agricultural Technology Advancement: This project contributes to the field of agricultural technology in Uganda, providing a scalable solution for monitoring and improving cocoa production.

Conlusion

This project exemplifies the ability to address complex object detection challenges, manage intricate data conversion processes, and optimize resources while achieving significant and quantifiable results. The model's performance improvements and practical applications underscore the project's success and its potential impact on agricultural technology in Uganda.

Contributors

AaronOnosala

37 commits

AaronOnosala/Cocoa-Object-Detection

1

stars

37

commits

Python

primary language

Oct 15, 2024

updated

README

Cocoa-Object-Detection Project

Screenshot 2024-08-12 at 11 29 06 Screenshot 2024-08-13 at 19 20 29 Screenshot 2024-08-12 at 11 28 05

Background

The Cocoa Object Detection project aimed to create a robust model for identifying cocoa fruit at various stages

  1. Mature_Unripe - Images with mature but not yet ripe cocoa pods
  2. Immature - Images with Cocoa pods that are still growing.
  3. Ripped - Images with ripe mature cocoa pods.
  4. Spoilt - Images with Spoilt cocoa pods.

cocoa

from images. The original dataset provided by Makerere Artificial Intelligence Lab was in PASCAL VOC XML format, the dataset contains objects in cocoa trees under 4 classes Spoilt, Immature, Mature_Unripe and Ripped. It has been split into 3 subsets.

  • Train with 4550 images.
  • Validation with 1262 images.
  • Test with 318 images. The dataset can be downloaded as a single zip file of ~370MB from here. cocoa_annotated

The dataset has 2 types of labels. The first type is PASCAL VOC XML files for every image with the label information (see picture below) and these are found in the respective train and validation folders alongside the images. The second type of label is a CSV file named labelmap.csv that is found in the train and validation folders. A row in the CSV represents an object in the image and has 10 columns;

  • Image id - The filename of the image in the respective folder. Note that this is repeated for images with multiple objetcs
  • Actual Label - The class label of the objects of interest in the image.
  • xmin, ymin, xmax, ymax - The bounding box cordinates of the objects in the image.
  • xmin_norm, ymin_norm, xmax_norm, ymax_norm - The normalized bounding box coordinates of the objects in the image.

Image shows a sample PASCAL VOC annoation in XML format cocoa_xml_label

Image shows a sample of the labels in a CSV file for Cocoa cocoa_csv_label

The challenge was to convert this data into a format suitable for training a YOLO (You Only Look Once) object detection model.

Approach

AI Framework Used In This Project

Screenshot 2024-08-12 at 11 46 01

Data Preparation

  1. Conversion: The original dataset annotations were in PASCAL VOC XML format. To train a YOLO model, we needed to convert these annotations into the YOLO format. This required writing a script to parse the XML files and convert bounding box coordinates and class labels into the YOLO format, which consists of normalized coordinates and class IDs. Successfully converted over 4,000 XML annotation files to YOLO format, ensuring accurate bounding box and class label translation.

  2. Dataset Organization: The dataset was split into training, validation, and test subsets. The conversion script handled XML files in the train and validation folders, outputting YOLO-formatted text files, and managed the dataset split into training (4,550 images), validation (1,262 images), and test (318 images) subsets.

Model Building and Training:

  1. Model Selection: YOLOv10 was selected for its efficiency and effectiveness in object detection tasks. The model configuration was adjusted to match the dataset's specifics.

  2. Training: The model was trained on the converted dataset using the YOLO framework, with careful monitoring of performance metrics throughout the training process. The YOLOv10 model, achieving an 99,8% accuracy rate on the validation dataset.

Detection and Evaluation:

  1. Inference: The trained model was applied to both images and videos to detect cocoa pods at various stages. Results were evaluated to ensure the model's accuracy and reliability in real-world scenarios.

  2. Results Visualization: Detected objects were highlighted in the output video to visually assess the model's performance.

YOLO v10 Network Structures

Screenshot 2024-10-11 at 08 48 49

Challenges

Data Conversion:

The primary challenge was converting the dataset from PASCAL VOC XML format to YOLO format. This required accurately translating bounding box coordinates and class labels while maintaining data integrity. I faced challenges in converting data formats, but i successfully processed and formatted over 4,000 XML files into YOLO-compatible text files.

Resource Constraints:

Limited computational resources and time constraints were significant hurdles. Training complex models on limited hardware often leads to extended training times and necessitates careful resource management. I managed limited computational resources effectively, optimizing the training process to fit within available hardware constraints.

Model Performance:

Despite the challenges, the final model achieved an 99,8% accuracy rate. This was a notable accomplishment considering the constraints faced during the project.

Outcomes

  • Accuracy Improvement: The YOLOv10 model achieved an 99,8% accuracy rate in detecting various stages of cocoa fruit, demonstrating a significant improvement in detection capabilities.

  • Successful Conversion: Efficiently converted over 4,000 XML annotations to YOLO format, enabling seamless application of the YOLOv10 model.

  • Resource Optimization: Managed to train and deploy the model within stringent resource and time limitations, showcasing efficient resource utilization.

  • Practical Impact: The model's application provides automated detection of cocoa fruit stages, offering valuable insights for enhancing cocoa farming practices in Uganda.

  • Agricultural Technology Advancement: This project contributes to the field of agricultural technology in Uganda, providing a scalable solution for monitoring and improving cocoa production.

Conlusion

This project exemplifies the ability to address complex object detection challenges, manage intricate data conversion processes, and optimize resources while achieving significant and quantifiable results. The model's performance improvements and practical applications underscore the project's success and its potential impact on agricultural technology in Uganda.

Contributors

AaronOnosala

37 commits

Languages

Python

100.0%