Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CollaborativeCoding/load_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def resetmetric(self):
y_pred = th.rand((5, class_size))

metricwrapper = MetricWrapper(
metric,
*metrics,
num_classes=class_size,
macro_averaging=True if class_size % 2 == 0 else False,
)
Expand Down
26 changes: 7 additions & 19 deletions tests/test_wrappers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
from pathlib import Path
from tempfile import TemporaryDirectory

import pytest
import torch
from torchvision import transforms
import torch as th

from CollaborativeCoding import MetricWrapper, load_data, load_model


def test_load_model():
import torch as th

image_shape = (1, 16, 16)
num_classes = 4

Expand All @@ -36,17 +32,14 @@ def test_load_model():


def test_load_data():
from tempfile import TemporaryDirectory

import torch as th
from torchvision import transforms

dataset_names = [
"usps_0-6",
"mnist_0-3",
"usps_7-9",
"svhn",
"mnist_4-9", # Uncomment when implemented
"mnist_4-9",
]

trans = transforms.Compose(
Expand All @@ -56,21 +49,16 @@ def test_load_data():
]
)

with TemporaryDirectory() as tmppath:
for name in dataset_names:
dataset, _, _ = load_data(
name, train=False, data_dir=Path(tmppath), transform=trans
)
for name in dataset_names:
dataset = load_data(name, train=False, data_dir=Path.cwd() / "Data", transform=trans)

im, _ = dataset.__getitem__(0)
im, _ = dataset.__getitem__(0)

assert dataset.__len__() != 0
assert type(im) == th.Tensor and len(im.size()) == 3
assert dataset.__len__() != 0
assert type(im) is th.Tensor and len(im.size()) == 3


def test_load_metric():
import torch as th

metrics = ("entropy", "f1", "recall", "precision", "accuracy")

class_sizes = [3, 6, 10]
Expand Down
Loading