コード例 #1
0
 def test_torch(self, init_param, img: torch.Tensor, track_meta: bool, device):
     set_track_meta(track_meta)
     img = img.to(device)
     xform = Flipd("image", init_param)
     res = xform({"image": img})
     self.assertEqual(img.shape, res["image"].shape)
     if track_meta:
         self.assertIsInstance(res["image"], MetaTensor)
     else:
         self.assertNotIsInstance(res["image"], MetaTensor)
         self.assertIsInstance(res["image"], torch.Tensor)
         with self.assertRaisesRegex(ValueError, "MetaTensor"):
             xform.inverse(res)
コード例 #2
0
 def test_correct_results(self, _, spatial_axis):
     for p in TEST_NDARRAYS:
         flip = Flipd(keys="img", spatial_axis=spatial_axis)
         expected = [np.flip(channel, spatial_axis) for channel in self.imt[0]]
         expected = np.stack(expected)
         result = flip({"img": p(self.imt[0])})["img"]
         assert_allclose(result, p(expected))
コード例 #3
0
ファイル: test_nvtx_decorator.py プロジェクト: Nic-Ma/MONAI
    def test_tranform_dict(self, input):
        transforms = Compose([
            Range("random flip dict")(Flipd(keys="image")),
            Range()(ToTensord("image"))
        ])
        # Apply transforms
        output = transforms(input)["image"]

        # 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)["image"]
        output2 = transforms2(input)["image"]
        output3 = transforms3(input)["image"]

        # Check the outputs
        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())
コード例 #4
0
 def test_correct_results(self, _, spatial_axis):
     flip = Flipd(keys="img", spatial_axis=spatial_axis)
     expected = list()
     for channel in self.imt[0]:
         expected.append(np.flip(channel, spatial_axis))
     expected = np.stack(expected)
     res = flip({"img": self.imt[0]})
     assert np.allclose(expected, res["img"])
コード例 #5
0
 def test_correct_results(self, _, spatial_axis):
     for p in TEST_NDARRAYS_ALL:
         flip = Flipd(keys="img", spatial_axis=spatial_axis)
         expected = [np.flip(channel, spatial_axis) for channel in self.imt[0]]
         expected = np.stack(expected)
         im = p(self.imt[0])
         result = flip({"img": im})["img"]
         assert_allclose(result, p(expected), type_test="tensor")
         test_local_inversion(flip, {"img": result}, {"img": im}, "img")
コード例 #6
0
ファイル: test_inverse.py プロジェクト: slohani-ai/MONAI
))

TESTS.append(("CropForegroundd 2d", "2D", 0,
              CropForegroundd(KEYS, source_key="label", margin=2)))

TESTS.append(
    ("CropForegroundd 3d", "3D", 0, CropForegroundd(KEYS, source_key="label")))

TESTS.append(("ResizeWithPadOrCropd 3d", "3D", 0,
              ResizeWithPadOrCropd(KEYS, [201, 150, 105])))

TESTS.append((
    "Flipd 3d",
    "3D",
    0,
    Flipd(KEYS, [1, 2]),
))

TESTS.append((
    "Flipd 3d",
    "3D",
    0,
    Flipd(KEYS, [1, 2]),
))

TESTS.append((
    "RandFlipd 3d",
    "3D",
    0,
    RandFlipd(KEYS, 1, [1, 2]),
))
コード例 #7
0
 def test_invalid_cases(self, _, spatial_axis, raises):
     with self.assertRaises(raises):
         flip = Flipd(keys="img", spatial_axis=spatial_axis)
         flip({"img": self.imt[0]})
コード例 #8
0
ファイル: test_flipd.py プロジェクト: ericspod/MONAI
 def test_meta_dict(self):
     xform = Flipd("image", [0, 1])
     res = xform({"image": torch.zeros(1, 3, 4)})
     self.assertTrue(
         res["image"].applied_operations == res["image_transforms"])
コード例 #9
0
TESTS.append(("CenterSpatialCropd 3d", "3D", 0, True,
              CenterSpatialCropd(KEYS, roi_size=[95, 97, 98])))

TESTS.append(("CropForegroundd 2d", "2D", 0, True,
              CropForegroundd(KEYS, source_key="label", margin=2)))

TESTS.append(("CropForegroundd 3d", "3D", 0, True,
              CropForegroundd(KEYS,
                              source_key="label",
                              k_divisible=[5, 101, 2])))

TESTS.append(("ResizeWithPadOrCropd 3d", "3D", 0, True,
              ResizeWithPadOrCropd(KEYS, [201, 150, 105])))

TESTS.append(("Flipd 3d", "3D", 0, True, Flipd(KEYS, [1, 2])))
TESTS.append(("Flipd 3d", "3D", 0, True, Flipd(KEYS, [1, 2])))

TESTS.append(("RandFlipd 3d", "3D", 0, True, RandFlipd(KEYS, 1, [1, 2])))

TESTS.append(("RandAxisFlipd 3d", "3D", 0, True, RandAxisFlipd(KEYS, 1)))
TESTS.append(("RandAxisFlipd 3d", "3D", 0, True, RandAxisFlipd(KEYS, 1)))

for acc in [True, False]:
    TESTS.append(("Orientationd 3d", "3D", 0, True,
                  Orientationd(KEYS, "RAS", as_closest_canonical=acc)))

TESTS.append(("Rotate90d 2d", "2D", 0, True, Rotate90d(KEYS)))

TESTS.append(
    ("Rotate90d 3d", "3D", 0, True, Rotate90d(KEYS, k=2, spatial_axes=(1, 2))))