(self)
| 98 | |
| 99 | class 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]: |
nothing calls this directly
no test coverage detected