AgriFieldNet#

class torchgeo.datasets.AgriFieldNet(paths='data', crs=None, classes=[0, 1, 2, 3, 4, 5, 6, 8, 9, 13, 14, 15, 16, 36], bands=('B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B8A', 'B09', 'B11', 'B12'), transforms=None, cache=True, download=False, time_series=False)[source]#

Bases: RasterDataset

AgriFieldNet India Challenge dataset.

The AgriFieldNet India Challenge dataset includes satellite imagery from Sentinel-2 cloud free composites (single snapshot) and labels for crop type that were collected by ground survey. The Sentinel-2 data are then matched with corresponding labels. The dataset contains 7081 fields, which have been split into training and test sets (5551 fields in the train and 1530 fields in the test). Satellite imagery and labels are tiled into 256x256 chips adding up to 1217 tiles. The fields are distributed across all chips, some chips may only have train or test fields and some may have both. Since the labels are derived from data collected on the ground, not all the pixels are labeled in each chip. If the field ID for a pixel is set to 0 it means that pixel is not included in either of the train or test set (and correspondingly the crop label will be 0 as well). For this challenge train and test sets have slightly different crop type distributions. The train set follows the distribution of ground reference data which is a skewed distribution with a few dominant crops being over represented. The test set was drawn randomly from an area weighted field list that ensured that fields with less common crop types were better represented in the test set. The original dataset can be downloaded from Source Cooperative.

Dataset format:

  • images are 12-band Sentinel-2 data

  • masks are tiff images with unique values representing the class and field id

Dataset classes:

    1. No-Data

    1. Wheat

    1. Mustard

    1. Lentil

    1. No Crop/Fallow

    1. Green pea

    1. Sugarcane

    1. Garlic

    1. Maize

    1. Gram

    1. Coriander

    1. Potato

    1. Berseem

    1. Rice

If you use this dataset in your research, please cite the following dataset:

Note

This dataset requires the following additional library to be installed:

  • azcopy: to download the dataset from Source Cooperative.

Added in version 0.6.

filename_regex = '\n        ^ref_agrifieldnet_competition_v1_source_\n        (?P<unique_folder_id>[a-z0-9]{5})\n        _(?P<band>B[0-9A-Z]{2})_10m\n    '#

Regular expression used to extract date from filename.

The expression should use named groups. The expression may contain any number of groups. The following groups are specifically searched for by the base class:

  • date: used to calculate mint and maxt for index insertion

  • start: used to calculate mint for index insertion

  • stop: used to calculate maxt for index insertion

When separate_files is True, the following additional groups are searched for to find other files:

  • band: replaced with requested band name

rgb_bands: tuple[str, ...] = ('B04', 'B03', 'B02')#

Names of RGB bands in the dataset, used for plotting

all_bands: tuple[str, ...] = ('B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B8A', 'B09', 'B11', 'B12')#

Names of all available bands in the dataset

cmap: ClassVar[dict[int, tuple[int, int, int, int]]] = {0: (0, 0, 0, 255), 1: (255, 211, 0, 255), 2: (255, 37, 37, 255), 3: (0, 168, 226, 255), 4: (255, 158, 9, 255), 5: (37, 111, 0, 255), 6: (255, 255, 0, 255), 8: (111, 166, 0, 255), 9: (0, 175, 73, 255), 13: (222, 166, 9, 255), 14: (222, 166, 9, 255), 15: (124, 211, 255, 255), 16: (226, 0, 124, 255), 36: (137, 96, 83, 255)}#

Color map for the dataset, used for plotting

__init__(paths='data', crs=None, classes=[0, 1, 2, 3, 4, 5, 6, 8, 9, 13, 14, 15, 16, 36], bands=('B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B8A', 'B09', 'B11', 'B12'), transforms=None, cache=True, download=False, time_series=False)[source]#

Initialize a new AgriFieldNet dataset instance.

Parameters:
  • paths (str | PathLike[str] | Iterable[str | PathLike[str]]) – one or more root directories to search for files to load

  • crs (CRS | None) – coordinate reference system (CRS) to warp to (defaults to the CRS of the first file found)

  • classes (list[int]) – list of classes to include, the rest will be mapped to 0 (defaults to all classes)

  • bands (Sequence[str]) – the subset of bands to load

  • transforms (Callable[[dict[str, Any]], dict[str, Any]] | None) – a function/transform that takes input sample and its target as entry and returns a transformed version

  • cache (bool) – if True, cache the dataset in memory

  • download (bool) – if True, download dataset and store it in the root directory

  • time_series (bool) – if True, stack data along the time series dimension [T, C, H, W]. If False, merge data into a [C, H, W] mosaic.

Raises:

DatasetNotFoundError – If dataset is not found and download is False.

Added in version 0.9: The time_series parameter.

filename_glob = 'ref_agrifieldnet_competition_v1_source_*_{}_10m.*'#

Glob expression used to search for files.

This expression should be specific enough that it will not pick up files from other datasets. It should not include a file extension, as the dataset may be in a different file format than what it was originally downloaded as.

__getitem__(index)[source]#

Retrieve input, target, and/or metadata indexed by spatiotemporal slice.

Parameters:

index (slice | tuple[slice] | tuple[slice, slice] | tuple[slice, slice, slice]) – [xmin:xmax:xres, ymin:ymax:yres, tmin:tmax:tres] coordinates to index.

Returns:

Sample of input, target, and/or metadata at that index.

Raises:

IndexError – If index is not found in the dataset.

Return type:

dict[str, Any]

__annotate_func__()#

The type of the None singleton.

plot(sample, show_titles=True, suptitle=None)[source]#

Plot a sample from the dataset.

Parameters:
  • sample (dict[str, Any]) – a sample returned by __getitem__()

  • show_titles (bool) – flag indicating whether to show titles above each panel

  • suptitle (str | None) – optional string to use as a suptitle

Returns:

a matplotlib Figure with the rendered sample

Raises:

RGBBandsMissingError – If bands does not include all RGB bands.

Return type:

Figure