-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathtest_test_utils.py
85 lines (75 loc) · 4.21 KB
/
test_test_utils.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
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import unittest
from tests.test_utils import dict_product
class TestTestUtils(unittest.TestCase):
def setUp(self):
test_case_patchembeddingblock = []
for dropout_rate in (0.5,):
for in_channels in [1, 4]:
for hidden_size in [96, 288]:
for img_size in [32, 64]:
for patch_size in [8, 16]:
for num_heads in [8, 12]:
for proj_type in ["conv", "perceptron"]:
for pos_embed_type in ["none", "learnable", "sincos"]:
# for classification in (False, True): # TODO: add classification tests
for nd in (2, 3):
test_case = [
{
"in_channels": in_channels,
"img_size": (img_size,) * nd,
"patch_size": (patch_size,) * nd,
"hidden_size": hidden_size,
"num_heads": num_heads,
"proj_type": proj_type,
"pos_embed_type": pos_embed_type,
"dropout_rate": dropout_rate,
"spatial_dims": nd,
},
(2, in_channels, *([img_size] * nd)),
(2, (img_size // patch_size) ** nd, hidden_size),
]
test_case_patchembeddingblock.append(test_case)
self.test_case_patchembeddingblock = test_case_patchembeddingblock
def test_case_patchembeddingblock(self):
test_case_patchembeddingblock = dict_product(
dropout_rate=[0.5],
in_channels=[1, 4],
hidden_size=[96, 288],
img_size=[32, 64],
patch_size=[8, 16],
num_heads=[8, 12],
proj_type=["conv", "perceptron"],
pos_embed_type=["none", "learnable", "sincos"],
nd=[2, 3],
)
test_case_patchembeddingblock = [
[
params,
(2, params["in_channels"], *([params["img_size"]] * params["nd"])),
(2, (params["img_size"] // params["patch_size"]) ** params["nd"], params["hidden_size"]),
]
for params in test_case_patchembeddingblock
]
self.assertIsInstance(test_case_patchembeddingblock, list)
self.assertGreater(len(test_case_patchembeddingblock), 0)
self.assertEqual(len(test_case_patchembeddingblock), len(self.test_case_patchembeddingblock))
self.assertEqual(len(test_case_patchembeddingblock[0]), len(self.test_case_patchembeddingblock[0]))
self.assertEqual(len(test_case_patchembeddingblock[0][0]), len(self.test_case_patchembeddingblock[0][0]))
self.assertEqual(
test_case_patchembeddingblock[0][0]["in_channels"], self.test_case_patchembeddingblock[0][0]["in_channels"]
)
self.assertEqual(test_case_patchembeddingblock[0][1], self.test_case_patchembeddingblock[0][1])
self.assertEqual(test_case_patchembeddingblock[0][2], self.test_case_patchembeddingblock[0][2])
if __name__ == "__main__":
unittest.main()