0% found this document useful (0 votes)
3 views13 pages

MangoAI Tutorial

Mango Detector AI is an open-source desktop application designed for automated detection and counting of mangoes using YOLOv5, suitable for farmers and researchers. The app supports offline use on Windows and Linux, processes images and videos, and allows for real-time detection via live streams. It is customizable, private, and includes a comprehensive tutorial for building and distributing the application.

Uploaded by

Madhu Sadagopan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views13 pages

MangoAI Tutorial

Mango Detector AI is an open-source desktop application designed for automated detection and counting of mangoes using YOLOv5, suitable for farmers and researchers. The app supports offline use on Windows and Linux, processes images and videos, and allows for real-time detection via live streams. It is customizable, private, and includes a comprehensive tutorial for building and distributing the application.

Uploaded by

Madhu Sadagopan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Mango Detector AI

Open-Source Desktop App for Automated Mango Counting and Detection

Overview
Mango Detector AI is a production-ready, user-friendly desktop application for detecting and
counting mangoes in images, videos, and real-time streams. Built with YOLOv5 (a
state-of-the-art object detection model) and a modern Python GUI, it enables farmers,
researchers, and agritech startups to:
Instantly detect and count mangoes in fields, orchards, or market images

Analyze drone/CCTV feeds and generate logs of detected fruits

Process single images, folders, or video files with just a few clicks

Export detection results for further analysis

Features:
Works offline on Windows and Linux

Supports webcam/RTSP/CCTV live stream input

No internet required after installation

Clean, easy-to-use interface — no coding skills needed

Fully open-source (Apache License)

Can be retrained for other fruits or agricultural tasks

Why Use Mango Detector AI?


Accurate: Leverages robust deep learning to handle complex backgrounds and lighting
Fast: Optimized for consumer laptops — GPU optional!

Customizable: Retrain with your own dataset for better results or other crops

Private: All data stays on your device; nothing is uploaded

Project Structure
Dataset preparation and annotation: Build your own custom mango detection model

Model training: Train YOLOv5 to recognize mangoes in diverse conditions

Cross-platform GUI app: A one-click tool for mango detection

Standalone executable packaging: Run the app without needing Python installed

Distribution-ready: Package as .exe for Windows, AppImage for Linux

Who is this for?


Farmers, farm managers, and agritech startups

Students and researchers in computer vision or agriculture

Anyone needing automated, offline mango counting

Getting Started
Follow the tutorial below to build, customize, and distribute your own Mango Detector AI for your
region or use-case!
Mango Detector AI: Complete Project Tutorial

(Windows & Linux – Full Production Pipeline)


1. Project Overview and Flow

Goal:
Build and distribute a production-ready Mango Detection AI app (YOLOv5 + GUI) for Windows
(.exe) and Linux (AppImage), suitable for open-source or professional use.

Main Steps:

Dataset Preparation & Annotation

Model Training (YOLOv5)

Model Conversion (optional for mobile/deployment)

Building the Python GUI (CustomTkinter)

Packaging into a standalone desktop app

Distributing via Kaggle/Hugging Face/Your Website

Tips for README, Pro App, and Launch

2. Dataset Collection and Annotation


2.1. Collecting Mango Images

Sources:

Smartphone/digital camera (best if you control conditions)

Open datasets (Google, Kaggle, etc.)

Drone/CCTV/field cameras

Guidelines:

Collect varied images: day/night, different angles, distances, multiple mango varieties
Aim for at least 50–200 images for a small test project; 500+ for better results

2.2. Annotation (Labeling Mangoes)

Tools:

LabelImg (GUI for Windows/Linux/Mac)

Roboflow Annotate

CVAT (advanced, web-based)

Format:

YOLO format (recommended): one .txt file per image, same base name

Each line: <class_id> <x_center> <y_center> <width> <height> (normalized 0–1, all
relative to image size)

2.3. Organizing the Dataset

Folder Structure Example:

mango_dataset/
images/
train/
val/
labels/
train/
val/

Tips:

Split ~80% images for training, ~20% for validation (val)

Use scripts or [Link] to automate splitting if needed

3. Model Training with YOLOv5


3.1. Setting Up the Environment

Recommended:

Use Anaconda (conda) or Python venv for isolation


Python 3.8–3.10 (works best with YOLOv5)

PyTorch (CPU or GPU version as per hardware)

Install YOLOv5:

git clone [Link]


cd yolov5
pip install -r [Link]

Install extra (if using GUI later):

pip install customtkinter pillow opencv-python

3.2. Preparing the YOLO Data Config

Create [Link] with the following:

train: ./mango_dataset/images/train
val: ./mango_dataset/images/val
nc: 1
names: ['mango']

3.3. Training the Model

Run:

python [Link] --img 640 --batch 8 --epochs 100 --data [Link] --weights [Link] --name
mango_detect

[Link] is a small, fast model; can use [Link], etc., for bigger models if you have
resources.

Best weights will be saved in:


runs/train/mango_detect/weights/[Link]

3.4. Testing the Model

python [Link] --weights runs/train/mango_detect/weights/[Link] --source


path/to/test/images_or_video

Check that mangoes are being correctly detected!


4. Mango Detector AI: Desktop GUI Application
4.1. Overview

This section covers how to build a Python GUI application using CustomTkinter for mango
detection.
The app allows users to:

Select an image, video, or folder for detection

Run real-time detection on RTSP/HTTP streams

Log and export results

(Optionally) Package the app for Windows/Linux with a single click

No coding knowledge is required to use the final app.


4.2. Prerequisites

Before running the GUI, ensure you have:

Python 3.8–3.11 (Windows or Linux)

pip package manager

Your trained YOLOv5 model file ([Link] for Linux, or best_windows.pt for Windows)

All required Python packages installed

Recommended Python packages:

pip install customtkinter pillow opencv-python torch numpy

For YOLOv5, also clone the repository inside your project folder:

git clone [Link]

Place your model file (e.g., [Link]) in the main folder with your code.
4.3. Directory Structure

mango_detector_ai/
├── mango_gui_pt.py
├── [Link] (or best_windows.pt)
├── yolov5/
│ ├── models/
│ ├── utils/
│ └── ... (other YOLOv5 files)
└── mango_gui_outputs/ # Created automatically for results/logs

4.4. The Main GUI Code

Paste the following code into a file named mango_gui_pt.py:

(For space, paste the full code from your previous message or the clean version I provided
earlier.)

Notes:

The boxes are green for mangoes by default ((0,255,0)).

Make sure your YOLOv5 repo, weights, and dependencies are in the same folder or properly
referenced.

4.5. How to Run

On Linux:

python3 mango_gui_pt.py

On Windows:

python mango_gui_pt.py

For .exe creation, use PyInstaller:

pyinstaller --onefile mango_gui_pt.py

The resulting .exe will be in the dist/ folder.


5. Next Steps

For AppImage (Linux) and MSI (Windows) packaging, refer to packaging sections.

Distribute your app via Kaggle, Hugging Face, or your own website.

Add a README and polish your user instructions before public launch.
End of Part 1 & 2: Dataset, Training, and GUI Build

Mango Detector AI: Complete Project Tutorial

(Windows & Linux – Full Production Pipeline)


1. Project Overview and Flow

Goal:
Build and distribute a production-ready Mango Detection AI app (YOLOv5 + GUI) for Windows
(.exe) and Linux (AppImage), suitable for open-source or professional use.

Main Steps:

Dataset Preparation & Annotation

Model Training (YOLOv5)

Model Conversion (optional for mobile/deployment)

Building the Python GUI (CustomTkinter)

Packaging into a standalone desktop app

Distributing via Kaggle/Hugging Face/Your Website

Tips for README, Pro App, and Launch

2. Dataset Collection and Annotation


2.1. Collecting Mango Images

Sources:

Smartphone/digital camera (best if you control conditions)

Open datasets (Google, Kaggle, etc.)

Drone/CCTV/field cameras

Guidelines:

Collect varied images: day/night, different angles, distances, multiple mango varieties

Aim for at least 50–200 images for a small test project; 500+ for better results
2.2. Annotation (Labeling Mangoes)

Tools:

LabelImg (GUI for Windows/Linux/Mac)

Roboflow Annotate

CVAT (advanced, web-based)

Format:

YOLO format (recommended): one .txt file per image, same base name

Each line: <class_id> <x_center> <y_center> <width> <height> (normalized 0–1, all
relative to image size)

2.3. Organizing the Dataset

Folder Structure Example:

mango_dataset/
images/
train/
val/
labels/
train/
val/

Tips:

Split ~80% images for training, ~20% for validation (val)

Use scripts or [Link] to automate splitting if needed

3. Model Training with YOLOv5


3.1. Setting Up the Environment

Recommended:

Use Anaconda (conda) or Python venv for isolation


Python 3.8–3.10 (works best with YOLOv5)

PyTorch (CPU or GPU version as per hardware)

Install YOLOv5:

git clone [Link]


cd yolov5
pip install -r [Link]

Install extra (if using GUI later):

pip install customtkinter pillow opencv-python

3.2. Preparing the YOLO Data Config

Create [Link] with the following:

train: ./mango_dataset/images/train
val: ./mango_dataset/images/val
nc: 1
names: ['mango']

3.3. Training the Model

Run:

python [Link] --img 640 --batch 8 --epochs 100 --data [Link] --weights [Link] --name
mango_detect

[Link] is a small, fast model; can use [Link], etc., for bigger models if you have
resources.

Best weights will be saved in:


runs/train/mango_detect/weights/[Link]

3.4. Testing the Model

python [Link] --weights runs/train/mango_detect/weights/[Link] --source


path/to/test/images_or_video

Check that mangoes are being correctly detected!


4. Mango Detector AI: Desktop GUI Application
4.1. Overview

This section covers how to build a Python GUI application using CustomTkinter for mango
detection.
The app allows users to:

Select an image, video, or folder for detection

Run real-time detection on RTSP/HTTP streams

Log and export results

(Optionally) Package the app for Windows/Linux with a single click

No coding knowledge is required to use the final app.


4.2. Prerequisites

Before running the GUI, ensure you have:

Python 3.8–3.11 (Windows or Linux)

pip package manager

Your trained YOLOv5 model file ([Link] for Linux, or best_windows.pt for Windows)

All required Python packages installed

Recommended Python packages:

pip install customtkinter pillow opencv-python torch numpy

For YOLOv5, also clone the repository inside your project folder:

git clone [Link]

Place your model file (e.g., [Link]) in the main folder with your code.
4.3. Directory Structure

mango_detector_ai/
├── mango_gui_pt.py
├── [Link] (or best_windows.pt)
├── yolov5/
│ ├── models/
│ ├── utils/
│ └── ... (other YOLOv5 files)
└── mango_gui_outputs/ # Created automatically for results/logs

4.4. The Main GUI Code

Paste the following code into a file named mango_gui_pt.py:

(For space, paste the full code from your previous message or the clean version I provided
earlier.)

Notes:

The boxes are green for mangoes by default ((0,255,0)).

Make sure your YOLOv5 repo, weights, and dependencies are in the same folder or properly
referenced.

4.5. How to Run

On Linux:

python3 mango_gui_pt.py

On Windows:

python mango_gui_pt.py

For .exe creation, use PyInstaller:

pyinstaller --onefile mango_gui_pt.py

The resulting .exe will be in the dist/ folder.


5. Next Steps

For AppImage (Linux) and MSI (Windows) packaging, refer to packaging sections.

Distribute your app via Kaggle, Hugging Face, or your own website.

Add a README and polish your user instructions before public launch.

End of Part 1 & 2: Dataset, Training, and GUI Build

You might also like