Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
BaruchG committed Sep 16, 2022
2 parents 36d57f8 + 2a1f134 commit 88eb870
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 155 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Check Schema

on:
push:
branches: [master, "release/*"]
pull_request:
branches: [master, "release/*"]

jobs:
validate-schema:
uses: Lightning-AI/utilities/.github/workflows/[email protected]
with:
azure-dir: ''
24 changes: 0 additions & 24 deletions .github/workflows/ci_schema.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci_test-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
python -m pytest pl_bolts -v --cov=pl_bolts --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml --ignore=pl_bolts/datamodules --ignore=pl_bolts/datasets --ignore=pl_bolts/models/self_supervised/amdim/transforms.py --ignore=pl_bolts/models/rl
- name: Upload pytest test results
uses: actions/upload-artifact@master
uses: actions/upload-artifact@v3
with:
name: pytest-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}
path: junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_test-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
python -m pytest pl_bolts tests -v --cov=pl_bolts --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml
- name: Upload pytest test results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: pytest-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}
path: junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
make html --debug --jobs 2 SPHINXOPTS="-W"
- name: Upload built docs
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: docs-results-${{ github.sha }}
path: docs/build/html/
Expand Down
57 changes: 24 additions & 33 deletions pl_bolts/datamodules/emnist_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pl_bolts.datamodules.vision_datamodule import VisionDataModule
from pl_bolts.transforms.dataset_normalizations import emnist_normalization
from pl_bolts.utils import _TORCHVISION_AVAILABLE
from pl_bolts.utils.stability import under_review
from pl_bolts.utils.warnings import warn_missing_pkg

if _TORCHVISION_AVAILABLE:
Expand All @@ -14,7 +13,6 @@
EMNIST = object


@under_review()
class EMNISTDataModule(VisionDataModule):
"""
.. figure:: https://user-images.githubusercontent.com/4632336/123210742-4d6b3380-d477-11eb-80da-3e9a74a18a07.png
Expand Down Expand Up @@ -76,6 +74,23 @@ class EMNISTDataModule(VisionDataModule):
|
Args:
data_dir: Root directory of dataset.
split: The dataset has 6 different splits: ``byclass``, ``bymerge``,
``balanced``, ``letters``, ``digits`` and ``mnist``.
This argument is passed to :class:`torchvision.datasets.EMNIST`.
val_split: Percent (float) or number (int) of samples to use for the validation split.
num_workers: How many workers to use for loading data
normalize: If ``True``, applies image normalize.
batch_size: How many samples per batch to load.
seed: Random seed to be used for train/val/test splits.
shuffle: If ``True``, shuffles the train data every epoch.
pin_memory: If ``True``, the data loader will copy Tensors into
CUDA pinned memory before returning them.
drop_last: If ``True``, drops the last incomplete batch.
strict_val_split: If ``True``, uses the validation split defined in the paper and ignores ``val_split``.
Note that it only works with ``"balanced"``, ``"digits"``, ``"letters"``, ``"mnist"`` splits.
Here is the default EMNIST, train, val, test-splits and transforms.
Transforms::
Expand All @@ -87,8 +102,10 @@ class EMNISTDataModule(VisionDataModule):
Example::
from pl_bolts.datamodules import EMNISTDataModule
dm = EMNISTDataModule('.')
model = LitModel()
Trainer().fit(model, datamodule=dm)
"""

Expand Down Expand Up @@ -119,25 +136,6 @@ def __init__(
*args: Any,
**kwargs: Any,
) -> None:
"""
Args:
data_dir: Where to save/load the data.
split: The dataset has 6 different splits: ``byclass``, ``bymerge``,
``balanced``, ``letters``, ``digits`` and ``mnist``.
This argument is passed to :class:`torchvision.datasets.EMNIST`.
val_split: Percent (float) or number (int) of samples
to use for the validation split.
num_workers: How many workers to use for loading data
normalize: If ``True``, applies image normalize.
batch_size: How many samples per batch to load.
seed: Random seed to be used for train/val/test splits.
shuffle: If ``True``, shuffles the train data every epoch.
pin_memory: If ``True``, the data loader will copy Tensors into
CUDA pinned memory before returning them.
drop_last: If ``True``, drops the last incomplete batch.
strict_val_split: If ``True``, uses the validation split defined in the paper and ignores ``val_split``.
Note that it only works with ``"balanced"``, ``"digits"``, ``"letters"``, ``"mnist"`` splits.
"""
if not _TORCHVISION_AVAILABLE: # pragma: no cover
raise ModuleNotFoundError(
"You want to use MNIST dataset loaded from `torchvision` which is not installed yet."
Expand Down Expand Up @@ -183,13 +181,11 @@ def num_classes(self) -> int:

def prepare_data(self, *args: Any, **kwargs: Any) -> None:
"""Saves files to ``data_dir``."""

self.dataset_cls(self.data_dir, split=self.split, train=True, download=True)
self.dataset_cls(self.data_dir, split=self.split, train=False, download=True)

def setup(self, stage: Optional[str] = None) -> None:
"""Creates train, val, and test dataset."""

if stage == "fit" or stage is None:
train_transforms = self.default_transforms() if self.train_transforms is None else self.train_transforms
val_transforms = self.default_transforms() if self.val_transforms is None else self.val_transforms
Expand All @@ -212,14 +208,9 @@ def setup(self, stage: Optional[str] = None) -> None:
)

def default_transforms(self) -> Callable:
if self.normalize:
emnist_transforms = transform_lib.Compose([transform_lib.ToTensor(), emnist_normalization(self.split)])
else:
emnist_transforms = transform_lib.Compose([transform_lib.ToTensor()])

return (
transform_lib.Compose(
[
transform_lib.ToTensor(),
emnist_normalization(self.split),
]
)
if self.normalize
else transform_lib.Compose([transform_lib.ToTensor()])
)
return emnist_transforms
32 changes: 13 additions & 19 deletions pl_bolts/datamodules/fashion_mnist_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from pl_bolts.datamodules.vision_datamodule import VisionDataModule
from pl_bolts.utils import _TORCHVISION_AVAILABLE
from pl_bolts.utils.stability import under_review
from pl_bolts.utils.warnings import warn_missing_pkg

if _TORCHVISION_AVAILABLE:
Expand All @@ -13,14 +12,25 @@
FashionMNIST = None


@under_review()
class FashionMNISTDataModule(VisionDataModule):
"""
.. 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
Args:
data_dir: Root directory of dataset.
val_split: Percent (float) or number (int) of samples to use for the validation split.
num_workers: Number of workers to use for loading data.
normalize: If ``True``, applies image normalization.
batch_size: Number of samples per batch to load.
seed: Random seed to be used for train/val/test splits.
shuffle: If ``True``, shuffles the train data every epoch.
pin_memory: If ``True``, the data loader will copy Tensors into CUDA pinned memory before
returning them.
drop_last: If ``True``, drops the last incomplete batch.
Specs:
- 10 classes (1 per type)
- Each image is (1 x 28 x 28)
Expand Down Expand Up @@ -61,19 +71,6 @@ def __init__(
*args: Any,
**kwargs: Any,
) -> None:
"""
Args:
data_dir: Where to save/load the data
val_split: Percent (float) or number (int) of samples to use for the validation split
num_workers: How many workers to use for loading data
normalize: If true applies image normalize
batch_size: How many samples per batch to load
seed: Random seed to be used for train/val/test splits
shuffle: If true shuffles the train data every epoch
pin_memory: If true, the data loader will copy Tensors into CUDA pinned memory before
returning them
drop_last: If true drops the last incomplete batch
"""
if not _TORCHVISION_AVAILABLE: # pragma: no cover
raise ModuleNotFoundError(
"You want to use FashionMNIST dataset loaded from `torchvision` which is not installed yet."
Expand All @@ -95,10 +92,7 @@ def __init__(

@property
def num_classes(self) -> int:
"""
Return:
10
"""
"""Returns the number of classes."""
return 10

def default_transforms(self) -> Callable:
Expand Down
Loading

0 comments on commit 88eb870

Please sign in to comment.