Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Dhruv2012/Autonomous-Farm-Robot/llms.txt

Use this file to discover all available pages before exploring further.

Two public agricultural datasets were used to train and evaluate AGRIBOT’s classification models — CWFID for initial validation and the BoniRob sugar beet dataset from the Photogrammetry & Robotics Lab at the University of Bonn for final model selection. Each dataset feeds a different preprocessing pipeline and input resolution, so it is important to understand their differences before running main.py.

CWFID Dataset

Full name: Crop/Weed Field Image Dataset CWFID contains annotated RGB images of carrot crops growing alongside weed, captured in a real agricultural field. It is a compact dataset well suited for rapid prototyping and architecture validation.
PropertyValue
Crop typeCarrot
Input resolution128 × 128 (UNet) or 512 × 384 (Bonnet) — set by h/w in main.py
Annotation formatPNG masks (per-pixel class labels)
Split definitiontrain_test_split.yaml
Image directoryimages/
Annotation directoryannotations/
URLhttps://github.com/cwfid/dataset
The YAML split file maps numeric sample indices to train and test lists. The load_cwfid_withyaml() helper in utils.py reads this file and assembles x_train, y_train, x_test, y_test arrays automatically. The resolution passed to this helper is determined by the model selected (h = 128, w = 128 for UNet; h = 512, w = 384 for Bonnet) not by a fixed CWFID property.

BoniRob Dataset (Bonn Sugar Beets)

The BoniRob dataset was captured by the BoniRob agricultural robot from the University of Bonn’s Photogrammetry & Robotics Lab. It contains multi-spectral images of sugar beet fields with dense three-class pixel annotations.
PropertyValue
Crop typeSugar beet
LabelsWeed (0), Crop (1), Soil (2)
Input resolution512 × 384 pixels
Input channels10 (RGB + vegetation indices + HSV)
Approximate size~6 GB uncompressed
Splitstrain/, val/, test/ under preprocessed directories
URLhttps://www.ipb.uni-bonn.de/data/sugarbeets2016/
Download datasets before training. BoniRob is ~6 GB uncompressed; ensure you have sufficient disk space and preprocess images to 512 × 384 before running main.py.
Some samples in the BoniRob dataset have missing images on one side of the input/output pair. The file Datasets(Git)/BoniRob dataset/Dataset Analysis lists all such samples so they can be removed before training. The preprocess() helper in utils.py performs this filtering automatically by taking the intersection of filenames found in the input and output directories. The preprocessed dataset is then split into train, validation, and test subsets by pre-process.py using an 80/20/validation strategy:
  • Train: ~64 % of total samples
  • Test: ~20 % of total samples
  • Validation: ~16 % of total samples

10-Channel Input for BoniRob

Plain RGB is insufficient to reliably distinguish green weed from green crop in field conditions. AGRIBOT extends the three RGB channels with seven additional channels — computed vegetation indices and HSV colour-space components — to give the Bonnet model richer spectral information. The channel construction is implemented in multichannel_input() in utils.py and mirrored by load_input() in real-time.py. In both functions the image is first in RGB order (channels 0=R, 1=G, 2=B), and the indices below use the same convention:
# Channel construction (from utils.py / real-time.py)
# Input img is in RGB order: img[:,:,0]=R, img[:,:,1]=G, img[:,:,2]=B

# Channels 0–2: normalized RGB (divided by 255 after vegetation index computation)
img[:,:,3] = (2*img[:,:,1] - img[:,:,0] - img[:,:,2])/255           # ExG
img[:,:,4] = (1.4*img[:,:,0] - img[:,:,1])/255                      # ExR
img[:,:,5] = (0.881*img[:,:,1] - 0.441*img[:,:,0] - 0.385*img[:,:,2] - 18.78745)/255  # CIVE
img[:,:,6] = (img[:,:,1] - img[:,:,0])/(img[:,:,1] + img[:,:,0])   # NDI
img[:,:,7] = hsv[:,:,0]/360                                          # Hue (from HSV)
img[:,:,8] = hsv[:,:,1]                                              # Saturation (from HSV)
img[:,:,9] = hsv[:,:,2]/255                                          # Value (from HSV)

# Normalize RGB channels last
img[:,:,0] = img[:,:,0]/255
img[:,:,1] = img[:,:,1]/255
img[:,:,2] = img[:,:,2]/255
In real-time.py the input frame arrives as BGR (from OpenCV) and is converted to RGB via frame[:,:,[2, 1, 0]] before the vegetation index computation, so the same channel indexing applies.
ChannelNameFormula
0Red (normalised)R / 255
1Green (normalised)G / 255
2Blue (normalised)B / 255
3ExG(2·G − R − B) / 255
4ExR(1.4·R − G) / 255
5CIVE(0.881·G − 0.441·R − 0.385·B − 18.78745) / 255
6NDI(G − R) / (G + R)
7HueH / 360
8SaturationS (0–1 range from OpenCV HSV)
9ValueV / 255
All values are stored as float16 to reduce memory pressure during batch generation.

Dataset Configuration in main.py

Use the dictionaries at the top of main.py to switch between datasets and architectures before running training:
training_model = {"unet": 0, "bonnet": 1}
dataset = {"cwfid": 0, "bonirob": 1}

MODEL   = training_model["bonnet"]   # Select Bonnet architecture
DATASET = dataset["bonirob"]         # Select BoniRob dataset
When DATASET = dataset["bonirob"] is set, main.py instantiates three data_gen() generators (train, val, test) rather than loading everything into memory, which is essential for a dataset of this size.

Build docs developers (and LLMs) love