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]))
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)
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]))
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)
def test_gpu_zoom(self, _, zoom, order, mode, cval, prefilter): key = "img" if importlib.util.find_spec("cupy"): zoom_fn = Zoomd( key, zoom=zoom, interp_order=order, mode=mode, cval=cval, prefilter=prefilter, use_gpu=True, keep_size=False, ) zoomed = zoom_fn({key: self.imt[0]}) expected = list() for channel in self.imt[0]: expected.append( zoom_scipy(channel, zoom=zoom, mode=mode, order=order, cval=cval, prefilter=prefilter)) expected = np.stack(expected).astype(np.float32) self.assertTrue(np.allclose(expected, zoomed[key]))
def test_correct_results(self, zoom, order, mode, cval, prefilter, use_gpu, keep_size): key = "img" zoom_fn = Zoomd( key, zoom=zoom, interp_order=order, mode=mode, cval=cval, prefilter=prefilter, use_gpu=use_gpu, keep_size=keep_size, ) zoomed = zoom_fn({key: self.imt[0]}) expected = list() for channel in self.imt[0]: expected.append( zoom_scipy(channel, zoom=zoom, mode=mode, order=order, cval=cval, prefilter=prefilter)) expected = np.stack(expected).astype(np.float32) self.assertTrue(np.allclose(expected, zoomed[key]))
def test_correct_results(self, min_zoom, max_zoom, order, keep_size): random_zoom = RandZoom(prob=1.0, min_zoom=min_zoom, max_zoom=max_zoom, interp_order=order, keep_size=keep_size,) random_zoom.set_random_state(1234) zoomed = random_zoom(self.imt[0]) expected = list() 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(zoomed, expected, atol=1.0)
def test_correct_results(self, zoom, interp_order): zoom_fn = Zoom(zoom=zoom, interp_order=interp_order, keep_size=False) zoomed = zoom_fn(self.imt[0]) _order = 0 if interp_order.endswith("linear"): _order = 1 expected = list() for channel in self.imt[0]: expected.append(zoom_scipy(channel, zoom=zoom, mode="nearest", order=_order, prefilter=False)) expected = np.stack(expected).astype(np.float32) np.testing.assert_allclose(zoomed, expected, atol=1.0)
def test_correct_results(self, zoom, mode, keep_size): key = "img" zoom_fn = Zoomd(key, zoom=zoom, mode=mode, keep_size=keep_size,) zoomed = zoom_fn({key: self.imt[0]}) _order = 0 if mode.endswith("linear"): _order = 1 expected = list() for channel in self.imt[0]: expected.append(zoom_scipy(channel, zoom=zoom, mode="nearest", order=_order, prefilter=False)) expected = np.stack(expected).astype(np.float32) np.testing.assert_allclose(expected, zoomed[key], atol=1.0)
def test_correct_results(self, zoom, mode): for p in TEST_NDARRAYS: zoom_fn = Zoom(zoom=zoom, mode=mode, keep_size=False) zoomed = zoom_fn(p(self.imt[0])) _order = 0 if mode.endswith("linear"): _order = 1 expected = [] for channel in self.imt[0]: expected.append( zoom_scipy(channel, zoom=zoom, mode="nearest", order=_order, prefilter=False)) expected = np.stack(expected).astype(np.float32) assert_allclose(zoomed, p(expected), atol=1.0)
def test_correct_results(self, zoom, mode, keep_size): key = "img" zoom_fn = Zoomd(key, zoom=zoom, mode=mode, keep_size=keep_size) for p in TEST_NDARRAYS: zoomed = zoom_fn({key: p(self.imt[0])}) _order = 0 if mode.endswith("linear"): _order = 1 expected = [ zoom_scipy(channel, zoom=zoom, mode="nearest", order=_order, prefilter=False) for channel in self.imt[0] ] expected = np.stack(expected).astype(np.float32) assert_allclose(zoomed[key], p(expected), atol=1.0)
def test_correct_results(self, min_zoom, max_zoom, mode, keep_size): for p in TEST_NDARRAYS: random_zoom = RandZoom(prob=1.0, min_zoom=min_zoom, max_zoom=max_zoom, mode=mode, keep_size=keep_size) random_zoom.set_random_state(1234) zoomed = random_zoom(p(self.imt[0])) expected = [ zoom_scipy(channel, zoom=random_zoom._zoom, mode="nearest", order=0, prefilter=False) for channel in self.imt[0] ] expected = np.stack(expected).astype(np.float32) assert_allclose(zoomed, p(expected), atol=1.0)
def test_gpu_zoom(self, _, zoom, order, mode, cval, prefilter): if importlib.util.find_spec('cupy'): zoom_fn = Zoom(zoom=zoom, order=order, mode=mode, cval=cval, prefilter=prefilter, use_gpu=True, keep_size=False) zoomed = zoom_fn(self.imt[0]) expected = list() for channel in self.imt[0]: expected.append( zoom_scipy(channel, zoom=zoom, mode=mode, order=order, cval=cval, prefilter=prefilter)) expected = np.stack(expected).astype(np.float32) self.assertTrue(np.allclose(expected, zoomed))