Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump pytorch-lightning[extra] from 1.9.4 to 2.0.0 in /requirements #1178

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ repos:
hooks:
- id: mypy
args: [--strict, --ignore-missing-imports, --show-error-codes]
additional_dependencies: [torch>=1.13, torchmetrics>=0.10, pytorch-lightning>=1.7, pytest>=6, pyvista>=0.20, omegaconf>=2.1, kornia>=0.6, numpy>=1.22.0]
additional_dependencies: [torch>=1.13, torchmetrics>=0.10, lightning>=1.8, pytest>=6, pyvista>=0.20, omegaconf>=2.1, kornia>=0.6, numpy>=1.22.0]
exclude: (build|data|dist|logo|logs|output)/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The following sections give basic examples of what you can do with TorchGeo.
First we'll import various classes and functions used in the following sections:

```python
from pytorch_lightning import Trainer
from lightning import Trainer
from torch.utils.data import DataLoader
from torchgeo.datamodules import InriaAerialImageLabelingDataModule
from torchgeo.datasets import CDL, Landsat7, Landsat8, VHR10, stack_samples
Expand Down Expand Up @@ -118,9 +118,9 @@ for batch in dataloader:

All TorchGeo datasets are compatible with PyTorch data loaders, making them easy to integrate into existing training workflows. The only difference between a benchmark dataset in TorchGeo and a similar dataset in torchvision is that each dataset returns a dictionary with keys for each PyTorch `Tensor`.

### Reproducibility with PyTorch Lightning
### Reproducibility with Lightning

In order to facilitate direct comparisons between results published in the literature and further reduce the boilerplate code needed to run experiments with datasets in TorchGeo, we have created PyTorch Lightning [*datamodules*](https://torchgeo.readthedocs.io/en/stable/api/datamodules.html) with well-defined train-val-test splits and [*trainers*](https://torchgeo.readthedocs.io/en/stable/api/trainers.html) for various tasks like classification, regression, and semantic segmentation. These datamodules show how to incorporate augmentations from the kornia library, include preprocessing transforms (with pre-calculated channel statistics), and let users easily experiment with hyperparameters related to the data itself (as opposed to the modeling process). Training a semantic segmentation model on the [Inria Aerial Image Labeling](https://project.inria.fr/aerialimagelabeling/) dataset is as easy as a few imports and four lines of code.
In order to facilitate direct comparisons between results published in the literature and further reduce the boilerplate code needed to run experiments with datasets in TorchGeo, we have created Lightning [*datamodules*](https://torchgeo.readthedocs.io/en/stable/api/datamodules.html) with well-defined train-val-test splits and [*trainers*](https://torchgeo.readthedocs.io/en/stable/api/trainers.html) for various tasks like classification, regression, and semantic segmentation. These datamodules show how to incorporate augmentations from the kornia library, include preprocessing transforms (with pre-calculated channel statistics), and let users easily experiment with hyperparameters related to the data itself (as opposed to the modeling process). Training a semantic segmentation model on the [Inria Aerial Image Labeling](https://project.inria.fr/aerialimagelabeling/) dataset is as easy as a few imports and four lines of code.

```python
datamodule = InriaAerialImageLabelingDataModule(root="...", batch_size=64, num_workers=6)
Expand Down
2 changes: 1 addition & 1 deletion benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
import time

import pytorch_lightning as pl
import lightning as pl
import torch
import torch.nn as nn
import torch.optim as optim
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"matplotlib": ("https://matplotlib.org/stable/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"python": ("https://docs.python.org/3", None),
"pytorch-lightning": ("https://pytorch-lightning.readthedocs.io/en/stable/", None),
"lightning": ("https://lightning.ai/docs/pytorch/stable/", None),
"pyvista": ("https://docs.pyvista.org/", None),
"rasterio": ("https://rasterio.readthedocs.io/en/stable/", None),
"rtree": ("https://rtree.readthedocs.io/en/stable/", None),
Expand Down
12 changes: 6 additions & 6 deletions docs/tutorials/pretrained_weights.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pytorch_lightning as pl\n",
"import timm\n",
"from pytorch_lightning.callbacks import EarlyStopping, ModelCheckpoint\n",
"from pytorch_lightning.loggers import CSVLogger\n",
"from lightning import Trainer\n",
"from lightning.callbacks import EarlyStopping, ModelCheckpoint\n",
"from lightning.loggers import CSVLogger\n",
"\n",
"from torchgeo.datamodules import EuroSATDataModule\n",
"from torchgeo.trainers import ClassificationTask\n",
Expand All @@ -92,7 +92,7 @@
"source": [
"## Datamodule\n",
"\n",
"We will utilize TorchGeo's datamodules from [PyTorch Lightning](https://pytorch-lightning.readthedocs.io/) to organize the dataloader setup."
"We will utilize TorchGeo's [Lightning](https://lightning.ai/docs/pytorch/stable/) datamodules to organize the dataloader setup."
]
},
{
Expand Down Expand Up @@ -178,7 +178,7 @@
"source": [
"## Training\n",
"\n",
"To train our pretrained model on the EuroSAT dataset we will make use of PyTorch Lightning's [Trainer](https://pytorch-lightning.readthedocs.io/en/latest/common/trainer.html). For a more elaborate explanation of how TorchGeo uses PyTorch Lightning, check out [this tutorial](https://torchgeo.readthedocs.io/en/stable/tutorials/trainers.html)."
"To train our pretrained model on the EuroSAT dataset we will make use of Lightning's [Trainer](https://lightning.ai/docs/pytorch/stable/common/trainer.html). For a more elaborate explanation of how TorchGeo uses Lightning, check out [this tutorial](https://torchgeo.readthedocs.io/en/stable/tutorials/trainers.html)."
]
},
{
Expand All @@ -204,7 +204,7 @@
"metadata": {},
"outputs": [],
"source": [
"trainer = pl.Trainer(\n",
"trainer = Trainer(\n",
" callbacks=[checkpoint_callback, early_stopping_callback],\n",
" logger=[csv_logger],\n",
" default_root_dir=experiment_dir,\n",
Expand Down
14 changes: 7 additions & 7 deletions docs/tutorials/trainers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"id": "NdrXRgjU7Zih"
},
"source": [
"# PyTorch Lightning Trainers\n",
"# Lightning Trainers\n",
"\n",
"In this tutorial, we demonstrate TorchGeo trainers to train and test a model. Specifically, we use the [Tropical Cyclone dataset](https://torchgeo.readthedocs.io/en/latest/api/datasets.html#tropical-cyclone) and train models to predict cyclone wind speed given imagery of the cyclone.\n",
"\n",
Expand Down Expand Up @@ -74,10 +74,10 @@
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from lightning import Trainer\n",
"from lightning.callbacks import EarlyStopping, ModelCheckpoint\n",
"from lightning.loggers import CSVLogger\n",
"\n",
"import pytorch_lightning as pl\n",
"from pytorch_lightning.callbacks import EarlyStopping, ModelCheckpoint\n",
"from pytorch_lightning.loggers import CSVLogger\n",
"from torchgeo.datamodules import TropicalCycloneDataModule\n",
"from torchgeo.trainers import RegressionTask"
]
Expand All @@ -103,7 +103,7 @@
"source": [
"## Lightning modules\n",
"\n",
"Our trainers use [PyTorch Lightning](https://pytorch-lightning.readthedocs.io/) to organize both the training code, and the dataloader setup code. This makes it easy to create and share reproducible experiments and results.\n",
"Our trainers use [Lightning](https://lightning.ai/docs/pytorch/stable/) to organize both the training code, and the dataloader setup code. This makes it easy to create and share reproducible experiments and results.\n",
"\n",
"First we'll create a `TropicalCycloneDataModule` object which is simply a wrapper around the [TropicalCyclone](https://torchgeo.readthedocs.io/en/latest/api/datasets.html#tropical-cyclone) dataset. This object 1.) ensures that the data is downloaded*, 2.) sets up PyTorch `DataLoader` objects for the train, validation, and test splits, and 3.) ensures that data from the same cyclone **is not** shared between the training and validation sets so that you can properly evaluate the generalization performance of your model.\n",
"\n",
Expand Down Expand Up @@ -178,7 +178,7 @@
"source": [
"## Training\n",
"\n",
"Now that we have the Lightning modules set up, we can use a PyTorch Lightning [Trainer](https://pytorch-lightning.readthedocs.io/en/latest/common/trainer.html) to run the training and evaluation loops. There are many useful pieces of configuration that can be set in the `Trainer` -- below we set up model checkpointing based on the validation loss, early stopping based on the validation loss, and a CSV based logger. We encourage you to see the [PyTorch Lightning docs](https://pytorch-lightning.readthedocs.io/) for other options that can be set here, e.g. Tensorboard logging, automatically selecting your optimizer's learning rate, and easy multi-GPU training."
"Now that we have the Lightning modules set up, we can use a Lightning [Trainer](https://lightning.ai/docs/pytorch/stable/common/trainer.html) to run the training and evaluation loops. There are many useful pieces of configuration that can be set in the `Trainer` -- below we set up model checkpointing based on the validation loss, early stopping based on the validation loss, and a CSV based logger. We encourage you to see the [Lightning docs](https://lightning.ai/docs/pytorch/stable/) for other options that can be set here, e.g. Tensorboard logging, automatically selecting your optimizer's learning rate, and easy multi-GPU training."
]
},
{
Expand Down Expand Up @@ -226,7 +226,7 @@
}
],
"source": [
"trainer = pl.Trainer(\n",
"trainer = Trainer(\n",
" callbacks=[checkpoint_callback, early_stopping_callback],\n",
" logger=[csv_logger],\n",
" default_root_dir=experiment_dir,\n",
Expand Down
4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies:
- isort[colors]>=5.8
- kornia>=0.6.5
- laspy>=2
- lightning>=1.8
- mypy>=0.900
- nbmake>=0.1
- nbsphinx>=0.8.5
Expand All @@ -35,10 +36,9 @@ dependencies:
- pydocstyle[toml]>=6.1
- pytest>=6.1.2
- pytest-cov>=2.4
- pytorch-lightning>=1.5.1
- git+https://github.com/pytorch/pytorch_sphinx_theme
- pyupgrade>=2.4
- radiant-mlhub>=0.2.1
- radiant-mlhub>=0.3
- rtree>=1
- scikit-image>=0.18
- scikit-learn>=0.22
Expand Down
4 changes: 2 additions & 2 deletions evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import os
from typing import Any, Dict, Union, cast

import pytorch_lightning as pl
import lightning as pl
import torch
from torchmetrics import MetricCollection
from torchmetrics.classification import BinaryAccuracy, BinaryJaccardIndex
Expand Down Expand Up @@ -146,7 +146,7 @@ def main(args: argparse.Namespace) -> None:
model.freeze()
model.eval()

dm = DATAMODULE( # type: ignore[call-arg]
dm = DATAMODULE(
seed=args.seed,
root=args.root,
num_workers=args.num_workers,
Expand Down
8 changes: 4 additions & 4 deletions experiments/run_chesapeakecvpr_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import csv
import os

import pytorch_lightning as pl
import torch
from lightning import Trainer

from torchgeo.datamodules import ChesapeakeCVPRDataModule
from torchgeo.trainers.chesapeake import SemanticSegmentationTask
Expand Down Expand Up @@ -86,8 +85,9 @@ def main(args: argparse.Namespace) -> None:
writer.writeheader()

# Test loop
trainer = pl.Trainer(
gpus=[args.device] if torch.cuda.is_available() else None,
trainer = Trainer(
accelerator="auto",
devices=[args.device],
logger=False,
enable_progress_bar=False,
enable_checkpointing=False,
Expand Down
13 changes: 6 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ filterwarnings = [
# https://github.com/Lightning-AI/lightning/pull/13261
"ignore:torch.distributed._sharded_tensor will be deprecated:DeprecationWarning:torch.distributed._sharded_tensor",
# https://github.com/Lightning-AI/lightning/issues/13989
"ignore:SelectableGroups dict interface is deprecated. Use select.:DeprecationWarning:pytorch_lightning.trainer.connectors.callback_connector",
"ignore:SelectableGroups dict interface is deprecated. Use select.:DeprecationWarning:lightning.pytorch.trainer.connectors.callback_connector",
# https://github.com/Lightning-AI/lightning/issues/14594
"ignore:To copy construct from a tensor, it is recommended to use:UserWarning:pytorch_lightning.core.module",
"ignore:To copy construct from a tensor, it is recommended to use:UserWarning:lightning.pytorch.core.module",
# https://github.com/rasterio/rasterio/issues/1742
# https://github.com/rasterio/rasterio/pull/1753
"ignore:Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated:DeprecationWarning:rasterio.crs",
Expand All @@ -94,21 +94,20 @@ filterwarnings = [
# https://github.com/lanpa/tensorboardX/pull/677
"ignore:ANTIALIAS is deprecated and will be removed in Pillow 10:DeprecationWarning:tensorboardX.summary",
# https://github.com/Lightning-AI/lightning/issues/16756
"ignore:Deprecated call to `pkg_resources.declare_namespace:DeprecationWarning:lightning_fabric",
"ignore:Deprecated call to `pkg_resources.declare_namespace:DeprecationWarning:pytorch_lightning",
"ignore:Deprecated call to `pkg_resources.declare_namespace:DeprecationWarning",

# Expected warnings
# pytorch-lightning warns us about using num_workers=0, but it's faster on macOS
# Lightning warns us about using num_workers=0, but it's faster on macOS
"ignore:The dataloader, .*, does not have many workers which may be a bottleneck:UserWarning",
# pytorch-lightning warns us about using the CPU when a GPU is available
# Lightning warns us about using the CPU when a GPU is available
"ignore:GPU available but not used.:UserWarning",
# https://github.com/kornia/kornia/pull/1611
"ignore:`ColorJitter` is now following Torchvision implementation.:DeprecationWarning:kornia.augmentation._2d.intensity.color_jitter",
# https://github.com/kornia/kornia/pull/1663
"ignore:`RandomGaussianBlur` has changed its behavior and now randomly sample sigma for both axes.:DeprecationWarning:kornia.augmentation._2d.intensity.gaussian_blur",

# Unexpected warnings, worth investigating
# pytorch-lightning is having trouble inferring the batch size for ChesapeakeCVPRDataModule and CycloneDataModule for some reason
# Lightning is having trouble inferring the batch size for ChesapeakeCVPRDataModule and CycloneDataModule for some reason
"ignore:Trying to infer the `batch_size` from an ambiguous collection:UserWarning",
]
markers = [
Expand Down
4 changes: 2 additions & 2 deletions requirements/min-reqs.old
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ setuptools==42.0.0
einops==0.3.0
fiona==1.8.12
kornia==0.6.5
lightning==1.8.0
matplotlib==3.3.0
numpy==1.17.3
omegaconf==2.1.0
pillow==6.2.1
pyproj==2.4.1
pytorch-lightning==1.5.1
rasterio==1.1.1
rtree==1.0.0
scikit-learn==0.22
Expand All @@ -28,7 +28,7 @@ opencv-python==4.1.2.30
pandas==0.25.2
pycocotools==2.0.1
pyvista==0.25.2
radiant-mlhub==0.2.1
radiant-mlhub==0.3.0
rarfile==4.0
scikit-image==0.18.0
scipy==1.6.2
Expand Down
2 changes: 1 addition & 1 deletion requirements/required.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ setuptools==67.6.0
einops==0.6.0
fiona==1.9.1
kornia==0.6.10
lightning[extra]==2.0.0
matplotlib==3.7.1
numpy==1.24.2
omegaconf==2.3.0
pillow==9.4.0
pyproj==3.4.1
pytorch-lightning[extra]==1.9.4
rasterio==1.3.6
rtree==1.0.1
scikit-learn==1.2.2
Expand Down
9 changes: 4 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ install_requires =
fiona>=1.8.12,<2
# kornia 0.6.5+ required due to change in kornia.augmentation API
kornia>=0.6.5,<0.7
# lightning 1.8+ is first release
lightning[extra]>=1.8,<2
# matplotlib 3.3+ required for (H, W, 1) image support in plt.imshow
matplotlib>=3.3,<4
# numpy 1.17.3+ required by Python 3.8 wheels
Expand All @@ -40,8 +42,6 @@ install_requires =
pillow>=6.2.1,<10
# pyproj 2.4.1+ required for Python 3.8 wheels
pyproj>=2.4.1,<4
# pytorch-lightning 1.5.1+ required for apply_to_collection bugfix
pytorch-lightning[extra]>=1.5.1,<2
# rasterio 1.1.1+ required for Python 3.8 wheels
rasterio>=1.1.1,<2
# rtree 1+ required for len(index), index & index, index | index
Expand Down Expand Up @@ -83,9 +83,8 @@ datasets =
pycocotools>=2.0.1,<3
# pyvista 0.25.2 required for wheels
pyvista>=0.25.2,<0.39
# radiant-mlhub 0.2.1+ required for api_key bugfix:
# https://github.com/radiantearth/radiant-mlhub/pull/48
radiant-mlhub>=0.2.1,<0.6
# radiant-mlhub 0.3+ required for newer tqdm support required by lightning
radiant-mlhub>=0.3,<0.6
# rarfile 4+ required for wheels
rarfile>=4,<5
# scikit-image 0.18+ required for numpy 1.17+ compatibility
Expand Down
8 changes: 4 additions & 4 deletions tests/datamodules/test_oscd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest
from _pytest.fixtures import SubRequest
from pytorch_lightning import Trainer
from lightning import Trainer

from torchgeo.datamodules import OSCDDataModule

Expand All @@ -30,7 +30,7 @@ def datamodule(self, request: SubRequest) -> OSCDDataModule:

def test_train_dataloader(self, datamodule: OSCDDataModule) -> None:
datamodule.setup("fit")
datamodule.trainer.training = True # type: ignore[union-attr]
datamodule.trainer.training = True
batch = next(iter(datamodule.train_dataloader()))
batch = datamodule.on_after_batch_transfer(batch, 0)
assert batch["image"].shape[-2:] == batch["mask"].shape[-2:] == (2, 2)
Expand All @@ -42,7 +42,7 @@ def test_train_dataloader(self, datamodule: OSCDDataModule) -> None:

def test_val_dataloader(self, datamodule: OSCDDataModule) -> None:
datamodule.setup("validate")
datamodule.trainer.validating = True # type: ignore[union-attr]
datamodule.trainer.validating = True
batch = next(iter(datamodule.val_dataloader()))
batch = datamodule.on_after_batch_transfer(batch, 0)
if datamodule.val_split_pct > 0.0:
Expand All @@ -55,7 +55,7 @@ def test_val_dataloader(self, datamodule: OSCDDataModule) -> None:

def test_test_dataloader(self, datamodule: OSCDDataModule) -> None:
datamodule.setup("test")
datamodule.trainer.testing = True # type: ignore[union-attr]
datamodule.trainer.testing = True
batch = next(iter(datamodule.test_dataloader()))
batch = datamodule.on_after_batch_transfer(batch, 0)
assert batch["image"].shape[-2:] == batch["mask"].shape[-2:] == (2, 2)
Expand Down
2 changes: 1 addition & 1 deletion tests/trainers/test_byol.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import torchvision
from _pytest.fixtures import SubRequest
from _pytest.monkeypatch import MonkeyPatch
from lightning import LightningDataModule, Trainer
from omegaconf import OmegaConf
from pytorch_lightning import LightningDataModule, Trainer
from torchvision.models import resnet18
from torchvision.models._api import WeightsEnum

Expand Down
2 changes: 1 addition & 1 deletion tests/trainers/test_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import torchvision
from _pytest.fixtures import SubRequest
from _pytest.monkeypatch import MonkeyPatch
from lightning import LightningDataModule, Trainer
from omegaconf import OmegaConf
from pytorch_lightning import LightningDataModule, Trainer
from torch.nn.modules import Module
from torchvision.models._api import WeightsEnum

Expand Down
2 changes: 1 addition & 1 deletion tests/trainers/test_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import torch.nn as nn
import torchvision.models.detection
from _pytest.monkeypatch import MonkeyPatch
from lightning import LightningDataModule, Trainer
from omegaconf import OmegaConf
from pytorch_lightning import LightningDataModule, Trainer
from torch.nn.modules import Module

from torchgeo.datamodules import MisconfigurationException, NASAMarineDebrisDataModule
Expand Down
2 changes: 1 addition & 1 deletion tests/trainers/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import torchvision
from _pytest.fixtures import SubRequest
from _pytest.monkeypatch import MonkeyPatch
from lightning import LightningDataModule, Trainer
from omegaconf import OmegaConf
from pytorch_lightning import LightningDataModule, Trainer
from torchvision.models._api import WeightsEnum

from torchgeo.datamodules import (
Expand Down
2 changes: 1 addition & 1 deletion tests/trainers/test_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import torch
import torch.nn as nn
from _pytest.monkeypatch import MonkeyPatch
from lightning import LightningDataModule, Trainer
from omegaconf import OmegaConf
from pytorch_lightning import LightningDataModule, Trainer
from torch.nn.modules import Module

from torchgeo.datamodules import (
Expand Down
Loading