What is TorchGeo of PyTorch?
This library is part of the PyTorch project. PyTorch is an open source machine learning framework. Programmers can build a complex neural network with ease using PyTorch as it has a core data structure, Tensor, multi-dimensional array like Numpy arrays. PyTorch use is increasing in current industries and in the research community as it is flexible, faster, easy to get the project up and running, due to which PyTorch is one of the top deep learning tools.
TorchGeo of PyTorch-
The torchgeo package consists of popular datasets, model architectures, and common image transformations for geospatial data.
The goal of this library is to make it simple:
- for machine learning experts to use geospatial data in their workflows, and
- for remote sensing experts to use their data in machine learning workflows.
The implementation of TorchGeo follows the design of other PyTorch domain libraries to reduce the amount of new concepts that a user must learn to integrate it with their existing workflow.
TorchGeo is a Python package that allows users to transparently use heterogenous geospatial data in PyTorch-based deep learning pipelines. Specifically, TorchGeo provides:
1. Data loaders for common geospatial datasets from the literature.
2. Data loaders for combining arbitrary geospatial raster and vector data layers with the ability to sample pixel-aligned patches on-the-fly.
3. Augmentations that are appropriate for multispectral imagery and geospatial data.
4. Data samplers appropriate for geospatial data.
5. Pre-trained models for many common remotely sensed imagery sources.
Datasets-
The dataset implementations consist of both benchmark datasets that allow users to interface with common datasets used in RS literature and generic datasets that allow users to interface with common geospatial data layers such as Landsat or Sentinel 2 imagery. Either of these types of datasets can also be geospatial datasets, i.e. datasets that contain geospatial metadata and can be sampled as such. These are part of the core contribution of TorchGeo and we describe them further in the following section.
In TorchGeo, we define two types of datasets: Geospatial Datasets and Non-geospatial Datasets. These abstract base classes are documented in more detail in Base Classes.
Geospatial Datasets-
Geospatial DataSet is designed for datasets that contain geospatial information, like latitude, longitude, coordinate system, and projection.
- Canadian Building Footprints
CLASS
torchgeo.datasets.CanadianBuildingFootprints(root='data', crs=None, res=1e-05, transforms=None, download=False, checksum=False)
Bases: torchgeo.datasets.VectorDataset
Canadian Building Footprints dataset.
The Canadian Building Footprints dataset contains 11,842,186 computer generated building footprints in all Canadian provinces and territories in GeoJSON format. This data is freely available for download and use.
__init__(root='data', crs=None, res=1e-05, transforms=None, download=False, checksum=False)
Parameters-
- root (str) – root directory where dataset can be found
- crs (Optional[rasterio.crs.CRS]) – coordinate reference system (CRS) to warp to (defaults to the CRS of the first file found)
- res (float) – resolution of the dataset in units of CRS
- transforms (Optional[Callable[[Dict[str, Any]], Dict[str, Any]]]) – a function/transform that takes an input sample and returns a transformed version
- download (bool) – if True, download dataset and store it in the root directory
- checksum (bool) – if True, check the MD5 of the downloaded files (may be slow)
Raises
- FileNotFoundError – if no files are found in root
- RuntimeError – if download=False and data is not found, or checksum=True and checksums don’t match
- Chesapeake Bay High-Resolution Land Cover Project
CLASS
torchgeo.datasets.Chesapeake(root='data', crs=None, res=None, transforms=None, cache=True, download=False, checksum=False)
Bases: torchgeo.datasets.RasterDataset, abc.ABC
Abstract base class for all Chesapeake datasets.
Chesapeake Bay High-Resolution Land Cover Project dataset.
This dataset was collected by the Chesapeake Conservancy’s Conservation Innovation Center (CIC) in partnership with the University of Vermont and WorldView Solutions, Inc. It consists of one-meter resolution land cover information for the Chesapeake Bay watershed (~100,000 square miles of land).
__init__(root='data', crs=None, res=None, transforms=None, cache=True, download=False, checksum=False)
Parameters
- root (str) – root directory where dataset can be found
- crs (Optional[rasterio.crs.CRS]) – coordinate reference system (CRS) to warp to (defaults to the CRS of the first file found)
- res (Optional[float]) – resolution of the dataset in units of CRS (defaults to the resolution of the first file found)
- transforms (Optional[Callable[[Dict[str, Any]], Dict[str, Any]]]) – a function/transform that takes an input sample and returns a transformed version
- cache (bool) – if True, cache file handle to speed up repeated sampling
- download (bool) – if True, download dataset and store it in the root directory
- checksum (bool) – if True, check the MD5 of the downloaded files (may be slow)
Raises
- FileNotFoundError – if no files are found in root
- RuntimeError – if download=False but dataset is missing or checksum fails
- CVPR 2019 Chesapeake Land Cover dataset.
The CVPR 2019 Chesapeake Land Cover dataset contains two layers of NAIP aerial imagery, Landsat 8 leaf-on and leaf-off imagery, Chesapeake Bay land cover labels, NLCD land cover labels, and Microsoft building footprint labels.
This dataset was organized to accompany the 2019 CVPR paper, “Large Scale High-Resolution Land Cover Mapping with Multi-Resolution Data”.
The paper “Resolving label uncertainty with implicit generative models” added an additional layer of data to this dataset containing a prior over the Chesapeake Bay land cover classes generated from the NLCD land cover labels.
Parameters-
- root (str) – root directory where dataset can be found
- splits (Sequence[str]) – a list of strings in the format “{state}-{train,val,test}” indicating the subset of data to use, for example “ny-train”
- layers (List[str]) – a list containing a subset of “naip-new”, “naip-old”, “lc”, “nlcd”, “landsat-leaf-on”, “landsat-leaf-off”, “buildings”, or “prior_from_cooccurrences_101_31_no_osm_no_buildings” indicating which layers to load
- transforms (Optional[Callable[[Dict[str, Any]], Dict[str, Any]]]) – a function/transform that takes an input sample and returns a transformed version
- cache (bool) – if True, cache file handle to speed up repeated sampling
- download (bool) – if True, download dataset and store it in the root directory
- checksum (bool) – if True, check the MD5 of the downloaded files (may be slow)
Raises
- FileNotFoundError – if no files are found in root
- RuntimeError – if download=False but dataset is missing or checksum fails
- Cropland Data Layer (CDL)
CLASS
torchgeo.datasets.CDL(root='data', crs=None, res=None, transforms=None, cache=True, download=False, checksum=False)
Bases: torchgeo.datasets.RasterDataset
Cropland Data Layer (CDL) dataset.
The Cropland Data Layer, hosted on CropScape, provides a raster, geo-referenced, crop-specific land cover map for the continental United States. The CDL also includes a crop mask layer and planting frequency layers, as well as boundary, water and road layers. The Boundary Layer options provided are County, Agricultural Statistics Districts (ASD), State, and Region. The data is created annually using moderate resolution satellite imagery and extensive agricultural ground truth.
Parameters
- root (str) – root directory where dataset can be found
- crs (Optional[rasterio.crs.CRS]) – coordinate reference system (CRS) to warp to (defaults to the CRS of the first file found)
- res (Optional[float]) – resolution of the dataset in units of CRS (defaults to the resolution of the first file found)
- transforms (Optional[Callable[[Dict[str, Any]], Dict[str, Any]]]) – a function/transform that takes an input sample and returns a transformed version
- cache (bool) – if True, cache file handle to speed up repeated sampling
- download (bool) – if True, download dataset and store it in the root directory
- checksum (bool) – if True, check the MD5 after downloading files (may be slow)
Raises
- FileNotFoundError – if no files are found in root
- RuntimeError – if download=False but dataset is missing or checksum fails
- Landsat-
CLASS
torchgeo.datasets.Landsat(root='data', crs=None, res=None, bands=[], transforms=None, cache=True)
Bases: torchgeo.datasets.RasterDataset, abc.ABC
Abstract base class for all Landsat datasets.
Landsat is a joint NASA/USGS program, providing the longest continuous space-based record of Earth’s land in existence.
Parameters
- root (str) – root directory where dataset can be found
- crs (Optional[rasterio.crs.CRS]) – coordinate reference system (CRS) to warp to (defaults to the CRS of the first file found)
- res (Optional[float]) – resolution of the dataset in units of CRS (defaults to the resolution of the first file found)
- bands (Sequence[str]) – bands to return (defaults to all bands)
- transforms (Optional[Callable[[Dict[str, Any]], Dict[str, Any]]]) – a function/transform that takes an input sample and returns a transformed version
- cache (bool) – if True, cache file handle to speed up repeated sampling
Raises
FileNotFoundError – if no files are found in root
- National Agriculture Imagery Program (NAIP)-
CLASS
torchgeo.datasets.NAIP(root, crs=None, res=None, transforms=None, cache=True)
Bases: torchgeo.datasets.RasterDataset
National Agriculture Imagery Program (NAIP) dataset.
The National Agriculture Imagery Program (NAIP) acquires aerial imagery during the agricultural growing seasons in the continental U.S. A primary goal of the NAIP program is to make digital ortho photography available to governmental agencies and the public within a year of acquisition.
NAIP is administered by the USDA’s Farm Service Agency (FSA) through the Aerial Photography Field Office in Salt Lake City. This “leaf-on” imagery is used as a base layer for GIS programs in FSA’s County Service Centers, and is used to maintain the Common Land Unit (CLU) boundaries.
- Sentinel-
CLASS
torchgeo.datasets.Sentinel(root, crs=None, res=None, transforms=None, cache=True)
Bases: torchgeo.datasets.RasterDataset
Abstract base class for all Sentinel datasets.
Sentinel is a family of satellites launched by the European Space Agency (ESA) under the Copernicus Programme.
Sentinel-2 dataset.
The Copernicus Sentinel-2 mission comprises a constellation of two polar-orbiting satellites placed in the same sun-synchronous orbit, phased at 180° to each other. It aims at monitoring variability in land surface conditions, and its wide swath width (290 km) and high revisit time (10 days at the equator with one satellite, and 5 days with 2 satellites under cloud-free conditions which results in 2-3 days at mid-latitudes) will support monitoring of Earth’s surface changes.
Parameters
- root (str) – root directory where dataset can be found
- crs (Optional[rasterio.crs.CRS]) – coordinate reference system (CRS) to warp to (defaults to the CRS of the first file found)
- res (Optional[float]) – resolution of the dataset in units of CRS (defaults to the resolution of the first file found)
- bands (Sequence[str]) – bands to return (defaults to all bands)
- transforms (Optional[Callable[[Dict[str, Any]], Dict[str, Any]]]) – a function/transform that takes an input sample and returns a transformed version
- cache (bool) – if True, cache file handle to speed up repeated sampling
Raises
FileNotFoundError – if no files are found in root.
Non-geospatial Datasets
Vision DataSet is designed for datasets that lack geospatial information. These datasets can still be combined using concat dataset.
- ADVANCE (AuDio Visual Aerial sceNe reCognition datasEt)-
CLASS
torchgeo.datasets.ADVANCE(root='data', transforms=None, download=False, checksum=False)
Bases: torchgeo.datasets.VisionDataset
ADVANCE dataset.
The ADVANCE dataset is a dataset for audio visual scene recognition.
Dataset features:
- 5,075 pairs of geotagged audio recordings and images
- three spectral bands - RGB (512x512 px)
- 10-second audio recordings
Dataset format:
- images are three-channel jpgs
- audio files are in wav format
Parameters
- root (str) – root directory where dataset can be found
- transforms (Optional[Callable[[Dict[str, torch.Tensor]], Dict[str, torch.Tensor]]]) – a function/transform that takes input sample and its target as entry and returns a transformed version
- download (bool) – if True, download dataset and store it in the root directory
- checksum (bool) – if True, check the MD5 of the downloaded files (may be slow)
Raises
RuntimeError – if download=False and data is not found, or checksums don’t match
- Smallholder Cashew Plantations in Benin-
CLASS
torchgeo.datasets.BeninSmallHolderCashews(root='data', chip_size=256, stride=128, bands=('B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B8A', 'B09', 'B11', 'B12', 'CLD'), transforms=None, download=False, api_key=None, checksum=False, verbose=False)
Bases: torchgeo.datasets.VisionDataset
Smallholder Cashew Plantations in Benin dataset.
This dataset contains labels for cashew plantations in a 120 km2 area in the center of Benin. Each pixel is classified for Well-managed plantation, Poorly-managed plantation, No plantation and other classes. The labels are generated using a combination of ground data col