{"id":8724,"library":"torchgeo","title":"TorchGeo","description":"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.","status":"active","version":"0.9.0","language":"en","source_language":"en","source_url":"https://github.com/torchgeo/torchgeo","tags":["geospatial","pytorch","deep-learning","earth-observation","satellite-imagery","computer-vision","remote-sensing"],"install":[{"cmd":"pip install torchgeo","lang":"bash","label":"Stable release"},{"cmd":"pip install 'torchgeo[all]'","lang":"bash","label":"With all optional dependencies"}],"dependencies":[{"reason":"Core PyTorch dependency for tensor operations and neural networks.","package":"torch","optional":false},{"reason":"Commonly used alongside PyTorch for image processing utilities.","package":"torchvision","optional":false},{"reason":"Used for advanced training functionalities and data modules. Specific versions are often required to avoid compatibility issues.","package":"lightning","optional":true},{"reason":"Required for reading and writing raster geospatial data. Specific versions can cause issues.","package":"rasterio","optional":true},{"reason":"Required for point cloud data processing.","package":"laspy","optional":true},{"reason":"Required for using certain segmentation models.","package":"segmentation-models-pytorch","optional":true}],"imports":[{"symbol":"EuroSAT","correct":"from torchgeo.datasets import EuroSAT"},{"symbol":"RasterDataset","correct":"from torchgeo.datasets import RasterDataset"},{"symbol":"RandomGeoSampler","correct":"from torchgeo.samplers import RandomGeoSampler"},{"symbol":"AugmentationSequential","correct":"from torchgeo.transforms import AugmentationSequential"},{"symbol":"ResNet18_Weights","correct":"from torchgeo.models import ResNet18_Weights"}],"quickstart":{"code":"import torch\nfrom torchgeo.datasets import EuroSAT\nfrom torchgeo.transforms import AugmentationSequential, RandomGrayscale\nfrom torchgeo.samplers import RandomBatchGeoSampler\nfrom torch.utils.data import DataLoader\nimport tempfile\nimport os\n\n# Initialize transforms\ntransforms = AugmentationSequential(\n    RandomGrayscale(p=0.5),\n    data_keys=[\"image\"]\n)\n\n# Use a temporary directory for the dataset to avoid polluting the user's system\nwith tempfile.TemporaryDirectory() as tmpdir:\n    # Initialize EuroSAT dataset (will download if not present)\n    dataset = EuroSAT(root=tmpdir, split=\"train\", transforms=transforms, download=True)\n\n    # Initialize a sampler to get patches\n    sampler = RandomBatchGeoSampler(dataset, patch_size=(64, 64), batch_size=4, length=10)\n\n    # Create a DataLoader\n    dataloader = DataLoader(dataset, sampler=sampler, num_workers=0)\n\n    # Iterate through one batch and print shapes\n    for batch in dataloader:\n        image = batch[\"image\"]\n        label = batch[\"label\"]\n        print(f\"Batch image shape: {image.shape}, label shape: {label.shape}\")\n        break # Just one batch for quickstart\n\n","lang":"python","description":"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."},"warnings":[{"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.","message":"TorchGeo 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.","severity":"breaking","affected_versions":">=0.8.0"},{"fix":"Ensure your Python environment is 3.12 or higher. Upgrade Python or create a new virtual environment with the correct version.","message":"TorchGeo versions 0.9.0 and later require Python 3.12 or newer. Users on older Python versions will encounter installation errors.","severity":"gotcha","affected_versions":">=0.9.0"},{"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.","message":"There 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.","severity":"gotcha","affected_versions":"0.7.x, 0.8.x"},{"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'`.","message":"Specific 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.","severity":"gotcha","affected_versions":"<0.7.2"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"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.","cause":"The `utils` submodule within `torchgeo.datasets` (or other modules) may have been refactored, moved, or its contents integrated directly into other classes/functions.","error":"ModuleNotFoundError: No module named 'torchgeo.datasets.utils'"},{"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.","cause":"The installed version of PyTorch Lightning is not officially tested or supported by the current TorchGeo version, leading to potential incompatibilities.","error":"UserWarning: `torchgeo` is being used with an unsupported `lightning` version. This might lead to unexpected behavior."},{"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)`.","cause":"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.","error":"TypeError: __init__ missing 1 required positional argument: 'root'"},{"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.","cause":"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.","error":"RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0!"}]}