Skip to main content

Computer Vision pipeline for Precision Agriculture focused on crop and weed edge detection.

Project description

CropEdgeAI 🌱

Python License YOLO Version

CropEdgeAI is a Computer Vision pipeline for crop and weed detection, with tools for dataset processing, data augmentation, hyperparameter optimization, and NCNN export for edge deployment.

Attribution

This project uses data from:

  • Weed-crop dataset in precision agriculture by Upadhyay et al., North Dakota State University
  • Licensed under Creative Commons Attribution 4.0 International (CC BY 4.0)
  • DOI: 10.17632/mthv4ppwyw.2 Please check NOTICE for further details.

Table of Contents

Features

  • Data loading, validation, splitting, augmentation
  • EDA: dataset statistics and visualizations
  • HPO with Optuna
  • YOLO v8/v9/v10/v11/v12 training and benchmarking
  • NCNN export for edge devices
  • Batch inference with stats export
  • Google Drive backup

Supported Crops

Black bean, Canola, Corn, Field pea, Flax, Lentil, Soybean, Sugar beet

Installation

  • Python 3.11 or 3.12
  • CUDA GPU (optional)
  • 40GB+ disk space
git clone https://github.com/manueljesus/cropedgeai.git
cd cropedgeai
pip install uv
uv sync

For development: uv sync --group dev

Quick Start

1. Data Preparation

from cropedgeai.dataset import WeedCropDatasetLoader

loader = WeedCropDatasetLoader("path/to/weed-crop-dataset")
dataset = loader()

print(f"Loaded {len(dataset)} annotations")
print(f"Classes: {dataset['class_name'].unique()}")

2. Exploratory Data Analysis

from cropedgeai.eda import WeedCropEDA, WeedCropVisualizer

eda = WeedCropEDA(dataset, dataset_name="My Dataset")
stats = eda.dataset_distribution()

visualizer = WeedCropVisualizer(eda)
visualizer.plot_class_balance()
visualizer.plot_spatial_distribution()

3. Dataset Splitting & Augmentation

from cropedgeai.dataset import DatasetSplitter, DatasetAugmenter

splitter = DatasetSplitter(dataset, validation_size=0.15, test_size=0.15, output_dir="./processed", organize_files=True)
train, val, test = splitter()

augmenter = DatasetAugmenter(train, "./augmented", "./processed")
augmented_dataset = augmenter(
    run_overlay=True,
    run_closeup=True,
    overlay_images=1000,
    weeds_per_image=5
)

4. Model Training & Benchmarking

from cropedgeai.experiments import YOLOExperiment

experiment = YOLOExperiment("config/baseline_experiment.yaml")
results = experiment()

5. Hyperparameter Optimization

from cropedgeai.experiments import YOLOHyperparameterOptimizer

optimizer = YOLOHyperparameterOptimizer("config/hpo_yolo11n.yaml")
hpo_results = optimizer()

6. Edge Deployment Optimization

from cropedgeai.experiments import YOLONCNNHyperparameterOptimizer

ncnn_optimizer = YOLONCNNHyperparameterOptimizer("config/ncnn_hpo.yaml")
results = ncnn_optimizer()

ncnn_path = ncnn_optimizer.export_ncnn(best_size) # Check results to confirm `best_size`

7. Batch Inference

cropedgeai model.pt input_folder/ output_folder/ \
  --conf-threshold 0.35 \
  --img-size 640 \
  --stats-csv detections.csv
from cropedgeai.inference import YOLOBatchProcessor

processor = YOLOBatchProcessor(
    model_path="best.pt",
    input_folder="test_images/",
    output_folder="results/",
    stats_csv_file="detection_stats.csv",
    conf_threshold=0.35
)
processor()

Configuration

Experiment

name: "My_Experiment"
dataset_yaml: "data/dataset.yaml"
models_to_test:
  yolo11n: "yolo11n.pt"
  yolo11s: "yolo11s.pt"
training_config:
  epochs: 100
  batch: 32
  imgsz: 640
  patience: 20

HPO

name: "crop_hpo"
dataset_yaml: "data/dataset.yaml"
base_model_path: "yolo11n.pt"
hyperparameter_search_space:
  lr0:
    type: "float"
    min: 0.0001
    max: 0.01
    log: true
  mosaic:
    type: "float"
    min: 0.0
    max: 1.0

CLI

cropedgeai model.pt input/ output/
cropedgeai model.ncnn input/ output/ --conf-threshold 0.4 --img-size 416
cropedgeai --help

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cropedgeai-0.1.0.tar.gz (65.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cropedgeai-0.1.0-py3-none-any.whl (70.3 kB view details)

Uploaded Python 3

File details

Details for the file cropedgeai-0.1.0.tar.gz.

File metadata

  • Download URL: cropedgeai-0.1.0.tar.gz
  • Upload date:
  • Size: 65.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for cropedgeai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4eff1c23ed88f4496a3b3a50a0c074513a51f692826d878c393145d081cba3c6
MD5 956e9d8b83b1ee0b6595482ab4bb7ce3
BLAKE2b-256 060ef83cfc4827358eb60817189d69019ecabdfdd2bed5bd69b1e92a26d7ecb3

See more details on using hashes here.

File details

Details for the file cropedgeai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cropedgeai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 70.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for cropedgeai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2239d5ee76571ab98411be92164d3792f392dcc93651d9d56dcdd50d83ff61fa
MD5 2a2b6e395dee0862ee4ecb797f8f44f4
BLAKE2b-256 c0c8d4fdf3eb6ffb38e5618487c93f16b873fbc6767746c7e1050638dd1494eb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page