-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Improve tests
- Loading branch information
Showing
4 changed files
with
65 additions
and
12 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,13 @@ | ||
# fmt: off | ||
from torch_uncertainty.models.mlp import bayesian_mlp, packed_mlp | ||
|
||
|
||
# fmt: on | ||
class TestMLPModel: | ||
"""Testing the mlp models.""" | ||
|
||
def test_packed(self): | ||
packed_mlp(1, 1, hidden_dims=[]) | ||
|
||
def test_bayesian(self): | ||
bayesian_mlp(1, 1, hidden_dims=[1, 1, 1]) |
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,20 +1,38 @@ | ||
import torch | ||
|
||
from torch_uncertainty.layers import BayesLinear | ||
from torch_uncertainty.layers import BayesConv2d, BayesLinear | ||
from torch_uncertainty.models.utils import StochasticModel | ||
|
||
|
||
@StochasticModel | ||
class DummyModel(torch.nn.Module): | ||
class DummyModelLinear(torch.nn.Module): | ||
def __init__(self, *args, **kwargs) -> None: | ||
super().__init__(*args, **kwargs) | ||
self.layer = BayesLinear(1, 10, 1) | ||
|
||
def forward(self, x): | ||
return self.layer(x) | ||
|
||
|
||
@StochasticModel | ||
class DummyModelConv(torch.nn.Module): | ||
def __init__(self, *args, **kwargs) -> None: | ||
super().__init__(*args, **kwargs) | ||
self.layer = BayesConv2d(1, 10, 1) | ||
|
||
def forward(self, x): | ||
return self.layer(x) | ||
|
||
|
||
class TestStochasticModel: | ||
"""Testing the ResNet std class.""" | ||
|
||
def test_main(self): | ||
model = DummyModel() | ||
def test_main_linear(self): | ||
model = DummyModelLinear() | ||
model.freeze() | ||
model.unfreeze() | ||
|
||
def test_main_conv(self): | ||
model = DummyModelConv() | ||
model.freeze() | ||
model.unfreeze() |
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