Skip to main content

A comprehensive library for agricultural deep learning

Project description

agml framework


👨🏿‍💻👩🏽‍💻🌈🪴 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. In the future, AgML will provide ag-specific ML functionality related to data, training, and evaluation. Here's a conceptual diagram of the overall framework.

agml framework

AgML supports both the TensorFlow and PyTorch machine learning frameworks.

Installation

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

pip install agml

Quick Start

AgML is designed for easy usage of agricultural data in a variety of formats. You can start off by using the AgMLDataLoader to download and load a dataset into a container:

import agml

loader = agml.data.AgMLDataLoader('apple_flower_segmentation')

You can then use the in-built processing methods to get the loader ready for your training and evaluation pipelines. This includes, but is not limited to, batching data, shuffling data, splitting data into training, validation, and test sets, and applying transforms.

import albumentations as A

# Batch the dataset into collections of 8 pieces of data:
loader.batch(8)

# Shuffle the data:
loader.shuffle()

# Apply transforms to the input images and output annotation masks:
loader.mask_to_channel_basis()
loader.transform(
    transform = A.RandomContrast(),
    dual_transform = A.Compose([A.RandomRotate90()])
)

# Split the data into train/val/test sets.
loader.split(train = 0.8, val = 0.1, test = 0.1)

The split datasets can be accessed using loader.train_data, loader.val_data, and loader.test_data. Any further processing applied to the main loader will be applied to the split datasets, until the split attributes are accessed, at which point you need to apply processing independently to each of the loaders. You can also turn toggle processing on and off using the loader.eval(), loader.reset_preprocessing(), and loader.disable_preprocessing() methods.

You can visualize data using the agml.viz module, which supports multiple different types of visualization for different data types:

# Disable processing and batching for the test data:
test_ds = loader.test_data
test_ds.batch(None)
test_ds.reset_prepreprocessing()

# Visualize the image and mask side-by-side:
agml.viz.visualize_image_and_mask(test_ds[0])

# Visualize the mask overlaid onto the image:
agml.viz.visualize_overlaid_masks(test_ds[0])

AgML supports both the TensorFlow and PyTorch libraries as backends, and provides functionality to export your loaders to native TensorFlow and PyTorch formats when you want to use them in a training pipeline. This includes both exporting the AgMLDataLoader to a tf.data.Dataset or torch.utils.data.DataLoader, but also internally converting data within the AgMLDataLoader itself, enabling access to its core functionality.

# Export the loader as a `tf.data.Dataset`:
train_ds = loader.train_data.export_tensorflow()

# Convert to PyTorch tensors without exporting.
train_ds = loader.train_data
train_ds.as_torch_dataset()

You're now ready to use AgML for training your own models!

Public Dataset Listing

Dataset Task Number of Images
bean_disease_uganda Image Classification 1295
carrot_weeds_germany Semantic Segmentation 60
plant_seedlings_aarhus Image Classification 5539
soybean_weed_uav_brazil Image Classification 15336
sugarcane_damage_usa Image Classification 153
crop_weeds_greece Image Classification 508
sugarbeet_weed_segmentation Semantic Segmentation 1931
rangeland_weeds_australia Image Classification 17509
fruit_detection_worldwide Object Detection 565
leaf_counting_denmark Image Classification 9372
apple_detection_usa Object Detection 2290
mango_detection_australia Object Detection 1730
apple_flower_segmentation Semantic Segmentation 148
apple_segmentation_minnesota Semantic Segmentation 670
rice_seedling_segmentation Semantic Segmentation 224
plant_village_classification Image Classification 55448
autonomous_greenhouse_regression Image Regression 389
grape_detection_syntheticday Object Detection 448
grape_detection_californiaday Object Detection 126
grape_detection_californianight Object Detection 150
guava_disease_pakistan Image Classification 306
apple_detection_spain Object Detection 967
apple_detection_drone_brazil Object Detection 689
plant_doc_classification Image Classification 2598
plant_doc_detection Object Detection 2598
wheat_head_counting Object Detection 6512
peachpear_flower_segmentation Semantic Segmentation 42
red_grapes_and_leaves_segmentation Semantic Segmentation 258
white_grapes_and_leaves_segmentation Semantic Segmentation 273

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).

To see the various ways in which you can use AgML datasets in your training pipelines, check out the example notebook.

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. To this end, we provide annotations in the following formats:

  • Image Classification: Image-To-Label-Number
  • Object Detection: COCO JSON
  • Semantic Segmentation: Dense Pixel-Wise

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.

Funding

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

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

agml-0.3.0.tar.gz (183.4 kB view details)

Uploaded Source

Built Distribution

agml-0.3.0-py3-none-any.whl (238.6 kB view details)

Uploaded Python 3

File details

Details for the file agml-0.3.0.tar.gz.

File metadata

  • Download URL: agml-0.3.0.tar.gz
  • Upload date:
  • Size: 183.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for agml-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3ba4437c95d3e041e8364f55b0e7d9e015d2a075fbfd7c16423f65be8c8cf6fa
MD5 c6ded2cb5ffb46c07e42586cefcc9039
BLAKE2b-256 e9a32d73ec2500fc0f74ce54448051decde294fc19c22c9442e35cce832206ed

See more details on using hashes here.

File details

Details for the file agml-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: agml-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 238.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for agml-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 87f56931f17bc4ffca27bb6039169cec595a800f27f238c9042080edbaea7a20
MD5 9b853afc1d79bf80af7529fa32fbc983
BLAKE2b-256 fe2d0489b2c215a71d79c9712f6cf892af95c6d745b2248bf386d0c44195a767

See more details on using hashes here.

Supported by

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