torchgeo.datasets#
TorchGeo defines several kinds of datasets for geospatial data.
Benchmark Datasets#
Curated benchmark datasets allow for model training and evaluation. They typically provide both input images and output labels, and target a variety of downstream applications.
Dataset |
Task |
Source |
# Samples |
# Classes |
Size (px) |
Resolution (m) |
Bands |
License |
|---|---|---|---|---|---|---|---|---|
C |
Google Earth, Freesound |
5,075 |
13 |
512x512 |
0.5 |
RGB |
CC-BY-4.0 |
|
S |
Sentinel-2 |
7,081 |
14 |
256x256 |
10 |
MSI |
CC-BY-4.0 |
|
R |
Pirelli Labs multi-sensor device |
9,358 |
air quality, weather |
CC-BY-4.0 |
||||
CD |
MAXAR, NAIP, Capella, Umbra |
3239 |
4 |
1024x1024 |
0.1–1 |
RGB, SAR |
CC-BY-4.0 AND CC-BY-NC-4.0 |
|
S |
Airbus Pléiades |
70 |
6 |
1,122x1,186 |
10 |
MSI |
CC-BY-4.0 |
|
R |
Sentinel-1/2 and Lidar |
256x256 |
10 |
SAR, MSI |
CC-BY-4.0 |
|||
C, R |
CSUAV AFRL, ISPRS, LINZ, AGRC |
388,435 |
2 |
256x256 |
0.15 |
RGB |
AGPL-3.0-only |
|
CD |
Sentinel-2 |
424 |
2 |
512x512 |
20 |
MSI |
OpenRAIL |
|
S |
Sentinel-1, TerraSAR-X, TanDEM-X, ENVISAT, ERS-1/2, ALOS PALSAR, and RADARSAT-1 |
19092 |
2 or 4 |
512x512 |
6-20 |
SAR |
CC-BY-4.0 |
|
CD |
Sentinel-2 |
356 |
2 |
512x512 |
10 |
MSI |
OpenRAIL |
|
S |
NAIP |
13, 54 |
1 |
MSI |
CC0-1.0 |
|||
S |
Sentinel-2 |
22,728 |
2 |
512x512 |
10 |
MSI |
CC-BY-4.0 |
|
C |
Sentinel-1/2, SRTM, ERA5 |
70,213 |
351 |
1x1 |
10 |
SAR, MSI, SRTM |
CC-BY-SA-4.0 |
|
S |
Aerial |
3,981 |
15 |
2,000x2,000 |
0.5 |
RGB |
CC-BY-4.0 |
|
OD |
Aerial |
23,463 |
20 |
800x800 |
0.5 |
RGB |
CC-BY-NC-4.0 |
|
S |
Sentinel-2 |
2,251 or 11,440 |
2 |
256x256 |
10 |
MSI |
CC-BY-4.0 |
|
S |
USGS National Map |
2,100 |
17 |
256x256 |
0.3 |
RGB |
CC-BY-4.0 |
|
DLRSD Multilabel |
C |
USGS National Map |
2,100 |
17 |
256x256 |
0.3 |
RGB |
CC-BY-4.0 |
OD |
Google Earth, Gaofen-2, Jilin-1, CycloMedia B.V. |
5,229 |
15 |
800–4000 |
RGB |
non-commercial |
||
S |
DigitalGlobe +Vivid |
803 |
7 |
2,448x2,448 |
0.5 |
RGB |
||
C, R |
Himawari |
189,364 |
8 |
512 |
5000 |
Infrared |
CC-BY-4.0 |
|
S |
Sentinel-1 |
66,810 |
2 |
256x256 |
5–20 |
SAR |
||
S |
NAIP, NLCD, OpenStreetMap |
10 |
1 |
MSI |
CC-BY-4.0 |
|||
C |
Sentinel-2 |
27,000 |
10 |
64x64 |
10 |
MSI |
MIT |
|
OD |
Aerial |
5,325 |
8 |
1,500x1500p |
0.01 |
RGB |
CC0-1.0 |
|
OD |
Gaofen/Google Earth |
15,000 |
37 |
1,024x1,024 |
0.3–0.8 |
RGB |
CC-BY-NC-SA-3.0 |
|
S,I |
Sentinel-2 |
70795 |
2,3 |
256x256 |
10 |
MSI |
Various |
|
C |
NAIP Aerial |
91,872 |
7 |
320x320 |
1 |
RGB |
CC-BY-NC-4.0 |
|
OD |
Drone imagery |
1,543 |
4 |
1,500x1,500 |
RGB |
CDLA-Permissive-1.0 |
||
S |
Gaofen-2 |
150 |
15 |
6,800x7,200 |
3 |
RGB |
||
S |
Aerial |
7,783 |
11 |
1,000x1,000 |
1 |
RGB, DEM |
CC-BY-4.0 |
|
S |
Landsat, CDL |
1 |
8,000x8,000 |
30 |
MSI |
CC-BY-4.0 |
||
OD,C |
Aerial |
591 |
33 |
200x200 |
0.1–1 |
RGB |
CC-BY-4.0 |
|
S |
Aerial |
360 |
2 |
5,000x5,000 |
0.3 |
RGB |
||
S |
Sentinel-2 |
4,688 |
7 |
3,035x2,016 |
10 |
MSI |
CC-BY-SA-4.0 |
|
S |
Landsat 7 |
206 |
5 |
8,400x7,500 |
15, 30 |
MSI |
CC0-1.0 |
|
S |
Landsat 8 |
96 |
5 |
8,900x8,900 |
15, 30 |
MSI |
CC0-1.0 |
|
CD |
Google Earth |
985 |
2 |
1,024x1,024 |
0.5 |
RGB |
||
CD |
Google Earth |
637 |
2 |
1,024x1,024 |
0.5 |
RGB |
||
S |
Aerial |
10,674 |
5 |
512x512 |
0.25–0.5 |
RGB |
CC-BY-NC-SA-4.0 |
|
S |
Google Earth |
5,987 |
7 |
1,024x1,024 |
0.3 |
RGB |
CC-BY-NC-SA-4.0 |
|
S |
Sentinel-1/2,EnMAP,HySpex |
3 |
20 |
100x120, 300x360, 1364x1636, 10000x12000, 15000x18000 |
0.3–30 |
HSI |
CC-BY-SA-4.0 |
|
S |
Sentinel, MapZen/TileZen, OpenStreetMap |
1,748 |
2 |
2,147x2,313 |
20 |
SAR |
MIT |
|
S |
Sentinel-1/2, ESA WorldCover, NOAA VIIRS DNB |
1018 |
1 |
1920x1920 |
10–463.83 |
SAR, MSI, 2020_Map, avg_rad |
CC-BY-4.0 |
|
OD |
PlanetScope |
707 |
1 |
256x256 |
3 |
RGB |
Apache-2.0 |
|
CD |
Sentinel-2 |
24 |
2 |
241–1,180 |
60 |
MSI |
CC-BY-NC-SA-4.0 |
|
I |
Sentinel-1/2 |
2,433 |
19 |
128x128xT |
10 |
MSI |
CC-BY-4.0 |
|
C |
Google Earth |
30,400 |
38 |
256x256 |
0.06–5 |
RGB |
CC-BY-4.0 |
|
S |
Aerial |
38 |
6 |
6,000x6,000 |
0.05 |
MSI |
||
C, R |
Sentinel-1 |
3,327 |
2 |
512x512 |
10 |
SAR |
OpenRAIL |
|
C |
Google Earth |
31,500 |
45 |
256x256 |
0.2–30 |
RGB |
CC-BY-NC-4.0 |
|
OD, R |
Aerial |
100 |
6 |
4,000x4,000 |
0.02 |
RGB |
CC-BY-4.0 |
|
S |
Planetscope |
70 |
2 |
256x256 |
4.7 |
RGB + NIR |
NICFI AND CC-BY-4.0 |
|
S |
Sentinel-1/2, MODIS |
180,662 |
33 |
256x256 |
10 |
SAR, MSI |
CC-BY-4.0 |
|
R |
Fish-eye |
363,375 |
64x64 |
RGB |
CC-BY-4.0 |
|||
OD |
Aerial |
2513 |
9 |
~2700x~4800 |
RGB |
CC-BY-NC-4.0 |
||
S |
Lansat & CDL |
25K |
134 |
264x264 |
30 |
MSI |
CC0-1.0 |
|
S |
Lansat & NLCD |
25K |
17 |
264x264 |
30 |
MSI |
CC0-1.0 |
|
S |
Sentinel-2 |
1,759,830 |
33 |
120x120 |
10 |
MSI |
CC-BY-4.0 |
|
C |
Sentinel-1/2 |
400,673 |
17 |
32x32 |
10 |
SAR, MSI |
CC-BY-4.0 |
|
S |
Aerial |
272 |
2 |
256x256 |
10 |
RGB + NIR |
CC-BY-NC-4.0 |
|
S |
Sentinel-2 |
10 |
256x256 |
10 |
MSI |
CC-BY-4.0 |
||
S |
OpenStreetMap & Sentinel-2 |
27K |
2 |
228x228 |
10 |
MSI |
CC-BY-4.0 |
|
R |
MODIS |
11k |
32x32 |
MSI |
CC-BY-SA-4.0 |
|||
C, R, S |
Aerial, Sentinel-1/2 |
50K |
12, 15, 20 |
6, 20, 304 |
0.2, 10 |
CIR, MSI, SAR |
CC-BY-4.0 |
|
R |
GOES 8–16 |
108,110 |
256x256 |
4K–8K |
MSI |
CC-BY-4.0 |
||
C |
USGS National Map |
2,100 |
21 |
256x256 |
0.3 |
RGB |
public domain |
|
R |
NAIP Aerial |
100K |
4 |
RGB, NIR |
CC-BY-4.0 |
|||
I |
Google Earth, Vaihingen |
800 |
10 |
358–1,728 |
0.08–2 |
RGB |
CC-BY-NC-4.0 |
|
S |
Aerial |
33 |
6 |
1,281–3,816 |
0.09 |
RGB |
||
R |
Landsat8, Sentinel-1 |
2615 |
CC-BY-NC-ND-4.0 |
|||||
I, T |
Sentinel-2 |
116K |
48 |
24x24 |
10 |
MSI |
CC-BY-NC-4.0 |
|
CD |
Maxar |
3,732 |
4 |
1,024x1,024 |
0.8 |
RGB |
CC-BY-NC-SA-4.0 |
Copernicus-Bench#
Copernicus-Bench is a comprehensive evaluation benchmark with 15 downstream tasks hierarchically organized across preprocessing (e.g., cloud removal), base applications (e.g., land cover classification), and specialized applications (e.g., air quality estimation). This benchmark enables systematic assessment of foundation model performances across various Sentinel missions on different levels of practical applications.
Level |
Dataset |
Task |
Source |
# Samples |
# Classes |
Size (px) |
Resolution (m) |
Bands |
License |
|---|---|---|---|---|---|---|---|---|---|
L1 |
Cloud-S2 |
S |
Sentinel-2 |
2,817 |
4 |
512x512 |
10 |
MSI |
CC0-1.0 |
L1 |
Cloud-S3 |
S |
Sentinel-3 |
1,995 |
5 |
256x256 |
300 |
MSI |
CC-BY-4.0 |
L2 |
EuroSAT-S1 |
C |
Sentinel-1 |
27,000 |
10 |
64x64 |
10 |
SAR |
CC-BY-4.0 |
L2 |
EuroSAT-S2 |
C |
Sentinel-2 |
27,000 |
10 |
64x64 |
10 |
SAR |
MIT |
L2 |
BigEarthNet-S1 |
C |
Sentinel-1 |
24,002 |
19 |
120x120 |
10 |
SAR |
CDLA-Permissive-1.0 |
L2 |
BigEarthNet-S2 |
C |
Sentinel-2 |
24,002 |
19 |
120x120 |
10 |
MSI |
CDLA-Permissive-1.0 |
L2 |
LC100Cls-S3 |
C |
Sentinel-3 |
8,635 |
23 |
96x96 |
300 |
MSI |
CC-BY-4.0 |
L2 |
LC100Seg-S3 |
S |
Sentinel-3 |
8,635 |
23 |
96x96 |
300 |
MSI |
CC-BY-4.0 |
L2 |
DFC2020-S1 |
S |
Sentinel-1 |
5,128 |
10 |
256x256 |
10 |
SAR |
CC-BY-4.0 |
L2 |
DFC2020-S2 |
S |
Sentinel-2 |
5,128 |
10 |
256x256 |
10 |
MSI |
CC-BY-4.0 |
L3 |
Flood-S1 |
CD |
Sentinel-1 |
5,000 |
3 |
224x224 |
10 |
SAR |
MIT |
L3 |
LCZ-S2 |
C |
Sentinel-2 |
25,000 |
17 |
32x32 |
10 |
MSI |
CC-BY-4.0 |
L3 |
Biomass-S3 |
R |
Sentinel-3 |
5,000 |
96x96 |
300 |
MSI |
CC-BY-4.0 |
|
L3 |
AQ-NO2-S5P |
R |
Sentinel-5P |
2,467 |
56x56 |
1,000 |
CC-BY-4.0 |
||
L3 |
AQ-O3-S5P |
R |
Sentinel-5P |
2,467 |
56x56 |
1,000 |
CC-BY-4.0 |
SpaceNet#
The SpaceNet Dataset is hosted as an Amazon Web Services (AWS) Public Dataset. It contains ~67,000 square km of very high-resolution imagery, >11M building footprints, and ~20,000 km of road labels to ensure that there is adequate open source data available for geospatial machine learning research. SpaceNet Challenge Dataset’s have a combination of very high resolution satellite imagery and high quality corresponding labels for foundational mapping features such as building footprints or road networks.
Dataset |
Task |
Source |
# Samples |
# Classes |
Size (px) |
Resolution (m) |
Bands |
License |
|---|---|---|---|---|---|---|---|---|
SpaceNet 1 |
I |
WorldView-2 |
9,735 |
406x439, 102x110 |
0.5–1 |
RGB, MSI |
CC-BY-SA-4.0 |
|
SpaceNet 2 |
I |
WorldView-3 |
14,119 |
650x650, 163x163 |
0.3–1.24 |
RGB, MSI |
CC-BY-SA-4.0 |
|
SpaceNet 3 |
I |
WorldView-3 |
3,477 |
7 |
1,300x1,300, 325x325 |
0.3–1.24 |
RGB, MSI |
CC-BY-SA-4.0 |
SpaceNet 4 |
I |
WorldView-2 |
1,991 |
900x900, 225x225 |
0.46–1.67 |
RGB, MSI |
CC-BY-SA-4.0 |
|
SpaceNet 5 |
I |
WorldView-3 |
2,588 |
1,300x1,300, 325x325 |
0.3–1.24 |
RGB, MSI |
CC-BY-SA-4.0 |
|
SpaceNet 6 |
I |
WorldView-2 |
5,462 |
900x900, 450x450 |
0.5–2 |
SAR, RGB, MSI |
CC-BY-SA-4.0 |
|
SpaceNet 7 |
I |
Dove |
1,889 |
1,024x1,024 |
4 |
RGB |
CC-BY-SA-4.0 |
|
SpaceNet 8 |
I |
Maxar |
1,289 |
8 |
1,300x1,300 |
0.3–0.8 |
RGB |
CC-BY-SA-4.0 |
Pre-Training Datasets#
Pre-training datasets are designed for foundation model development, providing millions of input images with global distributions. These datasets may come with output labels for supervised pre-training, or come without output labels for self-supervised pre-training.
Dataset |
Task |
Source |
# Samples |
# Classes |
Size (px) |
Resolution (m) |
Bands |
License |
|---|---|---|---|---|---|---|---|---|
C |
Sentinel-1/2 |
590,326 |
19–43 |
120x120 |
10 |
SAR, MSI |
CDLA-Permissive-1.0 |
|
T |
Sentinel-1/2/3/5P, DEM |
18.7M |
264x264 or 96x96 or 28x28 or 960x960 |
10–1000 |
SAR, MSI, Air Pollutants, DEM |
CC-BY-4.0 |
||
EnMAP |
11k |
128 |
30 |
HSI |
CC0-1.0 |
|||
C, S |
Aster, Sentinel, ERA5 |
100K–1M |
128x128 or 64x64 |
10 |
MSI |
CC-BY-4.0 |
||
C |
Google Earth |
1M |
51–73 |
0.5–153 |
RGB |
|||
LE |
Sentinel-2 |
100k |
256x256 |
10 |
MSI |
MIT |
||
SSL4EO-L |
T |
Landsat |
1M |
264x264 |
30 |
MSI |
CC0-1.0 |
|
SSL4EO-S12 |
T |
Sentinel-1/2 |
1M |
264x264 |
10 |
SAR, MSI |
CC-BY-4.0 |
|
C, R, S, I, OD |
NAIP, Landsat, Sentinel |
302M |
137 |
512 |
0.6–30 |
SAR, MSI |
ESA AND CC0-1.0 AND ODbL-1.0 AND CC-BY-4.0 |
|
T |
Sentinel-2 |
100K–1M |
264x264 |
10 |
MSI |
CC-BY-4.0 |
||
IC |
NAIP, orthophotos, Planet SkySat, Sentinel-2, Landsat 8–9 |
5.2M |
100–1000 |
0.1–30 |
RGB |
MIT |
Embeddings Datasets#
Embeddings are low-dimensional representations generated by foundation models. There are both patch-based embeddings designed for similarity search and pixel-based embeddings designed for applications like land cover mapping.
Dataset |
Kind |
Spatial Extent |
Spatial Resolution |
Temporal Extent |
Temporal Resolution |
Dimensions |
Dtype |
License |
|---|---|---|---|---|---|---|---|---|
Clay Embeddings v0 Sentinel |
Patch |
Global* |
5.12 km |
2018–2023* |
Snapshot |
768 |
float32 |
ODC-By-1.0 |
Clay Embeddings v1.5 NAIP |
Patch |
USA |
154–256 m |
2010–2021* |
Snapshot |
1024 |
float32 |
CC-BY-4.0 |
Patch |
Global |
2.14–3.56 km |
2015–2024* |
Snapshot |
2048 |
float32 |
CC-BY-SA-4.0 |
|
Patch |
Global |
320 m |
2024 |
Snapshot |
384 |
float32 |
CC-BY-4.0 |
|
Patch |
Global |
0.25° |
2021 |
Annual |
768 |
float32 |
CC-BY-4.0 |
|
Clay Embeddings v1.5 Sentinel |
Patch |
Global |
2.56 km |
2024–2025 |
Snapshot |
1024 |
float32 |
CC-BY-4.0 |
Patch |
Global* |
2.24–3.84 km |
2015–2024* |
Snapshot |
256–1152 |
float16, float32 |
CC-BY-SA-4.0 |
|
Pixel |
Togo |
10 m |
2019–2020 |
Annual |
128 |
uint16 |
CC-BY-4.0 |
|
Pixel |
Global |
10 m |
2017–2025* |
Annual |
128 |
int8 → float32 |
CC0-1.0 |
|
Pixel |
Global |
10 m |
2017–2025 |
Annual |
64 |
int8 → float64 |
CC-BY-4.0 |
|
Pixel |
Global |
30 m |
2000–2024 |
Annual |
12 |
uint16 → float32 |
CC-BY-4.0 |
Image Sources#
Uncurated raster imagery can be used within TorchGeo, either for inference using a pre-trained model, or for training by combination with mask labels.
Dataset |
Type |
Source |
Size (px) |
Resolution (m) |
License |
|---|---|---|---|---|---|
Imagery |
Airphen |
1,280x960 |
0.047–0.09 |
||
Imagery |
EnMAP |
1,200x1,200 |
30 |
||
Imagery |
Landsat |
8,900x8,900 |
30 |
public domain |
|
Imagery |
Aerial |
6,100x7,600 |
0.3–2 |
public domain |
|
Imagery |
Aerial |
256x256 OR 512x512 |
0.03–50 |
CC-BY-4.0 |
|
Imagery |
PRISMA |
512x512 |
5–30 |
||
Imagery |
Sentinel |
10,000x10,000 |
10 |
CC-BY-SA-3.0-IGO |
Mask Labels#
Uncurated raster and vector masks can be used within TorchGeo, typically in combination with an image source for model training.
Dataset |
Type |
Source |
Size (px) |
Resolution (m) |
License |
|---|---|---|---|---|---|
Masks |
Landsat, LiDAR |
40,000x40,000 |
30 |
CC-BY-4.0 |
|
DEM |
Aster |
3,601x3,601 |
30 |
public domain |
|
Geometries |
Bing Imagery |
ODbL-1.0 |
|||
Masks |
Landsat |
30 |
public domain |
||
Points |
Citizen Scientists |
||||
DEM |
Aster, SRTM, Russian Topomaps |
25 |
CSCDA-ESA |
||
Masks |
Sentinel-2 |
10 |
CC-BY-4.0 |
||
Geometries |
EU Countries |
CC-BY-SA-4.0 |
|||
Points |
Citizen Scientists |
CC0-1.0 OR CC-BY-4.0 OR CC-BY-NC-4.0 |
|||
Masks |
Landsat |
45,000x45,000 |
100 |
CC-BY-4.0 |
|
Masks |
Remote Sensing, In Situ Measurements |
3 |
public domain |
||
Masks |
PlanetScope |
180K |
3 |
CC-BY-4.0 |
|
Masks |
Sentinel-2 |
10 |
CC-BY-4.0 |
||
Masks |
Landsat |
30 |
public domain |
||
Geometries |
Maxar, CNES/Airbus |
CC-BY-4.0 OR ODbL-1.0 |
|||
Geometries |
OpenStreetMap |
ODbL-1.0 |
|||
Masks |
Landsat, MODIS |
30 |
|||
Points |
Citizen Scientists |
Toy Datasets#
Toy datasets are tiny, ~100 image datasets designed for tutorials, demos, or few-shot learning.
Dataset |
Task |
Source |
# Samples |
# Classes |
Size (px) |
Resolution (m) |
Bands |
License |
|---|---|---|---|---|---|---|---|---|
EuroSAT 100 |
C |
Sentinel-2 |
27,000 |
10 |
64x64 |
10 |
MSI |
MIT |
LandCover.ai 100 |
S |
Aerial |
10,674 |
5 |
512x512 |
0.25–0.5 |
RGB |
CC-BY-NC-SA-4.0 |
OSCD 100 |
CD |
Sentinel-2 |
24 |
2 |
241–1,180 |
60 |
MSI |
CC-BY-NC-SA-4.0 |
PASTIS 100 |
I |
Sentinel-1/2 |
2,433 |
19 |
128x128xT |
10 |
MSI |
CC-BY-4.0 |
Base Classes#
If you want to write your own custom dataset, you can extend one of these abstract base classes.
GeoDataset#
- class torchgeo.datasets.GeoDataset[source]#
Bases:
Dataset[dict[str,Any]],ABC,PlottingMixinAbstract base class for datasets containing geospatial information.
Geospatial information includes things like:
coordinates (latitude, longitude)
resolution
GeoDatasetis a special class of datasets. UnlikeNonGeoDataset, the presence of geospatial information allows two or more datasets to be combined based on latitude/longitude. This allows users to do things like:Combine image and target labels and sample from both simultaneously (e.g., Landsat and CDL)
Combine datasets for multiple image sources for multimodal learning or data fusion (e.g., Landsat and Sentinel)
Combine image and other raster data (e.g., elevation, temperature, pressure) and sample from both simultaneously (e.g., Landsat and Aster Global DEM)
These combinations require that all queries are present in both datasets, and can be combined using an
IntersectionDataset:dataset = landsat & cdl
Users may also want to:
Combine datasets for multiple image sources and treat them as equivalent (e.g., Landsat 7 and Landsat 8)
Combine datasets for disparate geospatial locations (e.g., Chesapeake NY and PA)
These combinations require that all queries are present in at least one dataset, and can be combined using a
UnionDataset:dataset = landsat7 | landsat8
- filename_glob = '*'#
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.
- __add__ = None#
GeoDatasetaddition can be ambiguous and is no longer supported. Users should instead use the intersection or union operator.
- abstractmethod __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:
- __and__(other)[source]#
Take the intersection of two
GeoDataset.- Parameters:
other (GeoDataset) – another dataset
- Returns:
a single dataset
- Raises:
ValueError – if other is not a
GeoDataset- Return type:
Added in version 0.2.
- __or__(other)[source]#
Take the union of two GeoDatasets.
- Parameters:
other (GeoDataset) – another dataset
- Returns:
a single dataset
- Raises:
ValueError – if other is not a
GeoDataset- Return type:
Added in version 0.2.
- __len__()[source]#
Return the number of files in the dataset.
- Returns:
length of the dataset
- Return type:
- __str__()[source]#
Return the informal string representation of the object.
- Returns:
informal string representation
- Return type:
- property bounds: tuple[slice, slice, slice]#
Bounds of the index.
- Returns:
Bounding x, y, and t slices.
- property crs: CRS#
coordinate reference system (CRS) of the dataset.
- Returns:
RasterDataset#
- class torchgeo.datasets.RasterDataset(paths='data', crs=None, res=None, bands=None, transforms=None, cache=True, time_series=False)[source]#
Bases:
GeoDatasetAbstract base class for
GeoDatasetstored as raster files.- filename_regex = '.*'#
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 calculatemintandmaxtforindexinsertionstart: used to calculatemintforindexinsertionstop: used to calculatemaxtforindexinsertion
When
separate_filesis True, the following additional groups are searched for to find other files:band: replaced with requested band name
- date_format = '%Y%m%d'#
Date format string used to parse date from filename.
Not used if
filename_regexdoes not contain adategroup orstartandstopgroups.
- is_image = True#
True if the dataset only contains model inputs (such as images). False if the dataset only contains ground truth model outputs (such as segmentation masks).
The sample returned by the dataset/data loader will use the “image” key if is_image is True, otherwise it will use the “mask” key.
For datasets with both model inputs and outputs, the recommended approach is to use 2 RasterDataset instances and combine them using an IntersectionDataset.
- separate_files = False#
True if data is stored in a separate file for each band, else False.
- property dtype: dtype#
The dtype of the dataset (overrides the dtype of the data file via a cast).
Defaults to float32 if
is_imageis True, else long. Can be overridden for tasks like pixel-wise regression where the mask should be float32 instead of long.- Returns:
the dtype of the dataset
Added in version 0.5.
- property resampling: Resampling#
Resampling algorithm used when reading input files.
Defaults to bilinear for float dtypes and nearest for int dtypes.
- Returns:
The resampling method to use.
Added in version 0.6.
- __init__(paths='data', crs=None, res=None, bands=None, transforms=None, cache=True, time_series=False)[source]#
Initialize a new RasterDataset instance.
- Parameters:
paths (str | PathLike[str] | Iterable[str | PathLike[str]]) – one or more root directories to search or files to load
crs (CRS | None) – coordinate reference system (CRS) to warp to (defaults to the CRS of the first file found)
res (float | tuple[float, float] | None) – resolution of the dataset in units of CRS (defaults to the resolution of the first file found)
bands (Sequence[str] | None) – bands to return (defaults to all bands)
transforms (Callable[[dict[str, Any]], dict[str, Any]] | None) – 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
time_series (bool) – if True, stack data along the time series dimension (typically
[T, C, H, W]). If False, merge data into a mosaic (typically[C, H, W]). For mask-style datasets (is_image=False), single-band data may have the channel dimension squeezed, resulting in shapes[T, H, W]or[H, W]whenC == 1.
- Raises:
AssertionError – If bands are invalid.
DatasetNotFoundError – If dataset is not found.
Added in version 0.9: The time_series parameter.
Changed in version 0.5: root was renamed to paths.
- __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:
VectorDataset#
- class torchgeo.datasets.VectorDataset(paths='data', crs=None, res=(0.0001, 0.0001), transforms=None, label_name=None, task='semantic_segmentation', layer=None)[source]#
Bases:
GeoDatasetAbstract base class for
GeoDatasetstored as vector files.- filename_regex = '.*'#
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 calculatemintandmaxtforindexinsertion
- date_format = '%Y%m%d'#
Date format string used to parse date from filename.
Not used if
filename_regexdoes not contain adategroup.
- property dtype: dtype#
The dtype of the dataset (overrides the dtype of the data file via a cast).
Defaults to long.
- Returns:
the dtype of the dataset
Added in version 0.6.
- __init__(paths='data', crs=None, res=(0.0001, 0.0001), transforms=None, label_name=None, task='semantic_segmentation', layer=None)[source]#
Initialize a new VectorDataset instance.
- Parameters:
paths (str | PathLike[str] | Iterable[str | PathLike[str]]) – one or more root directories to search or files to load
crs (CRS | None) – coordinate reference system (CRS) to warp to (defaults to the CRS of the first file found)
res (float | tuple[float, float]) – resolution of the dataset in units of CRS
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
label_name (str | None) – name of the dataset property that has the label to be rasterized into the mask
task (Literal['object_detection', 'semantic_segmentation', 'instance_segmentation']) – computer vision task the dataset is used for. Supported output types object_detection, semantic_segmentation, instance_segmentation
layer (str | int | None) – if the input is a multilayer vector dataset, such as a geopackage, specify which layer to use. Can be int to specify the index of the layer, str to select the layer with that name or None which opens the first layer
- Raises:
DatasetNotFoundError – If dataset is not found.
ValueError – If task is not one of allowed tasks
Added in version 0.4: The label_name parameter.
Changed in version 0.5: root was renamed to paths.
Added in version 0.8: The task and layer parameters
- __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:
- get_label(feature)[source]#
Get label value to use for rendering a feature.
- Parameters:
feature (Series) – the row from the GeoDataFrame from which to extract the label.
- Returns:
the integer label, or 0 if the feature should not be rendered.
- Return type:
Added in version 0.6.
Changed in version 0.8: The feature parameter changed to a
pandas.Series
NonGeoDataset#
- class torchgeo.datasets.NonGeoDataset[source]#
Bases:
Dataset[dict[str,Any]],ABC,PlottingMixinAbstract base class for datasets lacking geospatial information.
This base class is designed for datasets with pre-defined image chips.
- abstractmethod __getitem__(index)[source]#
Return an index within the dataset.
- Parameters:
index (int) – index to return
- Returns:
data and labels at that index
- Raises:
IndexError – if index is out of range of the dataset
- Return type:
NonGeoClassificationDataset#
- class torchgeo.datasets.NonGeoClassificationDataset(root='data', transforms=None, loader=<function default_loader>, is_valid_file=None)[source]#
Bases:
NonGeoDataset,ImageFolderAbstract base class for classification datasets lacking geospatial information.
This base class is designed for datasets with pre-defined image chips which are separated into separate folders per class.
- __init__(root='data', transforms=None, loader=<function default_loader>, is_valid_file=None)[source]#
Initialize a new NonGeoClassificationDataset instance.
- Parameters:
root (str | PathLike[str]) – root directory where dataset can be found
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
loader (Callable[[str], Image | NDArray[generic]]) – a callable function which takes as input a path to an image and returns a PIL Image or numpy array
is_valid_file (Callable[[str | PathLike[str]], bool] | None) – A function that takes the path of an Image file and checks if the file is a valid file
IntersectionDataset#
- class torchgeo.datasets.IntersectionDataset(dataset1, dataset2, spatial_only=False, collate_fn=<function concat_samples>, transforms=None)[source]#
Bases:
GeoDatasetDataset representing the intersection of two GeoDatasets.
This allows users to do things like:
Combine image and target labels and sample from both simultaneously (e.g., Landsat and CDL)
Combine datasets for multiple image sources for multimodal learning or data fusion (e.g., Landsat and Sentinel)
Combine image and other raster data (e.g., elevation, temperature, pressure) and sample from both simultaneously (e.g., Landsat and Aster Global DEM)
These combinations require that all queries are present in both datasets, and can be combined using an
IntersectionDataset:dataset = landsat & cdl
Added in version 0.2.
- __init__(dataset1, dataset2, spatial_only=False, collate_fn=<function concat_samples>, transforms=None)[source]#
Initialize a new IntersectionDataset instance.
When computing the intersection between two datasets that both contain model inputs (such as images) or model outputs (such as masks), the default behavior is to stack the data along the channel dimension. The collate_fn parameter can be used to change this behavior.
- Parameters:
dataset1 (GeoDataset) – the first dataset
dataset2 (GeoDataset) – the second dataset
spatial_only (bool) – if True, ignore temporal dimension when computing intersection
collate_fn (Callable[[Sequence[dict[str, Any]]], dict[str, Any]]) – function used to collate samples
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
- Raises:
RuntimeError – if datasets have no spatiotemporal intersection
ValueError – if either dataset is not a
GeoDataset
Added in version 0.8: The spatial_only parameter.
Added in version 0.4: The transforms parameter.
- __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:
- __str__()[source]#
Return the informal string representation of the object.
- Returns:
informal string representation
- Return type:
- property crs: CRS#
coordinate reference system (CRS) of both datasets.
- Returns:
UnionDataset#
- class torchgeo.datasets.UnionDataset(dataset1, dataset2, collate_fn=<function merge_samples>, transforms=None)[source]#
Bases:
GeoDatasetDataset representing the union of two GeoDatasets.
This allows users to do things like:
Combine datasets for multiple image sources and treat them as equivalent (e.g., Landsat 7 and Landsat 8)
Combine datasets for disparate geospatial locations (e.g., Chesapeake NY and PA)
These combinations require that all queries are present in at least one dataset, and can be combined using a
UnionDataset:dataset = landsat7 | landsat8
Added in version 0.2.
- __init__(dataset1, dataset2, collate_fn=<function merge_samples>, transforms=None)[source]#
Initialize a new UnionDataset instance.
When computing the union between two datasets that both contain model inputs (such as images) or model outputs (such as masks), the default behavior is to merge the data to create a single image/mask. The collate_fn parameter can be used to change this behavior.
- Parameters:
dataset1 (GeoDataset) – the first dataset
dataset2 (GeoDataset) – the second dataset
collate_fn (Callable[[Sequence[dict[str, Any]]], dict[str, Any]]) – function used to collate samples
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
- Raises:
ValueError – if either dataset is not a
GeoDataset
Added in version 0.4: The transforms parameter.
- __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:
- __str__()[source]#
Return the informal string representation of the object.
- Returns:
informal string representation
- Return type:
- property crs: CRS#
coordinate reference system (CRS) of both datasets.
- Returns:
Mixins#
Utilities#
Collation Functions#
- torchgeo.datasets.stack_samples(samples)[source]#
Stack a list of samples along a new axis.
Useful for forming a mini-batch of samples to pass to
torch.utils.data.DataLoader.- Parameters:
- Returns:
a single sample
- Return type:
Added in version 0.2.
- torchgeo.datasets.concat_samples(samples)[source]#
Concatenate a list of samples along an existing axis.
Useful for joining samples in a
torchgeo.datasets.IntersectionDataset.- Parameters:
- Returns:
a single sample
- Return type:
Added in version 0.2.
- torchgeo.datasets.merge_samples(samples)[source]#
Merge a list of samples.
Useful for joining samples in a
torchgeo.datasets.UnionDataset.- Parameters:
- Returns:
a single sample
- Return type:
Added in version 0.2.
- torchgeo.datasets.unbind_samples(sample)[source]#
Reverse of
stack_samples().Useful for turning a mini-batch of samples into a list of samples. These individual samples can then be plotted using a dataset’s
plotmethod.- Parameters:
- Returns:
list of samples
- Return type:
Added in version 0.2.
Splitting Functions#
- torchgeo.datasets.random_bbox_assignment(dataset, lengths, generator=<torch._C.Generator object>)[source]#
Split a GeoDataset randomly assigning its index’s objects.
This function will go through each object in the GeoDataset’s index and randomly assign it to new GeoDatasets.
- Parameters:
dataset (GeoDataset) – dataset to be split
lengths (Sequence[float]) – lengths or fractions of splits to be produced
generator (Generator | None) – (optional) generator used for the random permutation
- Returns:
A list of the subset datasets.
- Return type:
Added in version 0.5.
- torchgeo.datasets.random_bbox_splitting(dataset, fractions, generator=<torch._C.Generator object>)[source]#
Split a GeoDataset randomly splitting its index’s objects.
This function will go through each object in the GeoDataset’s index, split it in a random direction and assign the resulting objects to new GeoDatasets.
- Parameters:
dataset (GeoDataset) – dataset to be split
fractions (Sequence[float]) – fractions of splits to be produced
generator (Generator | None) – generator used for the random permutation
- Returns:
A list of the subset datasets.
- Return type:
Added in version 0.5.
- torchgeo.datasets.random_grid_cell_assignment(dataset, fractions, grid_size=6, generator=<torch._C.Generator object>)[source]#
Overlays a grid over a GeoDataset and randomly assigns cells to new GeoDatasets.
This function will go through each object in the GeoDataset’s index, overlay a grid over it, and randomly assign each cell to new GeoDatasets.
- Parameters:
dataset (GeoDataset) – dataset to be split
fractions (Sequence[float]) – fractions of splits to be produced
grid_size (int) – number of rows and columns for the grid
generator (Generator | None) – generator used for the random permutation
- Returns:
A list of the subset datasets.
- Return type:
Added in version 0.5.
- torchgeo.datasets.roi_split(dataset, rois)[source]#
Split a GeoDataset intersecting it with a ROI for each desired new GeoDataset.
- Parameters:
dataset (GeoDataset) – dataset to be split
rois (Sequence[Polygon]) – regions of interest of splits to be produced
- Returns:
A list of the subset datasets.
- Return type:
Added in version 0.5.
Errors#
- class torchgeo.datasets.DatasetNotFoundError(dataset)[source]#
Bases:
FileNotFoundErrorRaised when a dataset is requested but doesn’t exist.
Added in version 0.6.
- __weakref__#
list of weak references to the object