def test_types(img, n_rays, grid): mode = "cpp" rays = Rays_GoldenSpiral(n_rays) gt = star_dist3D(img, rays=rays, grid=grid, mode=mode) for dtype in (np.int8, np.int16, np.int32, np.uint8, np.uint16, np.uint32): x = star_dist3D(img.astype(dtype), rays=rays, grid=grid, mode=mode) print("test_stardist3D (mode {mode}) for shape {img.shape} and type {dtype}".format(mode =mode, img = img, dtype = dtype)) check_similar(gt, x)
def test_cpu_gpu(img, n_rays, grid): print(tuple(s//g for s, g in zip(img.shape, grid))) rays = Rays_GoldenSpiral(n_rays) with Timer(f"stardist {img.shape} {n_rays} rays - CPU"): s_cpp = star_dist3D(img, rays=rays, grid=grid, mode="cpp") with Timer(f"stardist {img.shape} {n_rays} rays - GPU"): s_ocl = star_dist3D(img, rays=rays, grid=grid, mode="opencl") check_similar(s_cpp, s_ocl) return s_cpp, s_ocl
def test_grid(grid,shape): ss_grid = tuple(slice(0, None, g) for g in grid) lbl = circle_image(shape=shape, radius=min(shape)//3) rays = Rays_GoldenSpiral(32) t1 = time() d1 = star_dist3D(lbl, rays = rays) d1 = d1[ss_grid] t1 = time()-t1 t2 = time() d2 = star_dist3D(lbl, rays = rays, grid = grid) t2 = time()-t2 print(f"time 1: {1000*t1:.2f}ms") print(f"time 2: {1000*t2:.2f}ms") assert np.allclose(d1,d2) return lbl, d1, d2
def test_cpu_gpu(img, n_rays, grid): rays = Rays_GoldenSpiral(n_rays) s_cpp = star_dist3D(img, rays=rays, grid=grid, mode="cpp") s_ocl = star_dist3D(img, rays=rays, grid=grid, mode="opencl") check_similar(s_cpp, s_ocl)
mode = "opencl" rays = Rays_GoldenSpiral(n_rays) gt = star_dist3D(img, rays=rays, grid=grid, mode=mode) for dtype in (np.int8, np.int16, np.int32, np.uint8, np.uint16, np.uint32): x = star_dist3D(img.astype(dtype), rays=rays, grid=grid, mode=mode) print("test_stardist3D (mode {mode}) for shape {img.shape} and type {dtype}".format(mode =mode, img = img, dtype = dtype)) check_similar(gt, x) @pytest.mark.gpu @pytest.mark.parametrize('img', (real_image3d()[1], random_image((33, 44, 55)))) @pytest.mark.parametrize('n_rays', (4, 16, 32)) @pytest.mark.parametrize('grid', ((1,1,1),(1,2,4))) def test_cpu_gpu(img, n_rays, grid): rays = Rays_GoldenSpiral(n_rays) s_cpp = star_dist3D(img, rays=rays, grid=grid, mode="cpp") s_ocl = star_dist3D(img, rays=rays, grid=grid, mode="opencl") check_similar(s_cpp, s_ocl) if __name__ == '__main__': from utils import circle_image rays = Rays_GoldenSpiral(4) lbl = circle_image((64,) * 3) a = star_dist3D(lbl, rays=rays, grid=(1, 2, 2), mode="cpp") b = star_dist3D(lbl, rays=rays, grid=(1, 2, 2), mode="opencl") print(np.amax(np.abs(a - b)))