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

Method test_cutoutd

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

Source from the content-addressed store, hash-verified

116 self.assertEqual(output.shape, sample.shape)
117
118 def test_cutoutd(self):
119 for dims in [2, 3]:
120 shape = (6, 3) + (32,) * dims
121 t = torch.rand(*shape, dtype=torch.float32)
122 sample = {"a": t, "b": t}
123 cutout = CutOutd(["a", "b"], 6, 1.0)
124 cutout.set_random_state(seed=123)
125 output = cutout(sample)
126 np.random.seed(123)
127 # simulate the randomize() of transform
128 np.random.random()
129 weight = torch.from_numpy(np.random.beta(1.0, 1.0, 6)).type(torch.float32)
130 perm = np.random.permutation(6)
131 coords = [torch.from_numpy(np.random.randint(0, d, size=(1,))) for d in t.shape[2:]]
132 assert_allclose(weight, cutout.cutout._params[0])
133 assert_allclose(perm, cutout.cutout._params[1])
134 self.assertSequenceEqual(coords, cutout.cutout._params[2])
135 self.assertEqual(output["a"].shape, sample["a"].shape)
136
137
138if __name__ == "__main__":

Callers

nothing calls this directly

Calls 3

set_random_stateMethod · 0.95
CutOutdClass · 0.90
assert_allcloseFunction · 0.90

Tested by

no test coverage detected