# TorchGeo: geospatial datasets, samplers and pre-trained models for PyTorch

> TorchGeo is a PyTorch domain library for remote sensing data, covering datasets, samplers, transforms and pre-trained models. It is a good fit if your imagery comes with CRS metadata and you already work in PyTorch; it is not a GIS and not a general image library.

**torchgeo/torchgeo** — TorchGeo: datasets, samplers, transforms, and pre-trained models for geospatial data

- Repository: https://github.com/torchgeo/torchgeo
- Website: https://torchgeo.org/
- Stars: 4,192 · Forks: 593
- Language: Python
- License: MIT
- Published: 2026-09-10 · Updated: 2026-09-10 · Language: en
- Canonical page: https://hysenlabs.com/projects/torchgeo-torchgeo

## The problem TorchGeo addresses: geospatial data does not fit standard PyTorch loaders

A standard PyTorch dataset assumes one file per sample at a fixed size. Satellite imagery breaks both assumptions. The README states that geospatial imagery is often multispectral with a different number of spectral bands and spatial resolution for every satellite, and that each file may be in a different coordinate reference system (CRS), requiring the data to be reprojected into a matching CRS. The CDL example in the README is a single image covering the continental United States, so there is no sensible one-file-per-sample mapping at all. TorchGeo targets two groups. The README frames the goal as making it simple for machine learning experts to work with geospatial data, and for remote sensing experts to explore machine learning solutions. Those are different starting points with the same blocker: the data layer. If you are the ML person, you get dataset classes that already know about bands and CRS. If you are the remote sensing person, you get a path into PyTorch that does not require writing your own tiling and reprojection code first. It is a domain library in the same sense as torchvision, which the README names as the closest analogue, but the domain is earth observation rather than natural images.

## How the dataset algebra and patch samplers actually work

The mechanism that carries most of the design is set algebra over datasets. The README builds a combined Landsat 7 and Landsat 8 dataset with the union operator, then intersects that with CDL. The README gives the reasoning explicitly: the intersection is used instead of the union to ensure that sampling only happens in regions that have both Landsat and CDL data. The README also states that each dataset may contain files in different coordinate reference systems or resolutions, but TorchGeo automatically ensures that a matching CRS and resolution is used. That is the core value: the library resolves the geospatial mismatch at the dataset boundary rather than in your training loop. The second half is sampling. Because the underlying images are far too large to index by file, TorchGeo defines samplers that work in geospatial coordinates. The README example uses RandomPatchSampler with size=256 and length=10000, meaning 256 by 256 pixel patches and 10,000 samples per epoch, and pairs it with stack_samples as the collate function to combine per-sample dictionaries into a mini-batch. The documentation also describes transforms and pre-trained models as part of the library, and the repository ships a hubconf.py at the top level, which is the PyTorch Hub entry point convention. The README does not spell out the internals of how CRS alignment is performed, so treat that as an implementation detail to check in the API docs before you rely on it for a specific sensor pair.

## Installing TorchGeo with pip or uv and running a first sampler

The README gives pip as the recommended installation method. The package is also published on conda-forge and Spack, but the README defers those instructions to the installation page in the documentation. Note the interpreter requirement in pyproject.toml: requires-python is >=3.12, and the classifiers list 3.12, 3.13 and 3.14. If you are on an older Python, installation will not resolve.

```bash
pip install torchgeo
```

The README also documents the uv path, which adds the dependency to an existing project rather than installing it globally.

```bash
uv add torchgeo
```

A first real use is the Landsat plus CDL combination. The README assumes the Landsat 7 and 8 imagery is already downloaded and passed via the paths argument, and restricts each sensor to the bands both satellites share. CDL is the one dataset in the example that TorchGeo can fetch itself, via download=True and checksum=True.

```python
from torchgeo.datasets import CDL, Landsat7, Landsat8

landsat7 = Landsat7(paths='...', bands=['B1', 'B7'])
landsat8 = Landsat8(paths='...', bands=['B2', 'B8'])
landsat = landsat7 | landsat8
cdl = CDL(paths='...', download=True, checksum=True)
dataset = landsat & cdl
```

After that, the sampler and loader are ordinary PyTorch objects. The README's example requests 256 by 256 patches and 10,000 samples per epoch, with a batch size of 128.

```python
from torch.utils.data import DataLoader
from torchgeo.datasets import stack_samples
from torchgeo.samplers import RandomPatchSampler

sampler = RandomPatchSampler(dataset, size=256, length=10000)
dataloader = DataLoader(
    dataset, batch_size=128, sampler=sampler, collate_fn=stack_samples
)
```

What you should see is a DataLoader that yields batches of patch dictionaries restricted to the geographic overlap of Landsat and CDL. The README's example imports Landsat7 and Landsat8 with bands given as truncated lists (['B1', ..., 'B7'] and ['B2', ..., 'B8']), so the exact band names in your own code have to come from the dataset API documentation rather than copied from the abbreviated README snippet.

## Where TorchGeo stops: data, not analysis, and not a GIS replacement

The clearest limitation is scope. TorchGeo is a data and model library. There is no documented raster algebra, no vector overlay, no map production, and no interactive inspection. If your actual task is computing an NDVI time series over an administrative boundary, or producing a print map, TorchGeo is the wrong tool and a GIS is the right one. The intersection operator is a good illustration of the boundary. It gives you the geographic overlap of two datasets for sampling purposes. It does not give you a reprojected raster you can hand to another tool, and the README does not present it as such. A second constraint is the dependency surface. The pyproject.toml dependency list includes geopandas, and a comment states that geopandas 1.0 or newer is required in order to use the pyogrio backend instead of Fiona, which the comment calls unmaintained. That means the geospatial stack underneath TorchGeo has its own version floors, and pinning conflicts with an existing environment are a realistic failure mode. The project also classifies itself as Development Status 4 - Beta, and the version in pyproject.toml is 0.11.0.dev1, so the API is not frozen. There is a third, quieter cost: the README's own example assumes you have already downloaded Landsat 7 and 8 imagery and know which bands you want. TorchGeo can download and checksum CDL in that example, but the README does not claim automatic download for every dataset, so for some sensors you still own the acquisition step.

## TorchGeo compared with torchvision and with a plain GDAL pipeline

TorchGeo is best understood against two alternatives, and it sits between them. The first is torchvision. The README describes TorchGeo as similar to torchvision but specific to geospatial data. The difference is what the dataset object knows. A torchvision dataset knows a file path and a label. A TorchGeo dataset knows a CRS and a resolution, which is why union and intersection between two datasets are meaningful operations at all. If your imagery is already tiled, projected to a single CRS and stored as plain images, torchvision plus a custom Dataset subclass is less machinery for the same result. The second alternative is a hand-rolled GDAL or rasterio pipeline feeding a PyTorch loader. That approach is more work up front, but it gives you full control over resampling method, nodata handling and windowing, and it has no opinion about your training loop. TorchGeo's trade-off is the inverse: you accept its dataset and sampler abstractions and its dependency stack in exchange for not writing reprojection and patch sampling yourself. Neither is strictly better. For a single sensor with a fixed tiling scheme, the hand-rolled path is often simpler to debug, because every step is code you wrote. TorchGeo pays off when you are combining sources, which is exactly the case the README leads with.

## Maintenance cadence, licence and upgrade cost

The repository is not archived, and the last push was on 2026-09-09, which is recent relative to the release history. Releases are not frequent on a monthly rhythm: v0.8.1 landed on 2026-01-25, v0.9.0 on 2026-02-14, and v0.10.0 on 2026-08-14. The gap between v0.9.0 and v0.10.0 is about six months, so plan for a small number of larger upgrades rather than a steady stream of patches. The version string in pyproject.toml is 0.11.0.dev1, meaning main is ahead of the latest release, so installing from the repository gives you unreleased API. The licence is MIT, declared both in the repository LICENSE file and in the license field of pyproject.toml, with license-files pointing at LICENSE. MIT is permissive and imposes no copyleft obligation on your own code. That matters less than the dependency licences: geopandas and the rest of the geospatial stack are separate projects with their own terms, and TorchGeo's MIT licence says nothing about them. Check those separately if your organisation has a policy against specific licences. The upgrade cost is dominated by the Python floor. requires-python is >=3.12, so an environment on 3.11 or older cannot install current TorchGeo at all, and moving to 3.12 may force upgrades elsewhere in your stack.

## Conclusion

Adopt TorchGeo if your imagery carries CRS and resolution metadata and you already train in PyTorch, because the dataset intersection and patch samplers remove a lot of manual reprojection work. Do not adopt it if you need a GIS analysis tool or a general-purpose vision library, since it does not replace either. Before committing, verify that the specific dataset classes you need exist for your sensors and that your Python is 3.12 or newer, since pyproject.toml sets requires-python to >=3.12.

## FAQ

### What exactly is PyTorch used for?

PyTorch is the framework TorchGeo is built on. The README describes TorchGeo as a PyTorch domain library, similar to torchvision, providing datasets, samplers, transforms and pre-trained models specific to geospatial data.

### Is PyTorch just Python?

TorchGeo is written in Python and installed as a Python package, and pyproject.toml sets requires-python to >=3.12. The repository's primary language is Python, though the top-level layout also includes package.json for Prettier formatting of non-Python files.

### Is PyTorch free to use?

TorchGeo itself is MIT licensed, declared in the LICENSE file and in the license field of pyproject.toml. Its dependencies, such as geopandas, are separate projects with their own licences.

### What language is PyTorch?

The repository's primary language is Python, and the README's usage examples are all Python code. pyproject.toml declares support for Python 3.12, 3.13 and 3.14.

### What are the alternatives to TorchGeo?

The README positions TorchGeo as similar to torchvision but specific to geospatial data, so torchvision with a custom Dataset subclass is the closest alternative when your imagery is already tiled into one CRS. A hand-rolled GDAL or rasterio pipeline feeding PyTorch is the other route, trading convenience for control over resampling and windowing.

## Sources

- [License: MIT](https://github.com/torchgeo/torchgeo/blob/main/LICENSE)
- [Project website](https://torchgeo.org/)
- [README](https://github.com/torchgeo/torchgeo/blob/main/README.md)
- [Releases](https://github.com/torchgeo/torchgeo/releases)
- [torchgeo/torchgeo on GitHub](https://github.com/torchgeo/torchgeo)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/torchgeo-torchgeo
