-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
106 additions
and
20 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
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.0.8' | ||
__version__ = '0.0.9' |
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 |
---|---|---|
|
@@ -19,5 +19,5 @@ | |
'tqdm', | ||
# 'nvidia-dali-cuda110 >= 1.7' | ||
], | ||
packages=find_packages() | ||
packages=find_packages(exclude=['tests']) | ||
) |
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,62 @@ | ||
from functools import partial | ||
import pytest | ||
import torch | ||
import torch.nn as nn | ||
from cvm.models.core import blocks | ||
|
||
|
||
def test_se_block_forward(): | ||
inputs = torch.randn(16, 3, 56, 56) | ||
|
||
se = blocks.SEBlock(3, 0.25) | ||
|
||
outputs = se(inputs) | ||
assert outputs.shape == inputs.shape | ||
assert isinstance(se.act, nn.ReLU) | ||
assert isinstance(se.gate, nn.Sigmoid) | ||
|
||
|
||
def test_se_block_decorator(): | ||
with blocks.se(inner_nonlinear=nn.SiLU, gating_fn=nn.Hardsigmoid): | ||
se = blocks.SEBlock(3, 0.25) | ||
|
||
assert isinstance(se.act, nn.SiLU) | ||
assert isinstance(se.gate, nn.Hardsigmoid) | ||
|
||
|
||
def test_normalizer_decorator(): | ||
with blocks.normalizer(None): | ||
layers = blocks.norm_activation(3) | ||
|
||
assert len(layers) == 1 | ||
assert isinstance(layers[0], nn.ReLU) | ||
|
||
with blocks.normalizer(nn.LayerNorm, position='before'): | ||
layers = blocks.norm_activation(3) | ||
|
||
assert len(layers) == 2 | ||
assert isinstance(layers[0], nn.LayerNorm) | ||
assert isinstance(layers[1], nn.ReLU) | ||
|
||
with blocks.normalizer(partial(nn.BatchNorm2d, eps=0.1), position='after'): | ||
layers = blocks.norm_activation(3) | ||
|
||
assert len(layers) == 2 | ||
assert isinstance(layers[0], nn.ReLU) | ||
assert isinstance(layers[1], nn.BatchNorm2d) | ||
assert layers[1].eps == 0.1 | ||
|
||
|
||
def test_nonlinear_decorator(): | ||
with blocks.nonlinear(None): | ||
layers = blocks.norm_activation(3) | ||
|
||
assert len(layers) == 1 | ||
assert isinstance(layers[0], nn.BatchNorm2d) | ||
|
||
with blocks.nonlinear(nn.SiLU): | ||
layers = blocks.norm_activation(3) | ||
|
||
assert len(layers) == 2 | ||
assert isinstance(layers[0], nn.BatchNorm2d) | ||
assert isinstance(layers[1], nn.SiLU) |
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,29 @@ | ||
import pytest | ||
import torch | ||
from cvm.models.core import SegmentationModel | ||
from cvm.utils import list_models, create_model | ||
|
||
|
||
@pytest.mark.parametrize('name', list_models('cvm')) | ||
def test_model_forward(name): | ||
model = create_model( | ||
name, | ||
dropout_rate=0., | ||
drop_path_rate=0., | ||
num_classes=10, | ||
cuda=False | ||
) | ||
|
||
model.eval() | ||
|
||
inputs = torch.randn((1, 3, 224, 224)) | ||
outputs = model(inputs) | ||
|
||
if name in ['unet', 'vae', 'dcgan']: | ||
... | ||
elif isinstance(model, SegmentationModel): | ||
assert outputs[0].shape == torch.Size([1, 10, 224, 224]) | ||
assert not torch.isnan(outputs[0]).any(), 'Output included NaNs' | ||
else: | ||
assert outputs.shape == torch.Size([1, 10]) | ||
assert not torch.isnan(outputs).any(), 'Output included NaNs' |