(self)
| 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 | |
| 138 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected