|
1 | 1 | from utils import load_data, load_metric, load_model |
2 | 2 |
|
| 3 | +# def test_load_model(): |
| 4 | +# import torch as th |
3 | 5 |
|
4 | | -def test_load_model(): |
5 | | - import torch as th |
| 6 | +# image_shape = (1, 16, 16) |
| 7 | +# num_classes = 4 |
6 | 8 |
|
7 | | - image_shape = (1, 28, 28) |
8 | | - num_classes = 4 |
| 9 | +# dummy_img = th.rand((1, *image_shape)) |
9 | 10 |
|
10 | | - dummy_img = th.rand((1, *image_shape)) |
| 11 | +# modelnames = [ |
| 12 | +# "magnusmodel", |
| 13 | +# "christianmodel", |
| 14 | +# "janmodel", |
| 15 | +# "solveigmodel", |
| 16 | +# "johanmodel", |
| 17 | +# ] |
11 | 18 |
|
12 | | - modelnames = [ |
13 | | - "magnusmodel", |
14 | | - "christianmodel", |
15 | | - "janmodel", |
16 | | - "solveigmodel", |
17 | | - "johanmodel", |
18 | | - ] |
| 19 | +# for name in modelnames: |
| 20 | +# print(name) |
| 21 | +# model = load_model(name, image_shape=image_shape, num_classes=num_classes) |
19 | 22 |
|
20 | | - for name in modelnames: |
21 | | - model = load_model(name, image_shape=image_shape, num_classes=num_classes) |
| 23 | +# with th.no_grad(): |
| 24 | +# output = model(dummy_img) |
| 25 | +# assert output.size() == (1, 4), ( |
| 26 | +# f"Model {name} returned image of size {output}. Expected (1,4)" |
| 27 | +# ) |
22 | 28 |
|
23 | | - with th.no_grad(): |
24 | | - output = model(dummy_img) |
25 | | - assert output.size() == (1, 4), ( |
26 | | - f"Model {name} returned image of size {output}. Expected (1,4)" |
27 | | - ) |
28 | 29 |
|
| 30 | +def test_load_data(): |
| 31 | + from tempfile import TemporaryDirectory |
29 | 32 |
|
30 | | -# def test_load_data(): |
31 | | -# from tempfile import TemporaryDirectory |
| 33 | + import torch as th |
| 34 | + from torchvision import transforms |
| 35 | + |
| 36 | + dataset_names = [ |
| 37 | + "usps_0-6", |
| 38 | + "mnist_0-3", |
| 39 | + "usps_7-9", |
| 40 | + "svhn", |
| 41 | + # 'mnist_4-9' #Uncomment when implemented |
| 42 | + ] |
32 | 43 |
|
33 | | -# import torch as th |
34 | | -# from torchvision import transforms |
35 | | - |
36 | | -# dataset_names = [ |
37 | | -# "usps_0-6", |
38 | | -# "mnist_0-3", |
39 | | -# "usps_7-9", |
40 | | -# "svhn", |
41 | | -# # 'mnist_4-9' #Uncomment when implemented |
42 | | -# ] |
| 44 | + trans = transforms.Compose( |
| 45 | + [ |
| 46 | + transforms.Resize((16, 16)), |
| 47 | + transforms.ToTensor(), |
| 48 | + ] |
| 49 | + ) |
| 50 | + |
| 51 | + with TemporaryDirectory() as tmppath: |
| 52 | + for name in dataset_names: |
| 53 | + dataset = load_data( |
| 54 | + name, train=False, data_path=tmppath, download=True, transform=trans |
| 55 | + ) |
43 | 56 |
|
44 | | -# trans = transforms.Compose( |
45 | | -# [ |
46 | | -# transforms.Resize((16, 16)), |
47 | | -# transforms.ToTensor(), |
48 | | -# ] |
49 | | -# ) |
50 | | - |
51 | | -# with TemporaryDirectory() as tmppath: |
52 | | -# for name in dataset_names: |
53 | | -# dataset = load_data( |
54 | | -# name, train=False, data_path=tmppath, download=True, transform=trans |
55 | | -# ) |
| 57 | + im, _ = dataset.__getitem__(0) |
56 | 58 |
|
57 | | -# im, lab = dataset.__getitem__(0) |
| 59 | + assert dataset.__len__() != 0 |
| 60 | + assert type(im) == th.Tensor and len(im.size()) == 3 |
58 | 61 |
|
59 | | -# assert dataset.__len__() != 0 |
60 | | -# assert type(im) == th.Tensor and len(im.size()) == 3 |
61 | | -# assert lab - lab == 0.0 |
62 | 62 |
|
63 | | -# def test_load_metric(): |
64 | | -# pass |
| 63 | +def test_load_metric(): |
| 64 | + pass |
0 commit comments