def test_prob_k_spatial_axes(self): rotate = Rotate90(k=2, spatial_axes=(0, 1)) rotated = rotate(self.imt[0]) expected = [] for channel in self.imt[0]: expected.append(np.rot90(channel, 2, (0, 1))) expected = np.stack(expected) self.assertTrue(np.allclose(rotated, expected))
def test_rotate90_default(self): rotate = Rotate90() rotated = rotate(self.imt[0]) expected = [] for channel in self.imt[0]: expected.append(np.rot90(channel, 1, (0, 1))) expected = np.stack(expected) self.assertTrue(np.allclose(rotated, expected))
def test_k(self): rotate = Rotate90(k=2) rotated = rotate(self.imt[0]) expected = list() for channel in self.imt[0]: expected.append(np.rot90(channel, 2, (0, 1))) expected = np.stack(expected) self.assertTrue(np.allclose(rotated, expected))
def test_prob_k_spatial_axes(self): rotate = Rotate90(k=2, spatial_axes=(0, 1)) for p in TEST_NDARRAYS: rotated = rotate(p(self.imt[0])) expected = [ np.rot90(channel, 2, (0, 1)) for channel in self.imt[0] ] expected = np.stack(expected) assert_allclose(rotated, p(expected), rtol=1.0e-5, atol=1.0e-8)
def test_rotate90_default(self): rotate = Rotate90() for p in TEST_NDARRAYS: rotated = rotate(p(self.imt[0])) expected = [ np.rot90(channel, 1, (0, 1)) for channel in self.imt[0] ] expected = np.stack(expected) assert_allclose(rotated, p(expected), rtol=1.0e-5, atol=1.0e-8)
def test_rotate90_default(self): rotate = Rotate90() for p in TEST_NDARRAYS_ALL: im = p(self.imt[0]) rotated = rotate(im) test_local_inversion(rotate, rotated, im) expected = [ np.rot90(channel, 1, (0, 1)) for channel in self.imt[0] ] expected = np.stack(expected) assert_allclose(rotated, p(expected), rtol=1.0e-5, atol=1.0e-8, type_test="tensor")
def test_tranform_randomized(self, input): # Compose deterministic and randomized transforms transforms = Compose([ Range("flip")(Flip()), Rotate90(), Range()(RandAdjustContrast(prob=0.0)), Range("random flip")(RandFlip(prob=1.0)), ToTensor(), ]) # Apply transforms output = transforms(input) # Decorate with NVTX Range transforms1 = Range()(transforms) transforms2 = Range("Transforms2")(transforms) transforms3 = Range(name="Transforms3", methods="__call__")(transforms) # Apply transforms with Range output1 = transforms1(input) output2 = transforms2(input) output3 = transforms3(input) # Check if the outputs are equal self.assertIsInstance(output, torch.Tensor) self.assertIsInstance(output1, torch.Tensor) self.assertIsInstance(output2, torch.Tensor) self.assertIsInstance(output3, torch.Tensor) np.testing.assert_equal(output.numpy(), output1.numpy()) np.testing.assert_equal(output.numpy(), output2.numpy()) np.testing.assert_equal(output.numpy(), output3.numpy()) # Check if the first randomized is RandAdjustContrast for tran in transforms.transforms: if isinstance(tran, Randomizable): self.assertIsInstance(tran, RandAdjustContrast) break