forked from royerlab/aydin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_torch_unet.py
89 lines (78 loc) · 2.62 KB
/
test_torch_unet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# flake8: noqa
import pytest
import torch
from aydin.nn.models.torch.torch_unet import UNetModel
def test_supervised_2D():
input_array = torch.zeros((1, 1, 64, 64))
model2d = UNetModel(
# (64, 64, 1),
nb_unet_levels=2,
supervised=True,
spacetime_ndim=2,
)
result = model2d(input_array)
assert result.shape == input_array.shape
assert result.dtype == input_array.dtype
@pytest.mark.parametrize("nb_unet_levels", [2, 3, 5, 8])
def test_masking_2D(nb_unet_levels):
input_array = torch.zeros((1, 1, 1024, 1024))
model2d = UNetModel(
# (64, 64, 1),
nb_unet_levels=nb_unet_levels,
supervised=False,
spacetime_ndim=2,
)
result = model2d(input_array, torch.ones(input_array.shape))
assert result.shape == input_array.shape
assert result.dtype == input_array.dtype
def test_supervised_3D():
input_array = torch.zeros((1, 1, 64, 64, 64))
model3d = UNetModel(
# (64, 64, 64, 1),
nb_unet_levels=2,
supervised=True,
spacetime_ndim=3,
)
result = model3d(input_array)
assert result.shape == input_array.shape
assert result.dtype == input_array.dtype
@pytest.mark.parametrize("nb_unet_levels", [2, 3, 5])
def test_masking_3D(nb_unet_levels):
input_array = torch.zeros((1, 1, 64, 64, 64))
model3d = UNetModel(
# (64, 64, 64, 1),
nb_unet_levels=nb_unet_levels,
supervised=False,
spacetime_ndim=3,
)
result = model3d(input_array, torch.ones(input_array.shape))
assert result.shape == input_array.shape
assert result.dtype == input_array.dtype
# def test_various_masking_3D():
# for i in [0, 4]:
# input_array = torch.zeros((1, 21 + i, 64, 64, 1))
# print(f'input shape: {input_array.shape}')
# model3d = UNetModel(
# input_array.shape[1:],
# nb_unet_levels=4,
# supervised=False,
# spacetime_ndim=3,
# )
# result = model3d.predict([input_array, input_array])
# assert result.shape == input_array.shape
# assert result.dtype == input_array.dtype
#
#
# def test_thin_masking_3D():
# for i in range(3):
# input_array = torch.zeros((1, 2 + i, 64, 64, 1))
# print(f'input shape: {input_array.shape}')
# model3d = UNetModel(
# input_array.shape[1:],
# nb_unet_levels=4,
# supervised=False,
# spacetime_ndim=3,
# )
# result = model3d.predict([input_array, input_array])
# assert result.shape == input_array.shape
# assert result.dtype == input_array.dtype