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 torchgeoVerified import paths — ran on the pinned version, not inferred.
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.
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.
Ensure your Python environment is 3.12 or higher. Upgrade Python or create a new virtual environment with the correct version.
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.
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'`.
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.
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.
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)`.
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.