Skip to main content

agml logo


👨🏿‍💻👩🏽‍💻🌈🪴 Want to join the AI Institute for Food Systems team and help lead AgML development? 🪴🌈👩🏼‍💻👨🏻‍💻

We're looking to hire a postdoc with both Python library development and ML experience. Send your resume and GitHub profile link to jmearles@ucdavis.edu!


Overview

AgML is a comprehensive library for agricultural machine learning. Currently, AgML provides access to a wealth of public agricultural datasets for common agricultural deep learning tasks.

AgML supports both the TensorFlow and PyTorch machine learning frameworks.

To browse our latest datasets, view our full set of documentation, and compare model performance on your crops / tasks of interest, please visit project-agml.github.io.

Installation

To install the latest release of AgML, run the following command:

pip install agml

Quick Start

AgML datasets are hosted on the Hugging Face Hub under the Project-AgML organization. You can start off by using the HuggingFaceDataLoader to download and load a dataset directly into a native Hugging Face DatasetDict:

from agml.data import HuggingFaceDataLoader

# Load a dataset from the Hub
loader = HuggingFaceDataLoader("Project-AgML/apple_flower_segmentation")

# Load a specific config/subset (e.g. an augmented variant)
loader = HuggingFaceDataLoader("Project-AgML/apple_flower_segmentation", config="augmented")

HuggingFaceDataLoader automatically casts image-like columns (image, mask, and image-typed label columns) to the Hugging Face Image type for decoded pixel access.

You can split the dataset into train/val/test sets, with optional stratification across one or more columns:

dataset = loader.split(val_size=0.1, test_size=0.1, stratify_cols="label")
# Returns a DatasetDict with 'train', 'val', and 'test' splits

# Access the underlying DatasetDict at any time
dataset = loader.dataset

For any preprocessing, inference, or training beyond loading and splitting, use the datasets and transformers libraries directly. Since loader.dataset is a native Hugging Face DatasetDict, it works out of the box with datasets' map, filter, and with_transform methods for preprocessing, and with transformers' Trainer, Pipeline, and model classes for training and inference — there's no separate AgML-specific processing API to learn.

from transformers import AutoImageProcessor, AutoModelForImageClassification, Trainer

processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224")
model = AutoModelForImageClassification.from_pretrained(
    "google/vit-base-patch16-224",
    num_labels=dataset["train"].features["label"].num_classes,
)

def preprocess(batch):
    batch["pixel_values"] = processor(batch["image"], return_tensors="pt")["pixel_values"]
    return batch

dataset = dataset.with_transform(preprocess)

trainer = Trainer(model=model, train_dataset=dataset["train"], eval_dataset=dataset["val"])
trainer.train()

Public Datasets

AgML contains a wide variety of public datasets from various locations across the world:

AgML Dataset World Map

Use the Dataset Search experience for filtering and previews. For programmatic filtering, agml.data.public_data_sources(...) supports task and modality filters.

iNatAg and iNatAg-mini

AgML provides an API with direct access to iNatAg (and iNatAg-mini), one of the world's largest collections of agricultural images dedicated for the task of image classification. Collectively, this dataset contains over 4 million images along with detailed species classificaations and enables access to a variety of large-scale agricultural machine learning tasks. You can instantiate the iNatAg (or iNatAg-mini, a smaller variant of iNatAg for smaller-scale applications) dataset as follows:

# To select a collection of scientific family names.
loader = agml.data.AgMLDataLoader.from_parent("iNatAg", filters={"family_name": ["...", "..."]})

# To select common names.
loader = agml.data.AgMLDataLoader.from_parent("iNatAg", filters={"common_name": "..."})

Usage Information

Using Public Agricultural Data

AgML aims to provide easy access to a range of existing public agricultural datasets The core of AgML's public data pipeline is AgMLDataLoader. You can use the AgMLDataLoader or agml.data.download_public_dataset() to download the dataset locally from which point it will be automatically loaded from the disk on future runs. From this point, the data within the loader can be split into train/val/test sets, batched, have augmentations and transforms applied, and be converted into a training-ready dataset (including batching, tensor conversion, and image formatting).

Annotation Formats

A core aim of AgML is to provide datasets in a standardized format, enabling the synthesizing of multiple datasets into a single training pipeline. Datasets on the Hugging Face Hub encode annotations as columns on the underlying Dataset/DatasetDict:

  • Image Classification: a label column of type ClassLabel.
  • Object Detection: an objects column, holding COCO-style bounding boxes (un-normlized [x_min, y_min, width, height]) and corresponding category IDs as a ClassLabel per image.
  • Semantic Segmentation: a mask column, a single-channel (L-mode) image the same size as the corresponding image.

Contributions

We welcome contributions! If you would like to contribute a new feature, fix an issue that you've noticed, or even just mention a bug or feature that you would like to see implemented, please don't hesitate to use the Issues tab to bring it to our attention.

See the contributing guidelines for more information, or the guide to contributing leaderboard results if you have benchmark results to add.

Funding

This project is partly funded by the National AI Institute for Food Systems.

Metadata

Release files for agml 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agml 0.8.1
File Size Uploaded
agml-0.8.1.tar.gz 6.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for agml 0.8.1
File Interpreter ABI Platform
agml-0.8.1-py3-none-any.whl Python 3 none any Details

Total release size: 6.9 MB

Release files / agml-0.8.1.tar.gz

Download URL agml-0.8.1.tar.gz
Size 6.2 MB
Tags Source
SHA-256 checksum
How to use checksums
4ae4b16e783cd771b676650845bd5a3276a6b0a6fc4f7ef942ac0c5c41d50d9a
BLAKE2b-256 checksum
How to use checksums
3b7902e752417880f0e413613c7d3e2e4001bfe3cdfef02d6661218b3b144e6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / agml-0.8.1-py3-none-any.whl

Download URL agml-0.8.1-py3-none-any.whl
Size 778.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b5b3c88cb6fc17c1fd22bbcae77d9e76603cb3011cb625c16c080a32014f59fe
BLAKE2b-256 checksum
How to use checksums
7a919e2148fd36981da8018e1d7a9c6c2becfe8b4b9829bd6c8044f68dc6587f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.8.1 This release

2 release files

0.8.0

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

1 release file

0.7.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page