MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / test_cutout

Method test_cutout

tests/transforms/test_regularization.py:100–116  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

98
99class TestCutOut(unittest.TestCase):
100 def test_cutout(self):
101 for dims in [2, 3]:
102 shape = (6, 3) + (32,) * dims
103 sample = torch.rand(*shape, dtype=torch.float32)
104 cutout = CutOut(6, 1.0)
105 cutout.set_random_state(seed=123)
106 output = cutout(sample)
107 np.random.seed(123)
108 # simulate the randomize() of transform
109 np.random.random()
110 weight = torch.from_numpy(np.random.beta(1.0, 1.0, 6)).type(torch.float32)
111 perm = np.random.permutation(6)
112 coords = [torch.from_numpy(np.random.randint(0, d, size=(1,))) for d in sample.shape[2:]]
113 assert_allclose(weight, cutout._params[0])
114 assert_allclose(perm, cutout._params[1])
115 self.assertSequenceEqual(coords, cutout._params[2])
116 self.assertEqual(output.shape, sample.shape)
117
118 def test_cutoutd(self):
119 for dims in [2, 3]:

Callers

nothing calls this directly

Calls 3

CutOutClass · 0.90
assert_allcloseFunction · 0.90
set_random_stateMethod · 0.45

Tested by

no test coverage detected