Пример #1
0
    def test_correct_results(self, min_zoom, max_zoom, mode, align_corners,
                             keep_size):
        key = "img"
        random_zoom = RandZoomd(
            key,
            prob=1.0,
            min_zoom=min_zoom,
            max_zoom=max_zoom,
            mode=mode,
            align_corners=align_corners,
            keep_size=keep_size,
        )
        random_zoom.set_random_state(1234)

        zoomed = random_zoom({key: self.imt[0]})
        expected = []
        for channel in self.imt[0]:
            expected.append(
                zoom_scipy(channel,
                           zoom=random_zoom._zoom,
                           mode="nearest",
                           order=0,
                           prefilter=False))
        expected = np.stack(expected).astype(np.float32)
        np.testing.assert_allclose(expected, zoomed[key], atol=1.0)
Пример #2
0
    def test_gpu_zoom(self, min_zoom, max_zoom, order, mode, cval, prefilter):
        key = "img"
        if importlib.util.find_spec("cupy"):
            random_zoom = RandZoomd(
                key,
                prob=1.0,
                min_zoom=min_zoom,
                max_zoom=max_zoom,
                interp_order=order,
                mode=mode,
                cval=cval,
                prefilter=prefilter,
                use_gpu=True,
                keep_size=False,
            )
            random_zoom.set_random_state(234)

            zoomed = random_zoom({key: self.imt[0]})
            expected = list()
            for channel in self.imt[0]:
                expected.append(
                    zoom_scipy(channel,
                               zoom=random_zoom._zoom,
                               mode=mode,
                               order=order,
                               cval=cval,
                               prefilter=prefilter))
            expected = np.stack(expected).astype(np.float32)
            self.assertTrue(np.allclose(expected, zoomed[key]))
Пример #3
0
    def test_correct_results(self, min_zoom, max_zoom, order, mode, cval,
                             prefilter, use_gpu, keep_size):
        key = "img"
        random_zoom = RandZoomd(
            key,
            prob=1.0,
            min_zoom=min_zoom,
            max_zoom=max_zoom,
            interp_order=order,
            mode=mode,
            cval=cval,
            prefilter=prefilter,
            use_gpu=use_gpu,
            keep_size=keep_size,
        )
        random_zoom.set_random_state(234)

        zoomed = random_zoom({key: self.imt[0]})
        expected = list()
        for channel in self.imt[0]:
            expected.append(
                zoom_scipy(channel,
                           zoom=random_zoom._zoom,
                           mode=mode,
                           order=order,
                           cval=cval,
                           prefilter=prefilter))
        expected = np.stack(expected).astype(np.float32)
        self.assertTrue(np.allclose(expected, zoomed[key]))
Пример #4
0
    def test_correct_results(self, min_zoom, max_zoom, mode, align_corners,
                             keep_size):
        key = "img"
        random_zoom = RandZoomd(
            key,
            prob=1.0,
            min_zoom=min_zoom,
            max_zoom=max_zoom,
            mode=mode,
            align_corners=align_corners,
            keep_size=keep_size,
        )
        for p in TEST_NDARRAYS:
            random_zoom.set_random_state(1234)

            zoomed = random_zoom({key: p(self.imt[0])})
            expected = [
                zoom_scipy(channel,
                           zoom=random_zoom.rand_zoom._zoom,
                           mode="nearest",
                           order=0,
                           prefilter=False) for channel in self.imt[0]
            ]

            expected = np.stack(expected).astype(np.float32)
            assert_allclose(zoomed[key], p(expected), atol=1.0)
Пример #5
0
 def test_auto_expand_3d(self):
     random_zoom = RandZoomd(
         keys="img", prob=1.0, min_zoom=[0.8, 0.7], max_zoom=[1.2, 1.3], mode="nearest", keep_size=False
     )
     for p in TEST_NDARRAYS:
         random_zoom.set_random_state(1234)
         test_data = {"img": p(np.random.randint(0, 2, size=[2, 2, 3, 4]))}
         zoomed = random_zoom(test_data)
         assert_allclose(random_zoom.rand_zoom._zoom, (1.048844, 1.048844, 0.962637), atol=1e-2)
         assert_allclose(zoomed["img"].shape, (2, 2, 3, 3))