From b4d31b480bd881986a1618b0425f6a9bfc0bc999 Mon Sep 17 00:00:00 2001 From: InCogNiTo124 Date: Mon, 3 Aug 2020 14:23:51 +0200 Subject: [PATCH 01/24] Add Cityscapes DataModule --- pl_bolts/datamodules/cityscapes_datamodule.py | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 pl_bolts/datamodules/cityscapes_datamodule.py diff --git a/pl_bolts/datamodules/cityscapes_datamodule.py b/pl_bolts/datamodules/cityscapes_datamodule.py new file mode 100644 index 0000000000..c4ae91ed46 --- /dev/null +++ b/pl_bolts/datamodules/cityscapes_datamodule.py @@ -0,0 +1,135 @@ +from typing import Optional, Sequence + +from pytorch_lightning import LightningDataModule +from torch.utils.data import DataLoader, random_split +from torchvision import transforms as transform_lib +from torchvision.datasets import Cityscapes + + +class CityscapesDataModule(LightningDataModule): + + name = 'Cityscapes' + extra_args = {} + + def __init__( + self, + data_dir, + val_split=5000, + num_workers=16, + batch_size=32, + *args, + **kwargs, + ): + """ + Standard Cityscapes, train, val, test splits and transforms + + Transforms: + + transforms = transform_lib.Compose([ + transform_lib.ToTensor(), + ]) + + Example:: + + from pl_bolts.datamodules import CityscapesDataModule + + dm = CityscapesDataModule(PATH) + model = LitModel(datamodule=dm) + + Or you can set your own transforms + + Example:: + + dm.train_transforms = ... + dm.test_transforms = ... + dm.val_transforms = ... + + Args: + data_dir: where to save/load the data + val_split: how many of the training images to use for the validation split + num_workers: how many workers to use for loading data + batch_size: number of examples per training/eval step + """ + super().__init__(*args, **kwargs) + self.dims = (3, 32, 32) + self.DATASET = Cityscapes + self.data_dir = data_dir + self.val_split = val_split + self.num_workers = num_workers + self.batch_size = batch_size + + @property + def num_classes(self): + """ + Return: + 30 + """ + return 30 + + def prepare_data(self): + """ + Saves Cityscapes files to data_dir + """ + self.DATASET(self.data_dir, train=True, download=True, transform=transform_lib.ToTensor(), **self.extra_args) + self.DATASET(self.data_dir, train=False, download=True, transform=transform_lib.ToTensor(), **self.extra_args) + + def train_dataloader(self): + """ + Cityscapes train set with removed subset to use for validation + """ + transforms = self.default_transforms() if self.train_transforms is None else self.train_transforms + + dataset = self.DATASET(self.data_dir, train=True, download=False, transform=transforms, **self.extra_args) + train_length = len(dataset) + dataset_train, _ = random_split(dataset, [train_length - self.val_split, self.val_split]) + loader = DataLoader( + dataset_train, + batch_size=self.batch_size, + shuffle=True, + num_workers=self.num_workers, + drop_last=True, + pin_memory=True + ) + return loader + + def val_dataloader(self): + """ + Cityscapes val set uses a subset of the training set for validation + """ + transforms = self.default_transforms() if self.val_transforms is None else self.val_transforms + + dataset = self.DATASET(self.data_dir, train=True, download=False, transform=transforms, **self.extra_args) + train_length = len(dataset) + _, dataset_val = random_split(dataset, [train_length - self.val_split, self.val_split]) + loader = DataLoader( + dataset_val, + batch_size=self.batch_size, + shuffle=False, + num_workers=self.num_workers, + pin_memory=True, + drop_last=True + ) + return loader + + def test_dataloader(self): + """ + Cityscapes test set uses the test split + """ + transforms = self.default_transforms() if self.test_transforms is None else self.test_transforms + + dataset = self.DATASET(self.data_dir, train=False, download=False, transform=transforms, **self.extra_args) + loader = DataLoader( + dataset, + batch_size=self.batch_size, + shuffle=False, + num_workers=self.num_workers, + drop_last=True, + pin_memory=True + ) + return loader + + def default_transforms(self): + cityscapes_transforms = transform_lib.Compose([ + transform_lib.ToTensor(), + ]) + return cityscapes_transforms From d1071cd6f6a715bde4162e09f1ee7c5370590c29 Mon Sep 17 00:00:00 2001 From: InCogNiTo124 Date: Mon, 3 Aug 2020 14:37:42 +0200 Subject: [PATCH 02/24] Fix docs? --- pl_bolts/datamodules/cityscapes_datamodule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pl_bolts/datamodules/cityscapes_datamodule.py b/pl_bolts/datamodules/cityscapes_datamodule.py index c4ae91ed46..195a3108fa 100644 --- a/pl_bolts/datamodules/cityscapes_datamodule.py +++ b/pl_bolts/datamodules/cityscapes_datamodule.py @@ -23,7 +23,7 @@ def __init__( """ Standard Cityscapes, train, val, test splits and transforms - Transforms: + Transforms:: transforms = transform_lib.Compose([ transform_lib.ToTensor(), From 2a38debc991761ce3a3a91de744f552d37d8f4a2 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 16:57:23 -0400 Subject: [PATCH 03/24] docs --- docs/source/dataloaders.rst | 21 +++++ docs/source/datamodules.rst | 179 ++++-------------------------------- docs/source/index.rst | 7 ++ 3 files changed, 48 insertions(+), 159 deletions(-) create mode 100644 docs/source/dataloaders.rst diff --git a/docs/source/dataloaders.rst b/docs/source/dataloaders.rst new file mode 100644 index 0000000000..efe932027b --- /dev/null +++ b/docs/source/dataloaders.rst @@ -0,0 +1,21 @@ +AsynchronousLoader +------------------ +This dataloader behaves identically to the standard pytorch dataloader, but will transfer +data asynchronously to the GPU with training. You can also use it to wrap an existing dataloader. + +Example:: + dataloader = AsynchronousLoader(DataLoader(ds, batch_size=16), device=device) + + for b in dataloader: + ... + +.. autoclass:: pl_bolts.datamodules.async_dataloader.AsynchronousLoader + :noindex: + +------------------ + +DummyDataset +------------ + +.. autoclass:: pl_bolts.datamodules.dummy_dataset.DummyDataset + :noindex: diff --git a/docs/source/datamodules.rst b/docs/source/datamodules.rst index 77c06f9c80..6468326e5c 100644 --- a/docs/source/datamodules.rst +++ b/docs/source/datamodules.rst @@ -1,175 +1,36 @@ .. role:: hidden :class: hidden-section -Lightning DataModule -==================== -Datasets in PyTorch, Lightning and general Deep learning research have 4 main parts: +DataModules +----------- +DataModules (introduced in PyTorch Lightning 0.9.0) decouple the data from a model. A DataModule +is simply a collection of a training dataloder, val dataloader and test dataloader. In addition, +it specifies how to: - 1. A train split + dataloader - 2. A val split + dataloader - 3. A test split + dataloader - 4. A step to download, split, etc... +- Downloading/preparing data. +- Train/val/test splits. +- Transforms -Step 4, also needs special care to make sure that it's only done on 1 GPU in a multi-GPU set-up. -In addition, there are other challenges such as models that are built using information from the dataset -such as needing to know image dimensions or number of classes. - -A datamodule simplifies all of these parts and has been integrated directly into Lightning in version 0.9.0. -You can view the documentation for the datamodule in the `Pytorch Lightning docs here. `_ - -.. code-block:: python - - class LitModel(pl.LightningModule): - - def __init__(self, datamodule): - c, w, h = datamodule.size() - self.l1 = nn.Linear(128, datamodule.num_classes) - self.datamodule = datamodule - - def prepare_data(self): - self.datamodule.prepare_data() - - def train_dataloader(self) - return self.datamodule.train_dataloader() - - def val_dataloader(self) - return self.datamodule.val_dataloader() - - def test_dataloader(self) - return self.datamodule.test_dataloader() - -DataModules can also be used with plain PyTorch - -.. code-block:: python - - from pl_bolts.datamodules import MNISTDataModule, CIFAR10DataModule - - datamodule = CIFAR10DataModule(PATH) - train_loader = datamodule.train_dataloader() - val_loader = datamodule.train_dataloader() - test_loader = datamodule.train_dataloader() - -An advantage is that you can parametrize the data of your LightningModule - -.. code-block:: python - - model = LitModel(datamodule = CIFAR10DataModule(PATH)) - model = LitModel(datamodule = ImagenetDataModule(PATH)) - -Or even bridge between SKLearn or numpy datasets - -.. code-block:: python - - from sklearn.datasets import load_boston - from pl_bolts.datamodules import SklearnDataModule - - X, y = load_boston(return_X_y=True) - datamodule = SklearnDataModule(X, y) - - model = LitModel(datamodule) - - -DataModule Advantages ---------------------- -Datamodules have two advantages: - - 1. You can guarantee that the exact same train, val and test splits can be used across models. - 2. You can parameterize your model to be dataset agnostic. +Then you can use it like this: Example:: - from pl_bolts.datamodules import STL10DataModule, CIFAR10DataModule + dm = MNISTDataModule('path/to/data') + model = LitModel() - # use the same dataset on different models (with exactly the same splits) - stl10_model = LitModel(STL10DataModule(PATH)) - stl10_model = CoolModel(STL10DataModule(PATH)) + trainer = Trainer() + trainer.fit(model, dm) - # or make your model dataset agnostic - cifar10_model = LitModel(CIFAR10DataModule(PATH)) - -Build a DataModule ------------------- -Use this to build your own consistent train, validation, test splits. +Or use it manually with plain PyTorch Example:: - from pytorch_lightning import LightningDataModule - - class MyDataModule(LightningDataModule): - - def __init__(self,...): - - def prepare_data(self): - # download and do something to your data - - def train_dataloader(self, batch_size): - return DataLoader(...) - - def val_dataloader(self, batch_size): - return DataLoader(...) - - def test_dataloader(self, batch_size): - return DataLoader(...) - -Then use this in any model you want. - -Example:: - - class LitModel(pl.LightningModule): - - def __init__(self, data_module=MyDataModule(PATH)): - super().__init() - self.dm = data_module - - def prepare_data(self): - self.dm.prepare_data() - - def train_dataloader(self): - return self.dm.train_dataloader() - - def val_dataloader(self): - return self.dm.val_dataloader() - - def test_dataloader(self): - return self.dm.test_dataloader() - -Asynchronous Loading --------------------- -DataModules also includes an extra asynchronous dataloader for accelerating single GPU training. - -This dataloader behaves identically to the standard pytorch dataloader, but will transfer -data asynchronously to the GPU with training. You can also use it to wrap an existing dataloader. - -Example:: - - from pl_bolts.datamodules.cifar10_dataset import CIFAR10 - ds = CIFAR10(tmpdir) - device = torch.device('cuda', 0) - - dataloader = AsynchronousLoader(ds, device=device) - - for b in dataloader: + dm = MNISTDataModule('path/to/data') + for batch in dm.train_dataloader(): ... - -or:: - - dataloader = AsynchronousLoader(DataLoader(ds, batch_size=16), device=device) - - for b in dataloader: + for batch in dm.val_dataloader(): + ... + for batch in dm.test_dataloader(): ... -------------- - -DummyDataset ------------- - -.. autoclass:: pl_bolts.datamodules.dummy_dataset.DummyDataset - :noindex: - -------------- - -AsynchronousLoader ------------------- - -.. autoclass:: pl_bolts.datamodules.async_dataloader.AsynchronousLoader - :noindex: +Please visit the PyTorch Lightning documentation for more details on DataModules diff --git a/docs/source/index.rst b/docs/source/index.rst index 83995b6289..d3408e3f11 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -31,6 +31,13 @@ PyTorch-Lightning-Bolts documentation sklearn_datamodule vision_datamodules +.. toctree:: + :maxdepth: 2 + :name: dataloaders + :caption: DataLoaders + + dataloaders + .. toctree:: :maxdepth: 2 :name: losses From b53145fce741cf15d8b4c166208d011f2ff6b994 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:05:15 -0400 Subject: [PATCH 04/24] docs --- docs/source/vision_datamodules.rst | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/docs/source/vision_datamodules.rst b/docs/source/vision_datamodules.rst index e44b1b1271..baf35fb0dc 100644 --- a/docs/source/vision_datamodules.rst +++ b/docs/source/vision_datamodules.rst @@ -9,10 +9,15 @@ Supervised learning These are standard vision datasets with the train, test, val splits pre-generated in DataLoaders with the standard transforms (and Normalization) values -MNIST -^^^^^ +CityScapes +^^^^^^^^^^ -.. autoclass:: pl_bolts.datamodules.mnist_datamodule.MNISTDataModule +.. autoclass:: pl_bolts.datamodules.cityscapes_datamodule.CityscapesDataModule + +CIFAR-10 +^^^^^^^^ + +.. autoclass:: pl_bolts.datamodules.cifar10_datamodule.CIFAR10DataModule :noindex: FashionMNIST @@ -21,12 +26,6 @@ FashionMNIST .. autoclass:: pl_bolts.datamodules.fashion_mnist_datamodule.FashionMNISTDataModule :noindex: -CIFAR-10 -^^^^^^^^ - -.. autoclass:: pl_bolts.datamodules.cifar10_datamodule.CIFAR10DataModule - :noindex: - Imagenet ^^^^^^^^ @@ -34,6 +33,12 @@ Imagenet .. autoclass:: pl_bolts.datamodules.imagenet_datamodule.ImagenetDataModule :noindex: +MNIST +^^^^^ + +.. autoclass:: pl_bolts.datamodules.mnist_datamodule.MNISTDataModule + :noindex: + ------------ Semi-supervised learning From 3108d7fd83ecc2dbb284e0ccbbf11e7139f3e4ea Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:08:53 -0400 Subject: [PATCH 05/24] docs --- pl_bolts/datamodules/cityscapes_datamodule.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pl_bolts/datamodules/cityscapes_datamodule.py b/pl_bolts/datamodules/cityscapes_datamodule.py index 195a3108fa..58b5790413 100644 --- a/pl_bolts/datamodules/cityscapes_datamodule.py +++ b/pl_bolts/datamodules/cityscapes_datamodule.py @@ -1,9 +1,8 @@ -from typing import Optional, Sequence - from pytorch_lightning import LightningDataModule from torch.utils.data import DataLoader, random_split from torchvision import transforms as transform_lib from torchvision.datasets import Cityscapes +import torch class CityscapesDataModule(LightningDataModule): @@ -17,6 +16,7 @@ def __init__( val_split=5000, num_workers=16, batch_size=32, + seed=42, *args, **kwargs, ): @@ -57,6 +57,7 @@ def __init__( self.val_split = val_split self.num_workers = num_workers self.batch_size = batch_size + self.seed = seed @property def num_classes(self): @@ -81,7 +82,11 @@ def train_dataloader(self): dataset = self.DATASET(self.data_dir, train=True, download=False, transform=transforms, **self.extra_args) train_length = len(dataset) - dataset_train, _ = random_split(dataset, [train_length - self.val_split, self.val_split]) + dataset_train, _ = random_split( + dataset, + [train_length - self.val_split, self.val_split], + generator=torch.Generator().manual_seed(self.seed) + ) loader = DataLoader( dataset_train, batch_size=self.batch_size, @@ -100,7 +105,11 @@ def val_dataloader(self): dataset = self.DATASET(self.data_dir, train=True, download=False, transform=transforms, **self.extra_args) train_length = len(dataset) - _, dataset_val = random_split(dataset, [train_length - self.val_split, self.val_split]) + _, dataset_val = random_split( + dataset, + [train_length - self.val_split, self.val_split], + generator=torch.Generator().manual_seed(self.seed) + ) loader = DataLoader( dataset_val, batch_size=self.batch_size, From ce31d39488d3c714dc4134adf617da991bd430dc Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:10:34 -0400 Subject: [PATCH 06/24] docs --- pl_bolts/datamodules/cityscapes_datamodule.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pl_bolts/datamodules/cityscapes_datamodule.py b/pl_bolts/datamodules/cityscapes_datamodule.py index 58b5790413..b9335706be 100644 --- a/pl_bolts/datamodules/cityscapes_datamodule.py +++ b/pl_bolts/datamodules/cityscapes_datamodule.py @@ -138,7 +138,11 @@ def test_dataloader(self): return loader def default_transforms(self): + mean = [0.28689554, 0.32513303, 0.28389177] + std = [0.18696375, 0.19017339, 0.18720214] + cityscapes_transforms = transform_lib.Compose([ transform_lib.ToTensor(), + transform_lib.Normalize(mean=mean, std=std) ]) return cityscapes_transforms From 82acea8f3113bef5aacfb35991a4ec9401bbd6b5 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:11:13 -0400 Subject: [PATCH 07/24] docs --- pl_bolts/datamodules/cityscapes_datamodule.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pl_bolts/datamodules/cityscapes_datamodule.py b/pl_bolts/datamodules/cityscapes_datamodule.py index b9335706be..e06ffe5d54 100644 --- a/pl_bolts/datamodules/cityscapes_datamodule.py +++ b/pl_bolts/datamodules/cityscapes_datamodule.py @@ -27,6 +27,10 @@ def __init__( transforms = transform_lib.Compose([ transform_lib.ToTensor(), + transform_lib.Normalize( + mean=[0.28689554, 0.32513303, 0.28389177], + std=[0.18696375, 0.19017339, 0.18720214] + ) ]) Example:: @@ -138,11 +142,11 @@ def test_dataloader(self): return loader def default_transforms(self): - mean = [0.28689554, 0.32513303, 0.28389177] - std = [0.18696375, 0.19017339, 0.18720214] - cityscapes_transforms = transform_lib.Compose([ transform_lib.ToTensor(), - transform_lib.Normalize(mean=mean, std=std) + transform_lib.Normalize( + mean=[0.28689554, 0.32513303, 0.28389177], + std=[0.18696375, 0.19017339, 0.18720214] + ) ]) return cityscapes_transforms From b5c1cd905cad71e0b8ecb0687b47fd21ca14bf85 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:33:25 -0400 Subject: [PATCH 08/24] docs --- docs/source/vision_datamodules.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/vision_datamodules.rst b/docs/source/vision_datamodules.rst index baf35fb0dc..3ad554d347 100644 --- a/docs/source/vision_datamodules.rst +++ b/docs/source/vision_datamodules.rst @@ -13,6 +13,7 @@ CityScapes ^^^^^^^^^^ .. autoclass:: pl_bolts.datamodules.cityscapes_datamodule.CityscapesDataModule + :noindex: CIFAR-10 ^^^^^^^^ From 7b4baa2576e64677fe8d331c2115c1305e8a0f44 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:35:06 -0400 Subject: [PATCH 09/24] docs --- pl_bolts/datamodules/cityscapes_datamodule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pl_bolts/datamodules/cityscapes_datamodule.py b/pl_bolts/datamodules/cityscapes_datamodule.py index e06ffe5d54..5ed6aff02e 100644 --- a/pl_bolts/datamodules/cityscapes_datamodule.py +++ b/pl_bolts/datamodules/cityscapes_datamodule.py @@ -5,7 +5,7 @@ import torch -class CityscapesDataModule(LightningDataModule): +class CityscapesDataModule(LightningDataModule): # pragma: no-cover name = 'Cityscapes' extra_args = {} From 6bf7c31d257fdb66cf25f2a7f3fd5bb624da963a Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:35:33 -0400 Subject: [PATCH 10/24] docs --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 62dd227648..644db29746 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,6 +27,7 @@ omit = pl_bolts/datamodules/concat_dataset.py pl_bolts/datamodules/cifar10_datamodule.py pl_bolts/datamodules/fashion_mnist_datamodule.py + pl_bolts/datamodules/*datamodule.py pl_bolts/datamodules/_datamodule.py [flake8] From f29005ae7079a5f1deedbea949236575aea6c022 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:35:43 -0400 Subject: [PATCH 11/24] docs --- pl_bolts/datamodules/cityscapes_datamodule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pl_bolts/datamodules/cityscapes_datamodule.py b/pl_bolts/datamodules/cityscapes_datamodule.py index 5ed6aff02e..e06ffe5d54 100644 --- a/pl_bolts/datamodules/cityscapes_datamodule.py +++ b/pl_bolts/datamodules/cityscapes_datamodule.py @@ -5,7 +5,7 @@ import torch -class CityscapesDataModule(LightningDataModule): # pragma: no-cover +class CityscapesDataModule(LightningDataModule): name = 'Cityscapes' extra_args = {} From 2e47f35fa2fa1e3161a2841cf4ed8aa9fd2624c2 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:39:35 -0400 Subject: [PATCH 12/24] docs --- docs/source/vision_datamodules.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/source/vision_datamodules.rst b/docs/source/vision_datamodules.rst index 3ad554d347..9ec839405a 100644 --- a/docs/source/vision_datamodules.rst +++ b/docs/source/vision_datamodules.rst @@ -36,6 +36,9 @@ Imagenet MNIST ^^^^^ +.. figure:: https://upload.wikimedia.org/wikipedia/commons/2/27/MnistExamples.png + :width: 800 + :alt: MNIST .. autoclass:: pl_bolts.datamodules.mnist_datamodule.MNISTDataModule :noindex: From ee730b08108239bba65bb1bb41a60550294fa52d Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:41:47 -0400 Subject: [PATCH 13/24] docs --- docs/source/vision_datamodules.rst | 2 +- pl_bolts/datamodules/mnist_datamodule.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/source/vision_datamodules.rst b/docs/source/vision_datamodules.rst index 9ec839405a..25735e9530 100644 --- a/docs/source/vision_datamodules.rst +++ b/docs/source/vision_datamodules.rst @@ -37,7 +37,7 @@ Imagenet MNIST ^^^^^ .. figure:: https://upload.wikimedia.org/wikipedia/commons/2/27/MnistExamples.png - :width: 800 + :width: 400 :alt: MNIST .. autoclass:: pl_bolts.datamodules.mnist_datamodule.MNISTDataModule diff --git a/pl_bolts/datamodules/mnist_datamodule.py b/pl_bolts/datamodules/mnist_datamodule.py index 7b62c622ca..12fc535a4e 100644 --- a/pl_bolts/datamodules/mnist_datamodule.py +++ b/pl_bolts/datamodules/mnist_datamodule.py @@ -40,6 +40,10 @@ def __init__( val_split: how many of the training images to use for the validation split num_workers: how many workers to use for loading data normalize: If true applies image normalize + + Specs: + - 10 classes (1 per digit) + - Each image is (1 x 32 x 32) """ super().__init__(*args, **kwargs) self.dims = (1, 28, 28) From 3f21cc4e056e67c4f13cfa0faad7817a7153eb07 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:42:12 -0400 Subject: [PATCH 14/24] docs --- docs/source/vision_datamodules.rst | 3 --- pl_bolts/datamodules/mnist_datamodule.py | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/source/vision_datamodules.rst b/docs/source/vision_datamodules.rst index 25735e9530..3ad554d347 100644 --- a/docs/source/vision_datamodules.rst +++ b/docs/source/vision_datamodules.rst @@ -36,9 +36,6 @@ Imagenet MNIST ^^^^^ -.. figure:: https://upload.wikimedia.org/wikipedia/commons/2/27/MnistExamples.png - :width: 400 - :alt: MNIST .. autoclass:: pl_bolts.datamodules.mnist_datamodule.MNISTDataModule :noindex: diff --git a/pl_bolts/datamodules/mnist_datamodule.py b/pl_bolts/datamodules/mnist_datamodule.py index 12fc535a4e..d08d13b678 100644 --- a/pl_bolts/datamodules/mnist_datamodule.py +++ b/pl_bolts/datamodules/mnist_datamodule.py @@ -20,6 +20,10 @@ def __init__( **kwargs, ): """ + .. figure:: https://upload.wikimedia.org/wikipedia/commons/2/27/MnistExamples.png + :width: 400 + :alt: MNIST + Standard MNIST, train, val, test splits and transforms Transforms:: From 64b9d5782c3c5b4110d3087bf08cda201304725e Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:50:11 -0400 Subject: [PATCH 15/24] docs --- pl_bolts/datamodules/cityscapes_datamodule.py | 8 ++++++++ pl_bolts/datamodules/mnist_datamodule.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pl_bolts/datamodules/cityscapes_datamodule.py b/pl_bolts/datamodules/cityscapes_datamodule.py index e06ffe5d54..62f0aff0b2 100644 --- a/pl_bolts/datamodules/cityscapes_datamodule.py +++ b/pl_bolts/datamodules/cityscapes_datamodule.py @@ -21,8 +21,16 @@ def __init__( **kwargs, ): """ + .. figure:: https://www.cityscapes-dataset.com/wordpress/wp-content/uploads/2015/07/muenster00-1024x510.png + :width: 400 + :alt: MNIST + Standard Cityscapes, train, val, test splits and transforms + Specs: + - 30 classes (road, person, sidewalk, etc...) + - (image, target) - image dims: (3 x 32 x 32), target dims: (3 x 32 x 32) + Transforms:: transforms = transform_lib.Compose([ diff --git a/pl_bolts/datamodules/mnist_datamodule.py b/pl_bolts/datamodules/mnist_datamodule.py index d08d13b678..75e1d759fc 100644 --- a/pl_bolts/datamodules/mnist_datamodule.py +++ b/pl_bolts/datamodules/mnist_datamodule.py @@ -20,7 +20,7 @@ def __init__( **kwargs, ): """ - .. figure:: https://upload.wikimedia.org/wikipedia/commons/2/27/MnistExamples.png + .. figure:: https://miro.medium.com/max/744/1*AO2rIhzRYzFVQlFLx9DM9A.png :width: 400 :alt: MNIST From 96683d018d41cd42fd44bd5eb17f2ea3486deb77 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:51:19 -0400 Subject: [PATCH 16/24] docs --- pl_bolts/datamodules/mnist_datamodule.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pl_bolts/datamodules/mnist_datamodule.py b/pl_bolts/datamodules/mnist_datamodule.py index 75e1d759fc..12430d254f 100644 --- a/pl_bolts/datamodules/mnist_datamodule.py +++ b/pl_bolts/datamodules/mnist_datamodule.py @@ -24,6 +24,10 @@ def __init__( :width: 400 :alt: MNIST + Specs: + - 10 classes (1 per digit) + - Each image is (1 x 32 x 32) + Standard MNIST, train, val, test splits and transforms Transforms:: @@ -44,10 +48,6 @@ def __init__( val_split: how many of the training images to use for the validation split num_workers: how many workers to use for loading data normalize: If true applies image normalize - - Specs: - - 10 classes (1 per digit) - - Each image is (1 x 32 x 32) """ super().__init__(*args, **kwargs) self.dims = (1, 28, 28) From d4fd61024887fdf839348ef1ebf0181db922e92a Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:52:49 -0400 Subject: [PATCH 17/24] docs --- pl_bolts/datamodules/cityscapes_datamodule.py | 2 +- pl_bolts/datamodules/fashion_mnist_datamodule.py | 9 +++++++++ pl_bolts/datamodules/mnist_datamodule.py | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pl_bolts/datamodules/cityscapes_datamodule.py b/pl_bolts/datamodules/cityscapes_datamodule.py index 62f0aff0b2..c9c2973949 100644 --- a/pl_bolts/datamodules/cityscapes_datamodule.py +++ b/pl_bolts/datamodules/cityscapes_datamodule.py @@ -23,7 +23,7 @@ def __init__( """ .. figure:: https://www.cityscapes-dataset.com/wordpress/wp-content/uploads/2015/07/muenster00-1024x510.png :width: 400 - :alt: MNIST + :alt: Cityscape Standard Cityscapes, train, val, test splits and transforms diff --git a/pl_bolts/datamodules/fashion_mnist_datamodule.py b/pl_bolts/datamodules/fashion_mnist_datamodule.py index 2e97bde6b9..4aedde7f84 100644 --- a/pl_bolts/datamodules/fashion_mnist_datamodule.py +++ b/pl_bolts/datamodules/fashion_mnist_datamodule.py @@ -19,6 +19,15 @@ def __init__( **kwargs, ): """ + .. figure:: https://3qeqpr26caki16dnhd19sv6by6v-wpengine.netdna-ssl.com/ + wp-content/uploads/2019/02/Plot-of-a-Subset-of-Images-from-the-Fashion-MNIST-Dataset.png + :width: 400 + :alt: Fashion MNIST + + Specs: + - 10 classes (1 per digit) + - Each image is (1 x 28 x 28) + Standard FashionMNIST, train, val, test splits and transforms Transforms:: diff --git a/pl_bolts/datamodules/mnist_datamodule.py b/pl_bolts/datamodules/mnist_datamodule.py index 12430d254f..0270d8d479 100644 --- a/pl_bolts/datamodules/mnist_datamodule.py +++ b/pl_bolts/datamodules/mnist_datamodule.py @@ -26,7 +26,7 @@ def __init__( Specs: - 10 classes (1 per digit) - - Each image is (1 x 32 x 32) + - Each image is (1 x 28 x 28) Standard MNIST, train, val, test splits and transforms From 211efb945be762da672aca5cbf0628f87d6d5cc9 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:55:00 -0400 Subject: [PATCH 18/24] docs --- pl_bolts/datamodules/fashion_mnist_datamodule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pl_bolts/datamodules/fashion_mnist_datamodule.py b/pl_bolts/datamodules/fashion_mnist_datamodule.py index 4aedde7f84..933a4af4b9 100644 --- a/pl_bolts/datamodules/fashion_mnist_datamodule.py +++ b/pl_bolts/datamodules/fashion_mnist_datamodule.py @@ -25,7 +25,7 @@ def __init__( :alt: Fashion MNIST Specs: - - 10 classes (1 per digit) + - 10 classes (1 per type) - Each image is (1 x 28 x 28) Standard FashionMNIST, train, val, test splits and transforms From e180f2ad2e7b949dcb76725f3f5d8f10b61a2dc8 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:56:15 -0400 Subject: [PATCH 19/24] docs --- pl_bolts/datamodules/cifar10_datamodule.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pl_bolts/datamodules/cifar10_datamodule.py b/pl_bolts/datamodules/cifar10_datamodule.py index 1f2db4399b..1367c1c774 100644 --- a/pl_bolts/datamodules/cifar10_datamodule.py +++ b/pl_bolts/datamodules/cifar10_datamodule.py @@ -26,6 +26,15 @@ def __init__( **kwargs, ): """ + .. figure:: https://3qeqpr26caki16dnhd19sv6by6v-wpengine.netdna-ssl.com/wp-content/uploads/2019/01/ + Plot-of-a-Subset-of-Images-from-the-CIFAR-10-Dataset.png + :width: 400 + :alt: CIFAR-10 + + Specs: + - 10 classes (1 per class) + - Each image is (3 x 32 x 32) + Standard CIFAR10, train, val, test splits and transforms Transforms:: From c53a15d7b43f03e9c96257ddfa8d539a68ca6ee4 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 17:59:00 -0400 Subject: [PATCH 20/24] docs --- pl_bolts/datamodules/imagenet_datamodule.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pl_bolts/datamodules/imagenet_datamodule.py b/pl_bolts/datamodules/imagenet_datamodule.py index 248a54f39f..02af3763ab 100644 --- a/pl_bolts/datamodules/imagenet_datamodule.py +++ b/pl_bolts/datamodules/imagenet_datamodule.py @@ -24,6 +24,15 @@ def __init__( **kwargs, ): """ + .. figure:: https://3qeqpr26caki16dnhd19sv6by6v-wpengine.netdna-ssl.com/wp-content/uploads/2017/08/ + Sample-of-Images-from-the-ImageNet-Dataset-used-in-the-ILSVRC-Challenge.png + :width: 400 + :alt: Imagenet + + Specs: + - 1000 classes + - Each image is (3 x varies x varies) (here we default to 3 x 224 x 224) + Imagenet train, val and test dataloaders. The train set is the imagenet train. From 324dbea1629082c1453d0fe7af0ab6acb9c91f4e Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 18:01:46 -0400 Subject: [PATCH 21/24] docs --- pl_bolts/datamodules/stl10_datamodule.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pl_bolts/datamodules/stl10_datamodule.py b/pl_bolts/datamodules/stl10_datamodule.py index 17b3dc4626..11e2a9478a 100644 --- a/pl_bolts/datamodules/stl10_datamodule.py +++ b/pl_bolts/datamodules/stl10_datamodule.py @@ -24,6 +24,14 @@ def __init__( **kwargs, ): """ + .. figure:: https://samyzaf.com/ML/cifar10/cifar1.jpg + :width: 400 + :alt: STL-10 + + Specs: + - 10 classes (1 per type) + - Each image is (3 x 96 x 96) + Standard STL-10, train, val, test splits and transforms. STL-10 has support for doing validation splits on the labeled or unlabeled splits From 7b19bd951f9ee7540493841a8010d18dc921ef99 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 18:03:37 -0400 Subject: [PATCH 22/24] docs --- pl_bolts/datamodules/cifar10_datamodule.py | 4 +++- pl_bolts/datamodules/cityscapes_datamodule.py | 4 +++- pl_bolts/datamodules/fashion_mnist_datamodule.py | 4 +++- pl_bolts/datamodules/imagenet_datamodule.py | 5 ++++- pl_bolts/datamodules/stl10_datamodule.py | 4 +++- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pl_bolts/datamodules/cifar10_datamodule.py b/pl_bolts/datamodules/cifar10_datamodule.py index 1367c1c774..f24ea1f9e3 100644 --- a/pl_bolts/datamodules/cifar10_datamodule.py +++ b/pl_bolts/datamodules/cifar10_datamodule.py @@ -52,7 +52,9 @@ def __init__( from pl_bolts.datamodules import CIFAR10DataModule dm = CIFAR10DataModule(PATH) - model = LitModel(datamodule=dm) + model = LitModel() + + Trainer().fit(model, dm) Or you can set your own transforms diff --git a/pl_bolts/datamodules/cityscapes_datamodule.py b/pl_bolts/datamodules/cityscapes_datamodule.py index c9c2973949..731db055d1 100644 --- a/pl_bolts/datamodules/cityscapes_datamodule.py +++ b/pl_bolts/datamodules/cityscapes_datamodule.py @@ -46,7 +46,9 @@ def __init__( from pl_bolts.datamodules import CityscapesDataModule dm = CityscapesDataModule(PATH) - model = LitModel(datamodule=dm) + model = LitModel() + + Trainer().fit(model, dm) Or you can set your own transforms diff --git a/pl_bolts/datamodules/fashion_mnist_datamodule.py b/pl_bolts/datamodules/fashion_mnist_datamodule.py index 933a4af4b9..3e81ebdbf4 100644 --- a/pl_bolts/datamodules/fashion_mnist_datamodule.py +++ b/pl_bolts/datamodules/fashion_mnist_datamodule.py @@ -41,7 +41,9 @@ def __init__( from pl_bolts.datamodules import FashionMNISTDataModule dm = FashionMNISTDataModule('.') - model = LitModel(datamodule=dm) + model = LitModel() + + Trainer().fit(model, dm) Args: data_dir: where to save/load the data diff --git a/pl_bolts/datamodules/imagenet_datamodule.py b/pl_bolts/datamodules/imagenet_datamodule.py index 02af3763ab..6daca3d6a8 100644 --- a/pl_bolts/datamodules/imagenet_datamodule.py +++ b/pl_bolts/datamodules/imagenet_datamodule.py @@ -46,7 +46,10 @@ def __init__( from pl_bolts.datamodules import ImagenetDataModule - datamodule = ImagenetDataModule(IMAGENET_PATH) + dm = ImagenetDataModule(IMAGENET_PATH) + model = LitModel() + + Trainer().fit(model, dm) Args: diff --git a/pl_bolts/datamodules/stl10_datamodule.py b/pl_bolts/datamodules/stl10_datamodule.py index 11e2a9478a..4e1961d627 100644 --- a/pl_bolts/datamodules/stl10_datamodule.py +++ b/pl_bolts/datamodules/stl10_datamodule.py @@ -50,7 +50,9 @@ def __init__( from pl_bolts.datamodules import STL10DataModule dm = STL10DataModule(PATH) - model = LitModel(datamodule=dm) + model = LitModel() + + Trainer().fit(model, dm) Args: data_dir: where to save/load the data From 2c9f5f918c18677ccbe5aa5cdfc3271318ddf19f Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 18:04:06 -0400 Subject: [PATCH 23/24] docs --- pl_bolts/datamodules/mnist_datamodule.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pl_bolts/datamodules/mnist_datamodule.py b/pl_bolts/datamodules/mnist_datamodule.py index 0270d8d479..2adc03fc11 100644 --- a/pl_bolts/datamodules/mnist_datamodule.py +++ b/pl_bolts/datamodules/mnist_datamodule.py @@ -41,7 +41,9 @@ def __init__( from pl_bolts.datamodules import MNISTDataModule dm = MNISTDataModule('.') - model = LitModel(datamodule=dm) + model = LitModel() + + Trainer().fit(model, dm) Args: data_dir: where to save/load the data From b32b917e95cce814eeae9fe73599f34c5cb03ad5 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 5 Aug 2020 18:10:39 -0400 Subject: [PATCH 24/24] docs --- docs/source/self_supervised_callbacks.rst | 2 +- pl_bolts/models/self_supervised/byol/byol_module.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/self_supervised_callbacks.rst b/docs/source/self_supervised_callbacks.rst index 8f9083f4f1..2739a5aa09 100644 --- a/docs/source/self_supervised_callbacks.rst +++ b/docs/source/self_supervised_callbacks.rst @@ -9,7 +9,7 @@ Useful callbacks for self-supervised learning models BYOLMAWeightUpdate ------------------ -The exponential moving average weight-update rule from Bring Your Own Latent Space (BYOL). +The exponential moving average weight-update rule from Bring Your Own Latent (BYOL). .. autoclass:: pl_bolts.callbacks.self_supervised.BYOLMAWeightUpdate :noindex: diff --git a/pl_bolts/models/self_supervised/byol/byol_module.py b/pl_bolts/models/self_supervised/byol/byol_module.py index 45055f2a04..a918780e61 100644 --- a/pl_bolts/models/self_supervised/byol/byol_module.py +++ b/pl_bolts/models/self_supervised/byol/byol_module.py @@ -27,7 +27,7 @@ def __init__(self, loss_temperature: float = 0.5, **kwargs): """ - PyTorch Lightning implementation of `Bring Your Own Latent Space (BYOL) + PyTorch Lightning implementation of `Bring Your Own Latent (BYOL) `_ Paper authors: Jean-Bastien Grill ,Florian Strub, Florent Altché, Corentin Tallec, Pierre H. Richemond, \