-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
1254048
commit 6f08341
Showing
8 changed files
with
100 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from utils import createfolders | ||
|
||
|
||
def test_createfolders(): | ||
import argparse | ||
from pathlib import Path | ||
from tempfile import TemporaryDirectory | ||
|
||
with TemporaryDirectory() as temp_dir: | ||
temp_dir = Path(temp_dir) | ||
|
||
parser = argparse.ArgumentParser() | ||
|
||
# Structuture related values | ||
parser.add_argument( | ||
"--datafolder", | ||
type=Path, | ||
default=temp_dir / "Data", | ||
help="Path to where data will be saved during training.", | ||
) | ||
parser.add_argument( | ||
"--resultfolder", | ||
type=Path, | ||
default=temp_dir / "Results", | ||
help="Path to where results will be saved during evaluation.", | ||
) | ||
parser.add_argument( | ||
"--modelfolder", | ||
type=Path, | ||
default=temp_dir / "Experiments", | ||
help="Path to where model weights will be saved at the end of training.", | ||
) | ||
|
||
args = parser.parse_args( | ||
[ | ||
"--datafolder", | ||
str(temp_dir / "Data"), | ||
"--resultfolder", | ||
str(temp_dir / "Results"), | ||
"--modelfolder", | ||
str(temp_dir / "Experiments"), | ||
] | ||
) | ||
|
||
createfolders(args.datafolder, args.resultfolder, args.modelfolder) | ||
|
||
assert (temp_dir / "Data").exists() | ||
assert (temp_dir / "Results").exists() | ||
assert (temp_dir / "Experiments").exists() |
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,15 @@ | ||
from utils.dataloaders.usps_0_6 import USPSDataset0_6 | ||
|
||
|
||
def test_uspsdataset0_6(): | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
|
||
datapath = Path("data/USPS") | ||
|
||
dataset = USPSDataset0_6(data_path=datapath, train=True) | ||
assert len(dataset) == 5460 | ||
data, target = dataset[0] | ||
assert data.shape == (1, 16, 16) | ||
assert all(target == np.array([0, 0, 0, 0, 0, 0, 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from utils.metrics import Recall | ||
|
||
|
||
def test_recall(): | ||
import torch | ||
|
||
recall = Recall(7) | ||
|
||
y_true = torch.tensor([0, 1, 2, 3, 4, 5, 6]) | ||
y_pred = torch.tensor([2, 1, 2, 1, 4, 5, 6]) | ||
|
||
recall_score = recall(y_true, y_pred) | ||
|
||
assert recall_score.allclose(torch.tensor(0.7143), atol=1e-5), ( | ||
f"Recall Score: {recall_score.item()}" | ||
) |
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,19 @@ | ||
import pytest | ||
import torch | ||
|
||
from utils.models import ChristianModel | ||
|
||
|
||
@pytest.mark.parametrize("in_channels, num_classes", [(1, 6), (3, 6)]) | ||
def test_christian_model(in_channels, num_classes): | ||
n, c, h, w = 5, in_channels, 16, 16 | ||
|
||
model = ChristianModel(c, num_classes) | ||
|
||
x = torch.randn(n, c, h, w) | ||
y = model(x) | ||
|
||
assert y.shape == (n, num_classes), f"Shape: {y.shape}" | ||
assert y.sum(dim=1).allclose(torch.ones(n), atol=1e-5), ( | ||
f"Softmax output should sum to 1, but got: {y.sum()}" | ||
) |
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