torchgeo: dataset composition with union and intersection operators
TorchGeo: datasets, samplers, transforms, and pre-trained models for geospatial data
At a glance
- What is it?
- TorchGeo is a PyTorch domain library for geospatial data, and its most interesting idea is that datasets compose with operators rather than helper functions: a union of two satellites you can treat as equivalent, an intersection of imagery and its labels. Its only JavaScript dependency is a formatter.
- Who is it for?
- Use TorchGeo when your imagery carries geographic metadata and you keep hitting the same three problems: mismatched coordinate systems, mismatched band counts, and images too large to load whole. It solves the first at composition time and the third with samplers, while band subsets are left to you.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 1 day ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.
Star history
- torchgeo/torchgeo4,246 ★ · +70
| Repository | 2026-09-11 | 2026-11-22 |
|---|---|---|
| torchgeo/torchgeo | 4.2k | 4.2k |
70 Stars in the last 72 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Datasets compose with operators, not helper functions
The library's central design choice is that dataset composition uses the same two symbols as set theory.
landsat7 = Landsat7(paths='...', bands=['B1', ..., 'B7'])
landsat8 = Landsat8(paths='...', bands=['B2', ..., 'B8'])
landsat = landsat7 | landsat8The union combines two satellites so that a query is answered if at least one of them can answer it. The readme names the two cases it is for: combining sources you want to treat as equivalent, such as two satellite generations, and combining sources that cover different places.
The intersection is the other operator, and the difference is a correctness question rather than a convenience one.
cdl = CDL(paths='...', download=True, checksum=True)
dataset = landsat & cdlA union requires every query to be present in at least one dataset; an intersection requires it to be present in both. So the intersection suits both data fusion, for example Landsat with Sentinel, and pairing imagery with its labels, where sampling anywhere one of them is missing produces an unusable training example.
Both classes are constructible directly if you need to be explicit about the requirement.
Coordinate systems and band counts are resolved during composition
The readme explains why geospatial data is hard before it explains the solution, and the reasons are specific.
Imagery is often multispectral with a different number of spectral bands and a different spatial resolution for every satellite. Each file may be in a different coordinate reference system, so data has to be reprojected before it means anything.
The example handles this without asking the user to. The two Landsat datasets are declared with explicit band lists, and the text explains why: the later satellite has more bands than the earlier one, so only the bands both satellites have in common are used. Nothing infers a sensible band set for you.
Then the alignment promise. The datasets may contain files in different coordinate reference systems or at different resolutions, and TorchGeo makes sure a matching system and resolution is used.
The label dataset adds two conveniences of its own: it can be downloaded on demand, and it can be checksummed, so a cached copy is verified rather than trusted.
That combination is the reason to use a library like this at all. The composition operators only make sense because each participating dataset guarantees that a sample returned from it is aligned with every other.
One image covers the United States, hence the sampler
The scale problem is stated with a concrete example, and it is why samplers exist.
Unlike benchmark datasets, geospatial datasets often include very large images. The example given is a land cover dataset that consists of a single image covering the entire continental United States.
You cannot hand that to a data loader. Instead the library defines samplers, and the example uses a random one that returns fixed size patches.
sampler = RandomPatchSampler(dataset, size=256, length=10000)
dataloader = DataLoader(
dataset, batch_size=128, sampler=sampler, collate_fn=stack_samples
)Three numbers do the work: the patch edge in pixels, the number of samples drawn per epoch, and the batch size. A hundred and twenty-eight patches of 256 by 256 pixels per batch, ten thousand samples per epoch.
The collation function is the fourth piece. Samples come back as dictionaries with an image and a mask, and a custom function stacks them into a batch.
After that the loader is ordinary. The readme's loop takes a batch, pulls the image and the mask out of it, and hands them to a training loop or to a pre-trained model. The geospatial part is entirely in front of that loop.
The manifest is already the next minor version
The released version is 0.10.1, published on September 29, 2026.
The build itself is not setuptools. The build backend is uv_build, from the same tool that the readme recommends for installing, and the requirement comment in the manifest explains that a recent version is needed for how distribution files are reorganised.
Dependency floors are annotated with the reason they exist
The dependency list carries comments, and the comments are about reasons rather than about provenance.
# geopandas 1.0+ required to use pyogrio backend instead of Fiona (unmaintained)
"types-geopandas>=1.0",The floor exists because version 1.0 uses the pyogrio backend instead of Fiona, which the comment calls unmaintained. Other comments give a different kind of reason, such as sphinx 8+ being required by pydata-sphinx-theme 0.18+. A floor that is there to avoid a version conflict with another library in the same environment is a different kind of constraint from a floor that is there for an API, and only one of them tells you what breaks if you force it lower.
The rest of the project is packaged three ways. A Python package index is the recommended route, a conda-forge channel is listed, and a Spack package is listed, with the conda and Spack instructions deferred to the documentation rather than given on the page.
Installs themselves are two lines, one for the standard installer and one for the fast resolver.
Two base classes separate labelled benchmarks from everything else
The library splits its datasets into two families, and the split is about whether labels come with the images.
A geospatial dataset is one with geographic metadata, and those are what the composition operators and samplers work on.
A benchmark dataset is one that includes both input images and target labels. The readme lists the tasks these cover: image classification, regression, semantic segmentation, object detection, instance segmentation and change detection.
Change detection is the one worth pausing on, because it is the task where the label is a relationship between two images of the same place at different times rather than a property of one image.
The example imports from four families of public entry point at once, which is a fair summary of how a user works: data modules for the task setup, datasets for the data, samplers for the geometry, and tasks for the model.
And it imports the training framework itself, so the library is designed to sit inside an existing training loop rather than to replace one.
The only JavaScript dependency is a formatter
The package manifest in this repository is ten lines long.
{
"name": "torchgeo",
"private": "true",
"dependencies": {
"prettier": ">=3.3"
}
}One dependency, a formatter, with a configuration for single quotes. And the package is marked private, so it is not published to any JavaScript registry.
Everything else about the distribution is Python-shaped. There is a Python lock file, a JavaScript lock file for that single formatter, a citation file for academic use, a development container definition, and a pre-commit configuration.
The module file at the repository root is the exception worth naming. A hub configuration file is what registers models and weights with a model hub, and the readme links a hub namespace and a Zenodo community alongside it.
So the package comes from three places: a Python package index, a conda channel and a Spack package, and the readme also links a Hugging Face namespace and a Zenodo community.
Editorial conclusion
Use TorchGeo when your imagery carries geographic metadata and you keep hitting the same three problems: mismatched coordinate systems, mismatched band counts, and images too large to load whole. It solves the first at composition time and the third with samplers, while band subsets are left to you. Check two things before you build on it. The union and intersection operators differ in a way that matters for correctness, since a union tolerates queries that only one dataset answers while an intersection requires both. Band subsets are explicit, so a multi-sensor project has to choose the common bands rather than assume a default.
Frequently asked questions
What exactly is PyTorch used for in torchgeo?
TorchGeo is a PyTorch domain library, described as being to geospatial data what torchvision is to images. It provides datasets, samplers, transforms and pre-trained models, and its examples sit inside a PyTorch training loop and data loader.
What are the alternatives to torchgeo?
The readme states the position TorchGeo takes: make it simple for machine learning experts to work with geospatial data, and for remote sensing experts to explore machine learning solutions.
How do I install torchgeo?
With the standard Python installer, or with the fast resolver. Conda and Spack packages exist as well, with their instructions in the documentation rather than on the readme.
What is the difference between a union and an intersection of torchgeo datasets?
A union requires every query to be present in at least one dataset, which suits combining equivalent sources or sources covering different places. An intersection requires the query to be present in both, which suits pairing imagery with its labels or fusing sensors where a partial sample would be useless.
Why does torchgeo need samplers?
Because geospatial datasets can contain a single enormous image, such as one covering the whole continental United States. Samplers draw fixed size patches instead, and a collation function stacks the resulting sample dictionaries into batches for an ordinary training loop.
What tasks does torchgeo cover?
Its benchmark datasets pair input images with target labels for image classification, regression, semantic segmentation, object detection, instance segmentation and change detection. There is also a data module for one specific aerial labelling dataset in the worked example.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/torchgeo-torchgeo)Star history chart for your README
[](https://hysenlabs.com/projects/torchgeo-torchgeo)Was this useful?