-
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.
Merge branch 'johan/devbranch' of github.com:SFI-Visual-Intelligence/…
…Collaborative-Coding-Exam into johan/devbranch
- Loading branch information
Showing
12 changed files
with
195 additions
and
147 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,29 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- uses: mamba-org/setup-micromamba@v1 | ||
with: | ||
micromamba-version: '2.0.5-0' # any version from https://github.com/mamba-org/micromamba-releases | ||
environment-file: environment.yml | ||
init-shell: bash | ||
cache-environment: true | ||
post-cleanup: 'all' | ||
generate-run-shell: false | ||
|
||
- name: Run tests | ||
run: | | ||
PYTHONPATH=. pytest tests | ||
shell: bash -el {0} |
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,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,20 @@ | ||
from utils.dataloaders.usps_0_6 import USPSDataset0_6 | ||
|
||
|
||
def test_uspsdataset0_6(): | ||
from pathlib import Path | ||
from tempfile import TemporaryFile | ||
|
||
import h5py | ||
import numpy as np | ||
|
||
with TemporaryFile() as tf: | ||
with h5py.File(tf, "w") as f: | ||
f["train/data"] = np.random.rand(10, 16 * 16) | ||
f["train/target"] = np.array([6, 5, 4, 3, 2, 1, 0, 0, 0, 0]) | ||
|
||
dataset = USPSDataset0_6(data_path=tf, train=True) | ||
assert len(dataset) == 10 | ||
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
Oops, something went wrong.