-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revision of dataset normalizations (#898)
- Loading branch information
1 parent
a8bbfc9
commit 7f8ede8
Showing
2 changed files
with
42 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pytest | ||
import torch | ||
from pytorch_lightning import seed_everything | ||
|
||
from pl_bolts.transforms.dataset_normalizations import ( | ||
cifar10_normalization, | ||
emnist_normalization, | ||
imagenet_normalization, | ||
stl10_normalization, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"normalization", | ||
[cifar10_normalization, imagenet_normalization, stl10_normalization], | ||
) | ||
def test_normalizations(normalization, catch_warnings): | ||
"""Test normalizations for CIFAR10, ImageNet, STL10.""" | ||
seed_everything(1234) | ||
x = torch.rand(3, 32, 32) | ||
assert normalization()(x).shape == (3, 32, 32) | ||
assert x.min() >= 0.0 | ||
assert x.max() <= 1.0 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"split", | ||
["balanced", "byclass", "bymerge", "digits", "letters", "mnist"], | ||
) | ||
def test_emnist_normalizations(split, catch_warnings): | ||
"""Test normalizations for each EMNIST dataset split.""" | ||
x = torch.rand(1, 28, 28) | ||
assert emnist_normalization(split)(x).shape == (1, 28, 28) | ||
assert x.min() >= 0.0 | ||
assert x.max() <= 1.0 |