Registry / ai-ml / torchgeo

torchgeo

JSON →
library0.9.0pypypi✓ verified 86d ago

TorchGeo is a Python library providing datasets, samplers, transforms, and pre-trained models specifically designed for geospatial data within the PyTorch ecosystem. It aims to simplify the development of deep learning models for Earth observation and remote sensing tasks. Currently at version 0.9.0, TorchGeo maintains an active development pace with frequent releases, typically every 2-3 months, to incorporate new features and datasets.

pip install torchgeo
INSTALL
IMPORT
SIG · TORCHGEO
T
torchgeo
ai-mlpythonv0.9.0
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
1/8 runs
py 3.11
✕ build_error
4/8 runs
py 3.12
✕ build_error
4/8 runs
py 3.13
✕ build_error
5/8 runs
py 3.9
✕ build_error
✕ timeout
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

EuroSAT
from torchgeo.datasets import EuroSAT
RasterDataset
from torchgeo.datasets import RasterDataset
RandomGeoSampler
from torchgeo.samplers import RandomGeoSampler
AugmentationSequential
from torchgeo.transforms import AugmentationSequential
ResNet18_Weights
from torchgeo.models import ResNet18_Weights

This quickstart demonstrates how to load the EuroSAT dataset, apply basic transformations using `AugmentationSequential`, set up a `RandomBatchGeoSampler` for extracting image patches, and load data in batches using a standard PyTorch `DataLoader`. Note that `EuroSAT` will download the dataset to the specified root directory if it's not already present.

import torch from torchgeo.datasets import EuroSAT from torchgeo.transforms import AugmentationSequential, RandomGrayscale from torchgeo.samplers import RandomBatchGeoSampler from torch.utils.data import DataLoader import tempfile import os # Initialize transforms transforms = AugmentationSequential( RandomGrayscale(p=0.5), data_keys=["image"] ) # Use a temporary directory for the dataset to avoid polluting the user's system with tempfile.TemporaryDirectory() as tmpdir: # Initialize EuroSAT dataset (will download if not present) dataset = EuroSAT(root=tmpdir, split="train", transforms=transforms, download=True) # Initialize a sampler to get patches sampler = RandomBatchGeoSampler(dataset, patch_size=(64, 64), batch_size=4, length=10) # Create a DataLoader dataloader = DataLoader(dataset, sampler=sampler, num_workers=0) # Iterate through one batch and print shapes for batch in dataloader: image = batch["image"] label = batch["label"] print(f"Batch image shape: {image.shape}, label shape: {label.shape}") break # Just one batch for quickstart
Debug
Known issues
breakingTorchGeo 0.8.0 introduced a complete rewrite of `GeoDataset` and `GeoSampler` internals. Code relying on direct manipulation or specific internal structures of these base classes might break.
fix
Review the official documentation for `GeoDataset` and `GeoSampler` usage patterns and update your code to align with the new API. Specifically, pay attention to how samples are structured and accessed.
affects: >=0.8.0
gotchaTorchGeo versions 0.9.0 and later require Python 3.12 or newer. Users on older Python versions will encounter installation errors.
fix
Ensure your Python environment is 3.12 or higher. Upgrade Python or create a new virtual environment with the correct version.
affects: >=0.9.0
gotchaThere have been reported incompatibilities with specific versions of the `lightning` library (e.g., 2.5.5 was not supported in v0.7.2). Using an unsupported `lightning` version can lead to errors or unexpected behavior during training.
fix
Consult TorchGeo's `pyproject.toml` or `setup.py` on GitHub for the exact `lightning` version constraints. If you encounter issues, try pinning `lightning` to a known compatible version, e.g., `pip install 'lightning<2.5'` if 2.5.x had issues.
affects: 0.7.x, 0.8.x
gotchaSpecific versions of `rasterio` (e.g., 1.4.0, 1.4.1) have caused issues in earlier TorchGeo versions, leading to potential crashes or incorrect data loading when processing raster data.
fix
Check the `rasterio` version listed in TorchGeo's dependency requirements. If you encounter `rasterio`-related errors, try updating TorchGeo to the latest version or explicitly installing a compatible `rasterio` version, for example, `pip install 'rasterio>=1.3.1,!=1.4.0,!=1.4.1'`.
affects: <0.7.2
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'torchgeo.datasets.utils'
The `utils` submodule within `torchgeo.datasets` (or other modules) may have been refactored, moved, or its contents integrated directly into other classes/functions.
fix
Check the official TorchGeo documentation or GitHub repository for the correct import path for the specific utility you are trying to use. The functionality might now be directly available on a class or in a different submodule.
UserWarning: `torchgeo` is being used with an unsupported `lightning` version. This might lead to unexpected behavior.
The installed version of PyTorch Lightning is not officially tested or supported by the current TorchGeo version, leading to potential incompatibilities.
fix
Verify the required `lightning` version in TorchGeo's `pyproject.toml` or `setup.py`. Downgrade or upgrade your `lightning` installation to a compatible version, e.g., `pip install 'lightning<2.5'` if 2.5.x is causing issues with your TorchGeo version.
TypeError: __init__ missing 1 required positional argument: 'root'
Many `torchgeo.datasets` classes, especially those loading data from disk, require a `root` directory path as a mandatory argument during initialization. This error occurs if `root` is omitted or incorrectly passed.
fix
When initializing a dataset, always provide the `root` argument pointing to the directory where the dataset should be stored or is located, e.g., `dataset = EuroSAT(root='./data', download=True)`.
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0!
This is a common PyTorch error indicating that tensors involved in an operation are on different devices (CPU vs. GPU), which can happen if not all data or models are explicitly moved to CUDA.
fix
Ensure all relevant tensors and models are moved to the same device (e.g., CUDA) before operations. Use `.to(device)` where `device = 'cuda' if torch.cuda.is_available() else 'cpu'`. For DataLoaders, custom collate functions or transform steps might be needed to ensure output tensors are on the desired device.
Upgrade
Version history
0.9.0latest on PyPI · released Feb 14, 2026
Audit
Dependencies
torchrequiredCore PyTorch dependency for tensor operations and neural networks.
torchvisionrequiredCommonly used alongside PyTorch for image processing utilities.
lightningoptionalUsed for advanced training functionalities and data modules. Specific versions are often required to avoid compatibility issues.
rasteriooptionalRequired for reading and writing raster geospatial data. Specific versions can cause issues.
laspyoptionalRequired for point cloud data processing.
segmentation-models-pytorchoptionalRequired for using certain segmentation models.
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
torchgeo — pip install torchgeo · libregistry