diff --git a/conftest.py b/conftest.py index cfae5366..149a351d 100644 --- a/conftest.py +++ b/conftest.py @@ -1,31 +1,23 @@ # global import pytest -from typing import Dict # local import ivy -from ivy_tests.test_ivy import helpers +import jax - -FW_STRS = ["numpy", "jax", "tensorflow", "torch"] +jax.config.update("jax_enable_x64", True) -TEST_BACKENDS: Dict[str, callable] = { - "numpy": lambda: helpers.globals._get_ivy_numpy(), - "jax": lambda: helpers.globals._get_ivy_jax(), - "tensorflow": lambda: helpers.globals._get_ivy_tensorflow(), - "torch": lambda: helpers.globals._get_ivy_torch(), -} +FW_STRS = ["numpy", "jax", "tensorflow", "torch"] @pytest.fixture(autouse=True) -def run_around_tests(dev_str, f, compile_graph, implicit, fw): - if "gpu" in dev_str and fw == "numpy": +def run_around_tests(device, compile_graph, fw): + if "gpu" in device and fw == "numpy": # Numpy does not support GPU pytest.skip() - ivy.unset_backend() - with f.use: - with ivy.DefaultDevice(dev_str): + with ivy.utils.backend.ContextManager(fw): + with ivy.DefaultDevice(device): yield @@ -40,7 +32,7 @@ def pytest_generate_tests(metafunc): # framework raw_value = metafunc.config.getoption("--backend") if raw_value == "all": - backend_strs = TEST_BACKENDS.keys() + backend_strs = FW_STRS else: backend_strs = raw_value.split(",") @@ -53,33 +45,16 @@ def pytest_generate_tests(metafunc): else: compile_modes = [False] - # with_implicit - raw_value = metafunc.config.getoption("--with_implicit") - if raw_value == "true": - implicit_modes = [True, False] - else: - implicit_modes = [False] - # create test configs configs = list() for backend_str in backend_strs: for device in devices: for compile_graph in compile_modes: - for implicit in implicit_modes: - configs.append( - ( - device, - TEST_BACKENDS[backend_str](), - compile_graph, - implicit, - backend_str, - ) - ) - metafunc.parametrize("dev_str,f,compile_graph,implicit,fw", configs) + configs.append((device, compile_graph, backend_str)) + metafunc.parametrize("device,compile_graph,fw", configs) def pytest_addoption(parser): parser.addoption("--device", action="store", default="cpu") parser.addoption("--backend", action="store", default="numpy,jax,tensorflow,torch") parser.addoption("--compile_graph", action="store", default="true") - parser.addoption("--with_implicit", action="store", default="false") diff --git a/ivy_vision/implicit.py b/ivy_vision/implicit.py index f4bc8373..a87a89db 100644 --- a/ivy_vision/implicit.py +++ b/ivy_vision/implicit.py @@ -52,7 +52,7 @@ def create_sampled_pixel_coords_image( normalized=False, randomize=True, homogeneous=False, - dev_str=None, + device=None, ): r"""Create image of randomly sampled homogeneous integer :math:`xy` pixel co-ordinates :math:`\mathbf{X}\in\mathbb{Z}^{h×w×3}`, stored as floating point @@ -81,7 +81,7 @@ def create_sampled_pixel_coords_image( homogeneous Whether the pixel co-ordinates should be 3D homogeneous or just 2D. Default is True. - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None) @@ -93,7 +93,7 @@ def create_sampled_pixel_coords_image( """ # BS x DH x DW x 2 low_res_pix_coords = ivy_svg.create_uniform_pixel_coords_image( - samples_per_dim, batch_shape, homogeneous=False, dev_str=dev_str + samples_per_dim, batch_shape, homogeneous=False, device=device ) # 2 @@ -106,7 +106,7 @@ def create_sampled_pixel_coords_image( ] ) ), - device=dev_str, + device=device, ) # BS x DH x DW x 2 @@ -118,13 +118,13 @@ def create_sampled_pixel_coords_image( low=ivy.to_scalar(-window_size[0] / 2), high=ivy.to_scalar(window_size[0] / 2), shape=list(downsam_pix_coords.shape[:-1]) + [1], - device=dev_str, + device=device, ) rand_y = ivy.random_uniform( low=ivy.to_scalar(-window_size[1] / 2), high=ivy.to_scalar(window_size[1] / 2), shape=list(downsam_pix_coords.shape[:-1]) + [1], - device=dev_str, + device=device, ) # BS x DH x DW x 2 @@ -132,13 +132,13 @@ def create_sampled_pixel_coords_image( downsam_pix_coords += rand_offsets downsam_pix_coords = ivy.clip( ivy.round(downsam_pix_coords), - ivy.array([0.0] * 2, device=dev_str), - ivy.array(list(reversed(image_dims)), dtype="float32", device=dev_str) - 1, + ivy.array([0.0] * 2, device=device), + ivy.array(list(reversed(image_dims)), dtype="float32", device=device) - 1, ) if normalized: downsam_pix_coords /= ( - ivy.array([image_dims[1], image_dims[0]], dtype="float32", device=dev_str) + ivy.array([image_dims[1], image_dims[0]], dtype="float32", device=device) + MIN_DENOMINATOR ) @@ -152,7 +152,7 @@ def create_sampled_pixel_coords_image( return downsam_pix_coords -def sample_images(list_of_images, num_pixels, batch_shape, image_dims, dev_str=None): +def sample_images(list_of_images, num_pixels, batch_shape, image_dims, device=None): """Samples each image in a list of aligned images at num_pixels random pixel co-ordinates, within a unifrom grid over the image. @@ -166,7 +166,7 @@ def sample_images(list_of_images, num_pixels, batch_shape, image_dims, dev_str=N Shape of batch. Inferred from inputs if None. image_dims Image dimensions. Inferred from inputs in None. - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as images if None. (Default value = None) @@ -177,8 +177,8 @@ def sample_images(list_of_images, num_pixels, batch_shape, image_dims, dev_str=N if image_dims is None: image_dims = list_of_images[0].shape[-3:-1] - if dev_str is None: - dev_str = ivy.dev(list_of_images[0]) + if device is None: + device = ivy.dev(list_of_images[0]) image_channels = [img.shape[-1] for img in list_of_images] @@ -194,7 +194,7 @@ def sample_images(list_of_images, num_pixels, batch_shape, image_dims, dev_str=N # BS x DH x DW x 2 sampled_pix_coords = ivy.astype( create_sampled_pixel_coords_image( - image_dims, new_img_dims, batch_shape, homogeneous=False, dev_str=dev_str + image_dims, new_img_dims, batch_shape, homogeneous=False, device=device ), "int32", ) @@ -209,8 +209,8 @@ def sample_images(list_of_images, num_pixels, batch_shape, image_dims, dev_str=N ivy.permute_dims( ivy.astype( ivy.linspace( - ivy.zeros(new_img_dims, device=dev_str), - ivy.ones(new_img_dims, device=dev_str) * (flat_batch_size - 1), + ivy.zeros(new_img_dims, device=device), + ivy.ones(new_img_dims, device=device) * (flat_batch_size - 1), flat_batch_size, axis=-1, ), diff --git a/ivy_vision/mesh.py b/ivy_vision/mesh.py index 31fa722b..af26d6cd 100644 --- a/ivy_vision/mesh.py +++ b/ivy_vision/mesh.py @@ -12,7 +12,7 @@ def rasterize_triangles( - pixel_coords_triangles, image_dims, batch_shape=None, dev_str=None + pixel_coords_triangles, image_dims, batch_shape=None, device=None ): """Rasterize image-projected triangles based on: https://www.scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical @@ -29,7 +29,7 @@ def rasterize_triangles( Image dimensions. batch_shape Shape of batch. Inferred from Inputs if None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -42,8 +42,8 @@ def rasterize_triangles( if batch_shape is None: batch_shape = [] - if dev_str is None: - dev_str = ivy.dev(pixel_coords_triangles) + if device is None: + device = ivy.dev(pixel_coords_triangles) # shapes as list batch_shape = list(batch_shape) @@ -113,7 +113,7 @@ def rasterize_triangles( num_batch_dims_after = len(batch_dims_after) # [batch_dim] - batch_indices = ivy.arange(batch_dim, dtype="int32", device=dev_str) + batch_indices = ivy.arange(batch_dim, dtype="int32", device=device) # [1]*num_batch_dims_before x batch_dim x [1]*num_batch_dims_after x 1 x 1 reshaped_batch_indices = ivy.reshape( @@ -157,7 +157,7 @@ def rasterize_triangles( ) -def create_trimesh_indices_for_image(batch_shape, image_dims, dev_str=None): +def create_trimesh_indices_for_image(batch_shape, image_dims, device=None): """Create triangle mesh for image with given image dimensions Parameters @@ -166,7 +166,7 @@ def create_trimesh_indices_for_image(batch_shape, image_dims, dev_str=None): Shape of batch. image_dims Image dimensions. - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None) @@ -188,20 +188,20 @@ def create_trimesh_indices_for_image(batch_shape, image_dims, dev_str=None): # 1 x W-1 t00_ = ivy.reshape( - ivy.arange(image_dims[1] - 1, dtype="float32", device=dev_str), (1, -1) + ivy.arange(image_dims[1] - 1, dtype="float32", device=device), (1, -1) ) # H-1 x 1 k_ = ( ivy.reshape( - ivy.arange(image_dims[0] - 1, dtype="float32", device=dev_str), (-1, 1) + ivy.arange(image_dims[0] - 1, dtype="float32", device=device), (-1, 1) ) * image_dims[1] ) # H-1 x W-1 - t00_ = ivy.matmul(ivy.ones((image_dims[0] - 1, 1), device=dev_str), t00_) - k_ = ivy.matmul(k_, ivy.ones((1, image_dims[1] - 1), device=dev_str)) + t00_ = ivy.matmul(ivy.ones((image_dims[0] - 1, 1), device=device), t00_) + k_ = ivy.matmul(k_, ivy.ones((1, image_dims[1] - 1), device=device)) # (H-1xW-1) x 1 t00 = ivy.expand_dims(t00_ + k_, axis=-1) @@ -220,7 +220,7 @@ def create_trimesh_indices_for_image(batch_shape, image_dims, dev_str=None): def coord_image_to_trimesh( - coord_img, validity_mask=None, batch_shape=None, image_dims=None, dev_str=None + coord_img, validity_mask=None, batch_shape=None, image_dims=None, device=None ): """Create trimesh, with vertices and triangle indices, from co-ordinate image. @@ -235,7 +235,7 @@ def coord_image_to_trimesh( Shape of batch. Inferred from inputs if None. (Default value = None) image_dims Image dimensions. Inferred from inputs in None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -245,8 +245,8 @@ def coord_image_to_trimesh( Vertices *[batch_shape,(hxw),3]* amd Trimesh indices *[batch_shape,n,3]* """ - if dev_str is None: - dev_str = ivy.dev(coord_img) + if device is None: + device = ivy.dev(coord_img) if batch_shape is None: batch_shape = ivy.shape(coord_img)[:-3] @@ -294,7 +294,7 @@ def coord_image_to_trimesh( # BS x 2x(H-1xW-1) x 3 all_trimesh_indices = create_trimesh_indices_for_image( - batch_shape, image_dims, dev_str + batch_shape, image_dims, device ) # BS x N x 3 diff --git a/ivy_vision/optical_flow.py b/ivy_vision/optical_flow.py index eb5b7f70..622f9abf 100644 --- a/ivy_vision/optical_flow.py +++ b/ivy_vision/optical_flow.py @@ -22,7 +22,7 @@ def depth_from_flow_and_cam_mats( triangulation_method="cmp", batch_shape=None, image_dims=None, - dev_str=None, + device=None, ): r"""Compute depth map :math:`\mathbf{X}\in\mathbb{R}^{h×w×1}` in frame 1 using optical flow :math:`\mathbf{U}_{1→2}\in\mathbb{R}^{h×w×2}` from frame 1 to 2, @@ -50,7 +50,7 @@ def depth_from_flow_and_cam_mats( Shape of batch. Inferred from inputs if None. (Default value = None) image_dims Image dimensions. Inferred from inputs in None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -70,13 +70,13 @@ def depth_from_flow_and_cam_mats( batch_shape = list(batch_shape) image_dims = list(image_dims) - if dev_str is None: - dev_str = ivy.dev(flow) + if device is None: + device = ivy.dev(flow) if inv_full_mats is None: inv_full_mats = ivy.inv( ivy_mech.make_transformation_homogeneous( - full_mats, batch_shape + [2], dev_str + full_mats, batch_shape + [2], device ) )[..., 0:3, :] @@ -85,12 +85,12 @@ def depth_from_flow_and_cam_mats( if uniform_pixel_coords is None: uniform_pixel_coords = ivy_svg.create_uniform_pixel_coords_image( - image_dims, batch_shape, dev_str=dev_str + image_dims, batch_shape, device=device ) # BS x H x W x 3 flow_homo = ivy.concat( - (flow, ivy.zeros(batch_shape + image_dims + [1], device=dev_str)), axis=-1 + (flow, ivy.zeros(batch_shape + image_dims + [1], device=device)), axis=-1 ) # BS x H x W x 3 @@ -178,7 +178,7 @@ def project_flow_to_epipolar_line( uniform_pixel_coords=None, batch_shape=None, image_dims=None, - dev_str=None, + device=None, ): r"""Project optical flow :math:`\mathbf{U}_{1→2}\in\mathbb{R}^{h×w×2}` to epipolar line in frame 1.\n `[reference] @@ -198,7 +198,7 @@ def project_flow_to_epipolar_line( Shape of batch. Inferred from inputs if None. (Default value = None) image_dims Image dimensions. Inferred from inputs in None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -221,7 +221,7 @@ def project_flow_to_epipolar_line( if uniform_pixel_coords is None: uniform_pixel_coords = ivy_svg.create_uniform_pixel_coords_image( - image_dims, batch_shape, dev_str + image_dims, batch_shape, device ) # BS x H x W x 3 @@ -331,7 +331,7 @@ def velocity_from_flow_cam_coords_and_cam_mats( uniform_pixel_coords=None, batch_shape=None, image_dims=None, - dev_str=None, + device=None, ): """Compute relative cartesian velocity from optical flow, camera co-ordinates, and camera extrinsics. @@ -355,7 +355,7 @@ def velocity_from_flow_cam_coords_and_cam_mats( Shape of batch. Inferred from inputs if None. (Default value = None) image_dims Image dimensions. Inferred from inputs in None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -375,12 +375,12 @@ def velocity_from_flow_cam_coords_and_cam_mats( batch_shape = list(batch_shape) image_dims = list(image_dims) - if dev_str is None: - dev_str = ivy.dev(flow_t_to_tm1) + if device is None: + device = ivy.dev(flow_t_to_tm1) if uniform_pixel_coords is None: uniform_pixel_coords = ivy_svg.create_uniform_pixel_coords_image( - image_dims, batch_shape, dev_str + image_dims, batch_shape, device ) # Interpolate cam coords from frame t-1 @@ -416,7 +416,7 @@ def velocity_from_flow_cam_coords_and_cam_mats( ivy.astype( warp < ivy.array( - [image_dims[1], image_dims[0]], dtype="float32", device=dev_str + [image_dims[1], image_dims[0]], dtype="float32", device=device ), "int32", ), @@ -430,7 +430,7 @@ def velocity_from_flow_cam_coords_and_cam_mats( # BS x H x W x 3, BS x H x W x 1 return ( - ivy.where(validity_mask, vel, ivy.zeros_like(vel, device=dev_str)), + ivy.where(validity_mask, vel, ivy.zeros_like(vel, device=device)), validity_mask, ) @@ -564,7 +564,7 @@ def velocity_from_cam_coords_id_image_and_object_trans( delta_t, batch_shape=None, image_shape=None, - dev_str=None, + device=None, ): """Compute velocity image from co-ordinate image, id image, and object transformations. @@ -586,7 +586,7 @@ def velocity_from_cam_coords_id_image_and_object_trans( Shape of batch. Inferred from inputs if None. (Default value = None) image_shape Image dimensions. Inferred from inputs in None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -603,8 +603,8 @@ def velocity_from_cam_coords_id_image_and_object_trans( if image_shape is None: image_shape = cam_coords_t.shape[num_batch_dims:-1] - if dev_str is None: - dev_str = ivy.dev(cam_coords_t) + if device is None: + device = ivy.dev(cam_coords_t) # shapes as list batch_shape = list(batch_shape) @@ -630,7 +630,7 @@ def velocity_from_cam_coords_id_image_and_object_trans( cam_coords_t_all_trans = ivy.where( motion_mask, cam_coords_t_all_trans, - ivy.zeros_like(cam_coords_t_all_trans, device=dev_str), + ivy.zeros_like(cam_coords_t_all_trans, device=device), ) # compute velocities @@ -641,7 +641,7 @@ def velocity_from_cam_coords_id_image_and_object_trans( # prune velocities # BS x IS x 3 - return ivy.where(motion_mask, vel, ivy.zeros_like(vel, device=dev_str)) + return ivy.where(motion_mask, vel, ivy.zeros_like(vel, device=device)) def flow_from_cam_coords_id_image_and_object_trans( diff --git a/ivy_vision/quantization.py b/ivy_vision/quantization.py index 52d00c4f..4dbb550b 100644 --- a/ivy_vision/quantization.py +++ b/ivy_vision/quantization.py @@ -23,7 +23,7 @@ def quantize_to_image( var_threshold=(1e-3, 1e12), uniform_pixel_coords=None, batch_shape=None, - dev_str=None, + device=None, ): r"""Quantize pixel co-ordinates with d feature channels (for depth, rgb, normals etc.), from images :math:`\mathbf{X}\in\mathbb{R}^{input\_images\_shape×(2+d)}`, @@ -64,7 +64,7 @@ def quantize_to_image( if None *[batch_shape,h,w,3]* (Default value = None) batch_shape Shape of batch. Assumed no batches if None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -83,14 +83,14 @@ def quantize_to_image( if batch_shape is None: batch_shape = pixel_coords.shape[:-2] - if dev_str is None: - dev_str = ivy.dev(pixel_coords) + if device is None: + device = ivy.dev(pixel_coords) if feat is None: d = 0 else: d = feat.shape[-1] - min_depth_diff = ivy.array([MIN_DEPTH_DIFF], device=dev_str) + min_depth_diff = ivy.array([MIN_DEPTH_DIFF], device=device) red = "min" if with_db else "sum" # shapes as list @@ -110,7 +110,7 @@ def quantize_to_image( # uniform pixel coords if uniform_pixel_coords is None: uniform_pixel_coords = ivy_svg.create_uniform_pixel_coords_image( - final_image_dims, batch_shape, dev_str=dev_str + final_image_dims, batch_shape, device=device ) uniform_pixel_coords = uniform_pixel_coords[..., 0:2] @@ -193,7 +193,7 @@ def quantize_to_image( return ( ivy.concat((uniform_pixel_coords[..., 0:2], feat_prior), axis=-1), ivy.concat((pixel_coords_prior_var, feat_prior_var), axis=-1), - ivy.zeros_like(feat[..., 0:1], device=dev_str), + ivy.zeros_like(feat[..., 0:1], device=device), ) # Depth Based Scaling # @@ -221,8 +221,8 @@ def quantize_to_image( if d == 1: # BS x 1 x 1+D - pc_n_feat_wo_depth_min = ivy.zeros(batch_shape + [1, 0], device=dev_str) - pc_n_feat_wo_depth_range = ivy.ones(batch_shape + [1, 0], device=dev_str) + pc_n_feat_wo_depth_min = ivy.zeros(batch_shape + [1, 0], device=device) + pc_n_feat_wo_depth_range = ivy.ones(batch_shape + [1, 0], device=device) else: # feat without depth @@ -306,7 +306,7 @@ def quantize_to_image( # Scatter # # num_valid_indices x 1 - counter = ivy.ones_like(pc_n_feat[..., 0:1], device=dev_str) + counter = ivy.ones_like(pc_n_feat[..., 0:1], device=device) if with_db: counter *= -1 diff --git a/ivy_vision/single_view_geometry.py b/ivy_vision/single_view_geometry.py index c8f6d302..4d509676 100644 --- a/ivy_vision/single_view_geometry.py +++ b/ivy_vision/single_view_geometry.py @@ -19,7 +19,7 @@ def create_uniform_pixel_coords_image( - image_dims, batch_shape=None, normalized=False, homogeneous=True, dev_str=None + image_dims, batch_shape=None, normalized=False, homogeneous=True, device=None ): r"""Create image of homogeneous integer :math:`xy` pixel co-ordinates @@ -51,7 +51,7 @@ def create_uniform_pixel_coords_image( homogeneous Whether the pixel co-ordinates should be 3D homogeneous or just 2D. Default is True. - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. (Default value = None) @@ -74,7 +74,7 @@ def create_uniform_pixel_coords_image( # H x W x 1 pixel_x_coords = ivy.astype( ivy.reshape( - ivy.tile(ivy.arange(image_dims[1], device=dev_str), [image_dims[0]]), + ivy.tile(ivy.arange(image_dims[1], device=device), [image_dims[0]]), (image_dims[0], image_dims[1], 1), ), "float32", @@ -85,7 +85,7 @@ def create_uniform_pixel_coords_image( # W x H x 1 pixel_y_coords_ = ivy.astype( ivy.reshape( - ivy.tile(ivy.arange(image_dims[0], device=dev_str), [image_dims[1]]), + ivy.tile(ivy.arange(image_dims[0], device=device), [image_dims[1]]), (image_dims[1], image_dims[0], 1), ), "float32", @@ -110,7 +110,7 @@ def create_uniform_pixel_coords_image( return pix_coords -def persp_angles_to_focal_lengths(persp_angles, image_dims, dev_str=None): +def persp_angles_to_focal_lengths(persp_angles, image_dims, device=None): r"""Compute focal lengths :math:`f_x, f_y` from perspective angles :math:`θ_x, θ_y`.\n `[reference] `_ # noqa @@ -122,7 +122,7 @@ def persp_angles_to_focal_lengths(persp_angles, image_dims, dev_str=None): Perspective angles *[batch_shape,2]* image_dims Image dimensions. - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -132,19 +132,19 @@ def persp_angles_to_focal_lengths(persp_angles, image_dims, dev_str=None): Focal lengths *[batch_shape,2]* """ - if dev_str is None: - dev_str = ivy.dev(persp_angles) + if device is None: + device = ivy.dev(persp_angles) # shapes as list image_dims = list(image_dims) # BS x 2 return -ivy.flip( - ivy.astype(ivy.array(image_dims, device=dev_str), "float32"), axis=-1 + ivy.astype(ivy.array(image_dims, device=device), "float32"), axis=-1 ) / (2 * ivy.tan(persp_angles / 2) + MIN_DENOMINATOR) -def focal_lengths_to_persp_angles(focal_lengths, image_dims, dev_str=None): +def focal_lengths_to_persp_angles(focal_lengths, image_dims, device=None): r"""Compute perspective angles :math:`θ_x, θ_y` from focal lengths :math:`f_x, f_y`.\n `[reference] `_ # noqa @@ -156,7 +156,7 @@ def focal_lengths_to_persp_angles(focal_lengths, image_dims, dev_str=None): batch_shape,2]* image_dims Image dimensions. - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -166,21 +166,21 @@ def focal_lengths_to_persp_angles(focal_lengths, image_dims, dev_str=None): Perspective angles *[batch_shape,2]* """ - if dev_str is None: - dev_str = ivy.dev(focal_lengths) + if device is None: + device = ivy.dev(focal_lengths) # shapes as list image_dims = list(image_dims) # BS x 2 return -2 * ivy.atan( - ivy.flip(ivy.astype(ivy.array(image_dims, device=dev_str), "float32"), axis=-1) + ivy.flip(ivy.astype(ivy.array(image_dims, device=device), "float32"), axis=-1) / (2 * focal_lengths + MIN_DENOMINATOR) ) def focal_lengths_and_pp_offsets_to_calib_mat( - focal_lengths, pp_offsets, batch_shape=None, dev_str=None + focal_lengths, pp_offsets, batch_shape=None, device=None ): r"""Compute calibration matrix :math:`\mathbf{K}\in\mathbb{R}^{3×3}` from focal lengths :math:`f_x, f_y` and @@ -197,7 +197,7 @@ def focal_lengths_and_pp_offsets_to_calib_mat( batch_shape Shape of batch. Inferred from inputs if None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -210,15 +210,15 @@ def focal_lengths_and_pp_offsets_to_calib_mat( if batch_shape is None: batch_shape = focal_lengths.shape[:-1] - if dev_str is None: - dev_str = ivy.dev(focal_lengths) + if device is None: + device = ivy.dev(focal_lengths) # shapes as list batch_shape = list(batch_shape) # BS x 1 x 1 - zeros = ivy.zeros(batch_shape + [1, 1], device=dev_str) - ones = ivy.ones(batch_shape + [1, 1], device=dev_str) + zeros = ivy.zeros(batch_shape + [1, 1], device=device) + ones = ivy.ones(batch_shape + [1, 1], device=device) # BS x 2 x 1 focal_lengths_reshaped = ivy.expand_dims(focal_lengths, axis=-1) @@ -322,7 +322,7 @@ def depth_to_ds_pixel_coords( # BS x H x W x 3 if uniform_pixel_coords is None: uniform_pixel_coords = create_uniform_pixel_coords_image( - image_dims, batch_shape, dev_str=ivy.dev(depth) + image_dims, batch_shape, device=ivy.dev(depth) ) # BS x H x W x 3 @@ -372,7 +372,7 @@ def depth_to_radial_depth( # BS x H x W x 3 if uniform_pix_coords is None: uniform_pix_coords = create_uniform_pixel_coords_image( - image_dims, batch_shape, dev_str=ivy.dev(depth) + image_dims, batch_shape, device=ivy.dev(depth) ) ds_pixel_coords = uniform_pix_coords * depth @@ -499,7 +499,7 @@ def cam_coords_to_depth(coords_wrt_cam, calib_mat, batch_shape=None, image_shape def ds_pixel_to_cam_coords( - ds_pixel_coords, inv_calib_mat, batch_shape=None, image_shape=None, dev_str=None + ds_pixel_coords, inv_calib_mat, batch_shape=None, image_shape=None, device=None ): r"""Get camera-centric homogeneous co-ordinates image :math:`\mathbf{X}_c\in\mathbb{R}^{is×4}` from @@ -519,7 +519,7 @@ def ds_pixel_to_cam_coords( Shape of batch. Inferred from inputs if None. (Default value = None) image_shape Image dimensions. Inferred from inputs in None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -536,8 +536,8 @@ def ds_pixel_to_cam_coords( if image_shape is None: image_shape = ds_pixel_coords.shape[num_batch_dims:-1] - if dev_str is None: - dev_str = ivy.dev(ds_pixel_coords) + if device is None: + device = ivy.dev(ds_pixel_coords) # shapes as list batch_shape = list(batch_shape) @@ -558,7 +558,7 @@ def depth_to_cam_coords( uniform_pixel_coords=None, batch_shape=None, image_dims=None, - dev_str=None, + device=None, ): r"""Get camera-centric homogeneous co-ordinates image :math:`\mathbf{X}_c\in\mathbb{R}^{hxw×4}` from @@ -577,7 +577,7 @@ def depth_to_cam_coords( Shape of batch. Inferred from inputs if None. (Default value = None) image_dims Image dimensions. Inferred from inputs in None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -593,8 +593,8 @@ def depth_to_cam_coords( if image_dims is None: image_dims = depth.shape[-3:-1] - if dev_str is None: - dev_str = ivy.dev(depth) + if device is None: + device = ivy.dev(depth) # shapes as list batch_shape = list(batch_shape) @@ -607,12 +607,12 @@ def depth_to_cam_coords( # BS x H x W x 4 return ds_pixel_to_cam_coords( - ds_pixel_coords, inv_calib_mat, batch_shape, image_dims, dev_str + ds_pixel_coords, inv_calib_mat, batch_shape, image_dims, device ) def world_to_cam_coords( - coords_wrt_world, ext_mat, batch_shape=None, image_shape=None, dev_str=None + coords_wrt_world, ext_mat, batch_shape=None, image_shape=None, device=None ): r"""Get camera-centric homogeneous co-ordinates image :math:`\mathbf{X}_c\in\mathbb{R}^{is×4}` from world-centric @@ -631,7 +631,7 @@ def world_to_cam_coords( Shape of batch. Inferred from inputs if None. (Default value = None) image_shape Image shape. Inferred from inputs in None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -648,8 +648,8 @@ def world_to_cam_coords( if image_shape is None: image_shape = coords_wrt_world.shape[num_batch_dims:-1] - if dev_str is None: - dev_str = ivy.dev(coords_wrt_world) + if device is None: + device = ivy.dev(coords_wrt_world) # shapes as list batch_shape = list(batch_shape) @@ -660,12 +660,12 @@ def world_to_cam_coords( # BS x IS x 4 return ivy.concat( - (cam_coords, ivy.ones(batch_shape + image_shape + [1], device=dev_str)), axis=-1 + (cam_coords, ivy.ones(batch_shape + image_shape + [1], device=device)), axis=-1 ) def cam_to_world_coords( - coords_wrt_cam, inv_ext_mat, batch_shape=None, image_shape=None, dev_str=None + coords_wrt_cam, inv_ext_mat, batch_shape=None, image_shape=None, device=None ): r"""Get world-centric homogeneous co-ordinates image :math:`\mathbf{X}_w\in\mathbb{R}^{is×4}` from camera-centric @@ -684,7 +684,7 @@ def cam_to_world_coords( Shape of batch. Inferred from inputs if None. (Default value = None) image_shape Image shape. Inferred from inputs in None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -701,8 +701,8 @@ def cam_to_world_coords( if image_shape is None: image_shape = coords_wrt_cam.shape[num_batch_dims:-1] - if dev_str is None: - dev_str = ivy.dev(coords_wrt_cam) + if device is None: + device = ivy.dev(coords_wrt_cam) # shapes as list batch_shape = list(batch_shape) @@ -715,7 +715,7 @@ def cam_to_world_coords( # BS x IS x 4 return ivy.concat( - (world_coords, ivy.ones(batch_shape + image_shape + [1], device=dev_str)), + (world_coords, ivy.ones(batch_shape + image_shape + [1], device=device)), axis=-1, ) @@ -961,7 +961,7 @@ def pixel_coords_to_world_ray_vectors( if pixel_coords is None: pixel_coords = create_uniform_pixel_coords_image( - image_shape, batch_shape, dev_str=ivy.dev(inv_full_mat) + image_shape, batch_shape, device=ivy.dev(inv_full_mat) ) # BS x [1]xNID x 3 @@ -1263,7 +1263,7 @@ def angular_pixel_to_sphere_coords(angular_pixel_coords, pixels_per_degree): def sphere_to_cam_coords( - sphere_coords, forward_facing_z=True, batch_shape=None, dev_str=None + sphere_coords, forward_facing_z=True, batch_shape=None, device=None ): r"""Convert camera-centric ego-sphere polar co-ordinates image :math:`\mathbf{S}_c\in\mathbb{R}^{bs×3}` to @@ -1279,7 +1279,7 @@ def sphere_to_cam_coords( Whether to use reference frame so z is forward facing. Default is False. batch_shape Shape of batch. Inferred from inputs if None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -1292,8 +1292,8 @@ def sphere_to_cam_coords( if batch_shape is None: batch_shape = sphere_coords.shape[:-1] - if dev_str is None: - dev_str = ivy.dev(sphere_coords) + if device is None: + device = ivy.dev(sphere_coords) # shapes as list batch_shape = list(batch_shape) @@ -1541,7 +1541,7 @@ def calib_mat_to_intrinsics_object(calib_mat, image_dims, batch_shape=None): def ext_mat_and_intrinsics_to_cam_geometry_object( - ext_mat, intrinsics, batch_shape=None, dev_str=None + ext_mat, intrinsics, batch_shape=None, device=None ): r"""Create camera geometry object from extrinsic matrix :math:`\mathbf{E}\in\mathbb{R}^{3×4}`, and camera intrinsics @@ -1555,7 +1555,7 @@ def ext_mat_and_intrinsics_to_cam_geometry_object( camera intrinsics object batch_shape Shape of batch. Inferred from inputs if None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -1568,8 +1568,8 @@ def ext_mat_and_intrinsics_to_cam_geometry_object( if batch_shape is None: batch_shape = ext_mat.shape[:-2] - if dev_str is None: - dev_str = ivy.dev(ext_mat) + if device is None: + device = ivy.dev(ext_mat) # shapes as list batch_shape = list(batch_shape) @@ -1583,7 +1583,7 @@ def ext_mat_and_intrinsics_to_cam_geometry_object( ext_mat, ivy.tile( ivy.reshape( - ivy.array([0.0, 0.0, 0.0, 1.0], device=dev_str), + ivy.array([0.0, 0.0, 0.0, 1.0], device=device), [1] * (num_batch_dims + 1) + [4], ), batch_shape + [1, 1], @@ -1619,7 +1619,7 @@ def ext_mat_and_intrinsics_to_cam_geometry_object( full_mat, ivy.tile( ivy.reshape( - ivy.array([0.0, 0.0, 0.0, 1.0], device=dev_str), + ivy.array([0.0, 0.0, 0.0, 1.0], device=device), [1] * (num_batch_dims + 1) + [4], ), batch_shape + [1, 1], @@ -1639,7 +1639,7 @@ def ext_mat_and_intrinsics_to_cam_geometry_object( def inv_ext_mat_and_intrinsics_to_cam_geometry_object( - inv_ext_mat, intrinsics, batch_shape=None, dev_str=None + inv_ext_mat, intrinsics, batch_shape=None, device=None ): r"""Create camera geometry object from inverse extrinsic matrix :math:`\mathbf{E}^{-1}\in\mathbb{R}^{3×4}`, and camera @@ -1653,7 +1653,7 @@ def inv_ext_mat_and_intrinsics_to_cam_geometry_object( camera intrinsics object batch_shape Shape of batch. Inferred from inputs if None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -1666,8 +1666,8 @@ def inv_ext_mat_and_intrinsics_to_cam_geometry_object( if batch_shape is None: batch_shape = inv_ext_mat.shape[:-2] - if dev_str is None: - dev_str = ivy.dev(inv_ext_mat) + if device is None: + device = ivy.dev(inv_ext_mat) # shapes as list batch_shape = list(batch_shape) @@ -1681,7 +1681,7 @@ def inv_ext_mat_and_intrinsics_to_cam_geometry_object( inv_ext_mat, ivy.tile( ivy.reshape( - ivy.array([0.0, 0.0, 0.0, 1.0], device=dev_str), + ivy.array([0.0, 0.0, 0.0, 1.0], device=device), [1] * (num_batch_dims + 1) + [4], ), batch_shape + [1, 1], @@ -1717,7 +1717,7 @@ def inv_ext_mat_and_intrinsics_to_cam_geometry_object( full_mat, ivy.tile( ivy.reshape( - ivy.array([0.0, 0.0, 0.0, 1.0], device=dev_str), + ivy.array([0.0, 0.0, 0.0, 1.0], device=device), [1] * (num_batch_dims + 1) + [4], ), batch_shape + [1, 1], diff --git a/ivy_vision/smoothing.py b/ivy_vision/smoothing.py index 5d913c09..06dbb09b 100644 --- a/ivy_vision/smoothing.py +++ b/ivy_vision/smoothing.py @@ -58,7 +58,7 @@ def weighted_image_smooth(mean, weights, kernel_dim): return new_mean, new_weights -def smooth_image_fom_var_image(mean, var, kernel_dim, kernel_scale, dev_str=None): +def smooth_image_fom_var_image(mean, var, kernel_dim, kernel_scale, device=None): """Smooth an image using variance values from a variance image of the same size, and a spatial smoothing kernel. @@ -73,7 +73,7 @@ def smooth_image_fom_var_image(mean, var, kernel_dim, kernel_scale, dev_str=None The dimension of the kernel kernel_scale The scale of the kernel along the channel dimension *[d]* - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -83,8 +83,8 @@ def smooth_image_fom_var_image(mean, var, kernel_dim, kernel_scale, dev_str=None Image smoothed based on variance image and smoothing kernel. """ - if dev_str is None: - dev_str = ivy.dev(mean) + if device is None: + device = ivy.dev(mean) # shapes as list kernel_shape = [kernel_dim, kernel_dim] @@ -93,7 +93,7 @@ def smooth_image_fom_var_image(mean, var, kernel_dim, kernel_scale, dev_str=None # KH x KW x 2 uniform_pixel_coords = ivy_svg.create_uniform_pixel_coords_image( - kernel_shape, dev_str=dev_str + kernel_shape, device=device )[..., 0:2] # 2 @@ -102,7 +102,7 @@ def smooth_image_fom_var_image(mean, var, kernel_dim, kernel_scale, dev_str=None float(math.floor(kernel_shape[0] / 2)), float(math.floor(kernel_shape[1] / 2)), ], - device=dev_str, + device=device, ) # KH x KW x 2 diff --git a/ivy_vision/two_view_geometry.py b/ivy_vision/two_view_geometry.py index f41b7dd7..58c8b6bb 100644 --- a/ivy_vision/two_view_geometry.py +++ b/ivy_vision/two_view_geometry.py @@ -14,7 +14,7 @@ def ds_pixel_to_ds_pixel_coords( - ds_pixel_coords1, cam1to2_full_mat, batch_shape=None, image_shape=None, dev_str=None + ds_pixel_coords1, cam1to2_full_mat, batch_shape=None, image_shape=None, device=None ): r"""Transform depth scaled homogeneous pixel co-ordinates image in first camera frame @@ -36,7 +36,7 @@ def ds_pixel_to_ds_pixel_coords( Shape of batch. Inferred from inputs if None. (Default value = None) image_shape Image shape. Inferred from inputs in None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -54,8 +54,8 @@ def ds_pixel_to_ds_pixel_coords( if image_shape is None: image_shape = ds_pixel_coords1.shape[num_batch_dims:-1] - if dev_str is None: - dev_str = ivy.dev(ds_pixel_coords1) + if device is None: + device = ivy.dev(ds_pixel_coords1) # shapes as list batch_shape = list(batch_shape) @@ -71,7 +71,7 @@ def ds_pixel_to_ds_pixel_coords( def cam_to_cam_coords( - cam_coords1, cam1to2_ext_mat, batch_shape=None, image_shape=None, dev_str=None + cam_coords1, cam1to2_ext_mat, batch_shape=None, image_shape=None, device=None ): r"""Transform camera-centric homogeneous co-ordinates image for camera 1 :math:`\mathbf{X}_{c1}\in\mathbb{R}^{is×4}` to @@ -90,7 +90,7 @@ def cam_to_cam_coords( Shape of batch. Inferred from inputs if None. (Default value = None) image_shape Image shape. Inferred from inputs in None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -108,8 +108,8 @@ def cam_to_cam_coords( if image_shape is None: image_shape = cam_coords1.shape[num_batch_dims:-1] - if dev_str is None: - dev_str = ivy.dev(cam_coords1) + if device is None: + device = ivy.dev(cam_coords1) # shapes as list batch_shape = list(batch_shape) @@ -238,7 +238,7 @@ def get_fundamental_matrix( camera_center1=None, pinv_full_mat1=None, batch_shape=None, - dev_str=None, + device=None, ): r"""Compute fundamental matrix :math:`\mathbf{F}\in\mathbb{R}^{3×3}` between two cameras, @@ -262,7 +262,7 @@ def get_fundamental_matrix( *[batch_shape,4,3]* (Default value = None) batch_shape Shape of batch. Inferred from inputs if None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -275,15 +275,15 @@ def get_fundamental_matrix( if batch_shape is None: batch_shape = full_mat1.shape[:-2] - if dev_str is None: - dev_str = ivy.dev(full_mat1) + if device is None: + device = ivy.dev(full_mat1) # shapes as list batch_shape = list(batch_shape) if camera_center1 is None: inv_full_mat1 = ivy.inv( - ivy_mech.make_transformation_homogeneous(full_mat1, batch_shape, dev_str) + ivy_mech.make_transformation_homogeneous(full_mat1, batch_shape, device) )[..., 0:3, :] camera_center1 = ivy_svg.inv_ext_mat_to_camera_center(inv_full_mat1) @@ -292,7 +292,7 @@ def get_fundamental_matrix( # BS x 4 x 1 camera_center1_homo = ivy.concat( - (camera_center1, ivy.ones(batch_shape + [1, 1], device=dev_str)), axis=-2 + (camera_center1, ivy.ones(batch_shape + [1, 1], device=device)), axis=-2 ) # BS x 3 @@ -307,7 +307,7 @@ def get_fundamental_matrix( # noinspection PyUnresolvedReferences def closest_mutual_points_along_two_skew_rays( - camera_centers, world_ray_vectors, batch_shape=None, image_shape=None, dev_str=None + camera_centers, world_ray_vectors, batch_shape=None, image_shape=None, device=None ): r"""Compute closest mutual homogeneous co-ordinates :math:`\mathbf{x}_{1,i,j}\in\mathbb{R}^{4}` and @@ -335,7 +335,7 @@ def closest_mutual_points_along_two_skew_rays( Shape of batch. Inferred from inputs if None. (Default value = None) image_shape Image dimensions. Inferred from inputs in None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -353,8 +353,8 @@ def closest_mutual_points_along_two_skew_rays( image_shape = world_ray_vectors.shape[num_batch_dims + 1 : -1] num_image_dims = len(image_shape) - if dev_str is None: - dev_str = ivy.dev(camera_centers) + if device is None: + device = ivy.dev(camera_centers) # shapes as list batch_shape = list(batch_shape) diff --git a/ivy_vision/voxel_grids.py b/ivy_vision/voxel_grids.py index c05cb60b..a7207ac7 100644 --- a/ivy_vision/voxel_grids.py +++ b/ivy_vision/voxel_grids.py @@ -13,7 +13,7 @@ def coords_to_voxel_grid( coord_bounds=None, features=None, batch_shape=None, - dev_str=None, + device=None, ): r"""Create voxel grid :math:`\mathbf{X}_v\in\mathbb{R}^{x×y×z×(3+N+1)}` from homogeneous co-ordinates :math:`\mathbf{X}_w\in\mathbb{R}^{num\_coords×4}`. Each @@ -45,7 +45,7 @@ def coords_to_voxel_grid( Features mapping to the same voxel are averaged. (Default value = None) batch_shape Shape of batch. Inferred from inputs if None. (Default value = None) - dev_str + device device on which to create the array 'cuda:0', 'cuda:1', 'cpu' etc. Same as x if None. (Default value = None) @@ -60,8 +60,8 @@ def coords_to_voxel_grid( if batch_shape is None: batch_shape = coords.shape[:-2] - if dev_str is None: - dev_str = ivy.dev(coords) + if device is None: + device = ivy.dev(coords) # shapes as list batch_shape = list(batch_shape) @@ -126,7 +126,7 @@ def coords_to_voxel_grid( else: # BS x N full_validity_mask = ivy.astype( - ivy.ones(batch_shape + [num_coords_per_batch], device=dev_str), "bool" + ivy.ones(batch_shape + [num_coords_per_batch], device=device), "bool" ) # BS x 1 x 3 @@ -186,7 +186,7 @@ def coords_to_voxel_grid( voxel_values_pruned_flat = ivy.concat( ( voxel_values_pruned_flat, - ivy.ones([total_num_valid_coords, 1], device=dev_str), + ivy.ones([total_num_valid_coords, 1], device=device), ), axis=-1, ) @@ -199,14 +199,14 @@ def coords_to_voxel_grid( else: max_dims = ivy.reshape(dims, batch_shape + [3]) batch_shape_array_list = ( - [ivy.array(batch_shape, dtype="int32", device=dev_str)] + [ivy.array(batch_shape, dtype="int32", device=device)] if num_batch_dims != 0 else [] ) total_dims_list = ivy.to_list( ivy.concat( batch_shape_array_list - + [max_dims, ivy.array([4 + feature_size], dtype="int32", device=dev_str)], + + [max_dims, ivy.array([4 + feature_size], dtype="int32", device=device)], axis=-1, ) ) diff --git a/ivy_vision_demos/interactive/coords_to_voxel_grid.py b/ivy_vision_demos/interactive/coords_to_voxel_grid.py index c5f124c4..5a56464b 100644 --- a/ivy_vision_demos/interactive/coords_to_voxel_grid.py +++ b/ivy_vision_demos/interactive/coords_to_voxel_grid.py @@ -142,10 +142,9 @@ def __init__(self, interactive, try_use_sim): plt.show() -def main(interactive=True, try_use_sim=True, f=None, fw=None): +def main(interactive=True, try_use_sim=True, fw=None): fw = ivy.choose_random_backend() if fw is None else fw ivy.set_backend(fw) - f = ivy.get_backend(backend=fw) if f is None else f sim = Simulator(interactive, try_use_sim) vis = Visualizer(ivy.to_numpy(sim.default_camera_ext_mat_homo)) @@ -205,5 +204,4 @@ def main(interactive=True, try_use_sim=True, f=None, fw=None): ) parsed_args = parser.parse_args() fw = parsed_args.backend - f = None if fw is None else ivy.get_backend(backend=fw) - main(not parsed_args.non_interactive, not parsed_args.no_sim, f=f, fw=fw) + main(not parsed_args.non_interactive, not parsed_args.no_sim, fw=fw) diff --git a/ivy_vision_demos/interactive/nerf.py b/ivy_vision_demos/interactive/nerf.py index e0777e92..28d751d5 100644 --- a/ivy_vision_demos/interactive/nerf.py +++ b/ivy_vision_demos/interactive/nerf.py @@ -13,22 +13,22 @@ class Model(ivy.Module): - def __init__(self, num_layers, layer_dim, embedding_length, dev_str=None): + def __init__(self, num_layers, layer_dim, embedding_length, device=None): self._num_layers = num_layers self._layer_dim = layer_dim self._embedding_length = embedding_length embedding_size = 3 + 3 * 2 * embedding_length - self._fc_layers = [ivy.Linear(embedding_size, layer_dim, device=dev_str)] + self._fc_layers = [ivy.Linear(embedding_size, layer_dim, device=device)] self._fc_layers += [ ivy.Linear( layer_dim + (embedding_size if i % 4 == 0 and i > 0 else 0), layer_dim, - device=dev_str, + device=device, ) for i in range(num_layers - 2) ] - self._fc_layers.append(ivy.Linear(layer_dim, 4, device=dev_str)) - super(Model, self).__init__(dev_str) + self._fc_layers.append(ivy.Linear(layer_dim, 4, device=device)) + super(Model, self).__init__(device) def _forward(self, x, feat=None, timestamps=None): embedding = ivy.fourier_encode( @@ -58,17 +58,15 @@ def __init__( with_tensor_splitting, compile_flag, interactive, - dev_str, - f, + device, fw, ): # ivy fw = ivy.choose_random_backend() if fw is None else fw ivy.set_backend(fw) - f = ivy.get_backend(backend=fw) if f is None else f - if dev_str: - ivy.set_default_device(dev_str) + if device: + ivy.set_default_device(device) ivy.seed(seed_value=0) # Load input images and poses @@ -124,7 +122,7 @@ def __init__( # tensor splitting self._with_tensor_splitting = with_tensor_splitting # if with_tensor_splitting: - # self._dev_manager = ivy.DevManager(dev_strs=[ivy.default_device()]) + # self._dev_manager = ivy.DevManager(devices=[ivy.default_device()]) # compile if compile_flag: @@ -371,8 +369,7 @@ def main( with_tensor_splitting, compile_flag, interactive=True, - dev_str=None, - f=None, + device=None, fw=None, ): nerf_demo = NerfDemo( @@ -383,8 +380,7 @@ def main( with_tensor_splitting, compile_flag, interactive, - dev_str, - f, + device, fw, ) nerf_demo.train() @@ -450,7 +446,6 @@ def main( ) parsed_args = parser.parse_args() fw = parsed_args.backend - f = None if fw is None else ivy.get_backend(backend=fw) main( parsed_args.iterations, parsed_args.samples_per_ray, @@ -460,6 +455,5 @@ def main( parsed_args.compile, not parsed_args.non_interactive, parsed_args.device, - f, fw, ) diff --git a/ivy_vision_demos/interactive/render_image.py b/ivy_vision_demos/interactive/render_image.py index 39a30fde..ac0c07ce 100644 --- a/ivy_vision_demos/interactive/render_image.py +++ b/ivy_vision_demos/interactive/render_image.py @@ -231,10 +231,9 @@ def __init__(self, interactive, try_use_sim): plt.show() -def main(interactive=True, try_use_sim=True, f=None, fw=None): +def main(interactive=True, try_use_sim=True, fw=None): fw = ivy.choose_random_backend() if fw is None else fw ivy.set_backend(fw) - f = ivy.get_backend(backend=fw) if f is None else f with_mxnet = ivy.current_backend_str() == "mxnet" if with_mxnet: @@ -388,5 +387,4 @@ def main(interactive=True, try_use_sim=True, f=None, fw=None): ) parsed_args = parser.parse_args() fw = parsed_args.backend - f = None if fw is None else ivy.get_backend(backend=fw) - main(not parsed_args.non_interactive, not parsed_args.no_sim, f, fw) + main(not parsed_args.non_interactive, not parsed_args.no_sim, fw) diff --git a/ivy_vision_demos/run_through.py b/ivy_vision_demos/run_through.py index d3a27c43..54f7e64a 100644 --- a/ivy_vision_demos/run_through.py +++ b/ivy_vision_demos/run_through.py @@ -325,7 +325,7 @@ def show_forward_warped_images(dep1, col1, f1_f_warp_no_db, f1_f_warp_w_db, dep_ plt.show() -def main(interactive=True, f=None, fw=None): +def main(interactive=True, fw=None): global INTERACTIVE INTERACTIVE = interactive @@ -335,7 +335,6 @@ def main(interactive=True, f=None, fw=None): # choose random framework fw = ivy.choose_random_backend() if fw is None else fw ivy.set_backend(fw) - f = ivy.get_backend(backend=fw) if f is None else f # Camera Geometry # # ----------------# @@ -558,5 +557,4 @@ def main(interactive=True, f=None, fw=None): ) parsed_args = parser.parse_args() fw = parsed_args.backend - f = None if fw is None else ivy.get_backend(backend=fw) - main(not parsed_args.non_interactive, f=f, fw=fw) + main(not parsed_args.non_interactive, fw=fw) diff --git a/ivy_vision_tests/test_implicit.py b/ivy_vision_tests/test_implicit.py index ba8b4913..d4577a01 100644 --- a/ivy_vision_tests/test_implicit.py +++ b/ivy_vision_tests/test_implicit.py @@ -111,7 +111,7 @@ def __init__(self): td = ImplicitTestData() -def test_downsampled_image_dims_from_desired_num_pixels(dev_str, fw): +def test_downsampled_image_dims_from_desired_num_pixels(device, fw): ivy.set_backend(fw) new_img_dims, num_pixels = ivy_imp.downsampled_image_dims_from_desired_num_pixels( [32, 32], 256 @@ -131,7 +131,7 @@ def test_downsampled_image_dims_from_desired_num_pixels(dev_str, fw): ivy.previous_backend() -def test_create_sampled_pixel_coords_image(dev_str, fw): +def test_create_sampled_pixel_coords_image(device, fw): if fw == "mxnet": # MXNet does not support clipping based on min or max specified as arrays pytest.skip() @@ -175,7 +175,7 @@ def test_create_sampled_pixel_coords_image(dev_str, fw): ivy.previous_backend() -def test_sample_images(dev_str, fw): +def test_sample_images(device, fw): if fw == "mxnet": # MXNet does not support splitting based on # section sizes, only number of sections as integer input @@ -193,7 +193,7 @@ def test_sample_images(dev_str, fw): ivy.previous_backend() -def test_sampled_volume_density_to_occupancy_probability(dev_str, fw): +def test_sampled_volume_density_to_occupancy_probability(device, fw): ivy.set_backend(fw) occ_prob = ivy_imp.sampled_volume_density_to_occupancy_probability( ivy.array(td.densities), ivy.array(td.inter_sample_distances) @@ -203,7 +203,7 @@ def test_sampled_volume_density_to_occupancy_probability(dev_str, fw): ivy.previous_backend() -def test_ray_termination_probabilities(dev_str, fw): +def test_ray_termination_probabilities(device, fw): ivy.set_backend(fw) ray_term_probs = ivy_imp.ray_termination_probabilities( ivy.array(td.densities), ivy.array(td.inter_sample_distances) @@ -213,7 +213,7 @@ def test_ray_termination_probabilities(dev_str, fw): ivy.previous_backend() -def test_stratified_sample(dev_str, fw): +def test_stratified_sample(device, fw): ivy.set_backend(fw) num = 10 res = ivy_imp.stratified_sample( @@ -226,7 +226,7 @@ def test_stratified_sample(dev_str, fw): ivy.previous_backend() -def test_render_rays_via_termination_probabilities(dev_str, fw): +def test_render_rays_via_termination_probabilities(device, fw): ivy.set_backend(fw) rendering, var = ivy_imp.render_rays_via_termination_probabilities( ivy.array(td.ray_term_probs), ivy.array(td.features), render_variance=True @@ -240,9 +240,7 @@ def test_render_rays_via_termination_probabilities(dev_str, fw): @pytest.mark.parametrize("with_features", [True, False]) @pytest.mark.parametrize("with_timestamps", [True, False]) -def test_render_implicit_features_and_depth( - dev_str, fw, with_features, with_timestamps -): +def test_render_implicit_features_and_depth(device, fw, with_features, with_timestamps): if fw == "mxnet": # MXNet does not support splitting with remainder pytest.skip() diff --git a/ivy_vision_tests/test_ivy_vision_demos.py b/ivy_vision_tests/test_ivy_vision_demos.py index a5a2e923..af770b01 100644 --- a/ivy_vision_tests/test_ivy_vision_demos.py +++ b/ivy_vision_tests/test_ivy_vision_demos.py @@ -6,47 +6,38 @@ import pytest -def test_demo_run_through(dev_str, f, fw): +def test_demo_run_through(device, fw): from ivy_vision_demos.run_through import main - if fw == "tensorflow_graph": - # these particular demos are only implemented in eager mode, without compilation - pytest.skip() - main(False, f=f, fw=fw) + main(False, fw=fw) @pytest.mark.parametrize("with_sim", [False]) -def test_demo_coords_to_voxel_grid(with_sim, dev_str, f, fw): +def test_demo_coords_to_voxel_grid(with_sim, device, fw): from ivy_vision_demos.interactive.coords_to_voxel_grid import main - if fw == "tensorflow_graph": - # these particular demos are only implemented in eager mode, without compilation - pytest.skip() - main(False, with_sim, f=f, fw=fw) + main(False, with_sim, fw=fw) @pytest.mark.parametrize("with_sim", [False]) -def test_demo_render_image(with_sim, dev_str, f, fw): +def test_demo_render_image(with_sim, device, fw): from ivy_vision_demos.interactive.render_image import main - if fw == "tensorflow_graph": - # these particular demos are only implemented in eager mode, without compilation - pytest.skip() - main(False, with_sim, f=f, fw=fw) + main(False, with_sim, fw=fw) @pytest.mark.parametrize("with_sim", [False]) -def test_demo_nerf(with_sim, dev_str, f, fw): +def test_demo_nerf(with_sim, device, fw): from ivy_vision_demos.interactive.nerf import main - if fw in ["numpy", "tensorflow_graph", "mxnet"]: + if fw in ["numpy", "mxnet"]: # NumPy does not support gradients # these particular demos are only implemented in eager mode, # without compilation # MXNet does not support splitting along an axis # with a remainder after division. pytest.skip() - main(1, 2, 1, 1, False, with_sim, f=f, fw=fw) + main(1, 2, 1, 1, False, with_sim, fw=fw) # cwd = os.getcwd() # os.remove(os.path.join(cwd, "nerf_video.mp4")) # shutil.rmtree(os.path.join(cwd, "nerf_renderings")) diff --git a/ivy_vision_tests/test_mesh.py b/ivy_vision_tests/test_mesh.py index 316764ce..c6d04282 100644 --- a/ivy_vision_tests/test_mesh.py +++ b/ivy_vision_tests/test_mesh.py @@ -98,11 +98,7 @@ def __init__(self): td = MeshTestData() -def test_rasterize_triangles(dev_str, fw): - if fw == "tensorflow_graph": - # the need to dynamically infer array shapes - # for scatter makes this only valid in eager mode currently - pytest.skip() +def test_rasterize_triangles(device, fw): ivy.set_backend(fw) assert np.allclose( ivy_mesh.rasterize_triangles(ivy.array(td.mesh_triangle), [3, 3]), @@ -121,7 +117,7 @@ def test_rasterize_triangles(dev_str, fw): ivy.previous_backend() -def test_create_trimesh_indices_for_image(dev_str, fw): +def test_create_trimesh_indices_for_image(device, fw): if fw == "mxnet": # mxnet matmul only support N-D*N-D array (N >= 3) pytest.skip() @@ -134,14 +130,14 @@ def test_create_trimesh_indices_for_image(dev_str, fw): ivy.previous_backend() -def test_coord_image_to_trimesh(dev_str, fw): +def test_coord_image_to_trimesh(device, fw): if fw == "mxnet": # mxnet matmul only support N-D*N-D array (N >= 3) pytest.skip() ivy.set_backend(fw) coord_img = ivy.array(td.coord_img.tolist()) vertices, trimesh_indices = ivy_mesh.coord_image_to_trimesh( - coord_img, batch_shape=[1], image_dims=[4, 3], dev_str=dev_str + coord_img, batch_shape=[1], image_dims=[4, 3], device=device ) assert np.allclose(vertices, td.tri_mesh_4x3_vertices, atol=1e-3) assert np.allclose(trimesh_indices, td.tri_mesh_4x3_indices, atol=1e-3) @@ -150,7 +146,7 @@ def test_coord_image_to_trimesh(dev_str, fw): ivy.array(td.coord_validity_img), batch_shape=[1], image_dims=[4, 3], - dev_str=dev_str, + device=device, ) assert np.allclose(vertices, td.tri_mesh_4x3_vertices, atol=1e-3) assert np.allclose(trimesh_indices, td.tri_mesh_4x3_valid_indices, atol=1e-3) diff --git a/ivy_vision_tests/test_optical_flow.py b/ivy_vision_tests/test_optical_flow.py index 20095826..3ec180cd 100644 --- a/ivy_vision_tests/test_optical_flow.py +++ b/ivy_vision_tests/test_optical_flow.py @@ -73,7 +73,7 @@ def __init__(self): td = OpticalFlowTestData() -def test_depth_from_flow_and_cam_poses(dev_str, fw): +def test_depth_from_flow_and_cam_poses(device, fw): assert np.allclose( ivy_flow.depth_from_flow_and_cam_mats( ivy.array(td.optical_flow), ivy.array(td.full_mats) @@ -90,7 +90,7 @@ def test_depth_from_flow_and_cam_poses(dev_str, fw): ) -def test_flow_from_depth_and_cam_poses(dev_str, fw): +def test_flow_from_depth_and_cam_poses(device, fw): assert np.allclose( ivy_flow.flow_from_depth_and_cam_mats( ivy.array(td.pixel_coords_to_scatter[:, 0:1]), @@ -109,7 +109,7 @@ def test_flow_from_depth_and_cam_poses(dev_str, fw): ) -def test_project_flow_to_epipolar_line(dev_str, fw): +def test_project_flow_to_epipolar_line(device, fw): assert np.allclose( ivy_flow.project_flow_to_epipolar_line( ivy.array(td.optical_flow), ivy.array(td.fund_mats[0]) @@ -126,7 +126,7 @@ def test_project_flow_to_epipolar_line(dev_str, fw): ) -def test_pixel_cost_volume(dev_str, fw): +def test_pixel_cost_volume(device, fw): assert np.allclose( ivy_flow.pixel_cost_volume( ivy.array(td.cv_image1.copy()), ivy.array(td.cv_image2.copy()), 1 @@ -143,7 +143,7 @@ def test_pixel_cost_volume(dev_str, fw): ) -def test_velocity_from_flow_cam_coords_and_cam_mats(dev_str, fw): +def test_velocity_from_flow_cam_coords_and_cam_mats(device, fw): assert ivy_flow.velocity_from_flow_cam_coords_and_cam_mats( ivy.array(td.optical_flow), ivy.array(td.cam_coords[:, 0]), @@ -153,7 +153,7 @@ def test_velocity_from_flow_cam_coords_and_cam_mats(dev_str, fw): ) -def test_project_cam_coords_with_object_transformations(dev_str, fw): +def test_project_cam_coords_with_object_transformations(device, fw): # test data np.random.seed(0) cam_coords_t = np.array( @@ -204,7 +204,7 @@ def test_project_cam_coords_with_object_transformations(dev_str, fw): ) -def test_velocity_from_cam_coords_id_image_and_object_trans(dev_str, fw): +def test_velocity_from_cam_coords_id_image_and_object_trans(device, fw): # test data np.random.seed(0) cam_coords_t = np.array( @@ -251,7 +251,7 @@ def test_velocity_from_cam_coords_id_image_and_object_trans(dev_str, fw): ) -def test_flow_from_cam_coords_id_image_and_object_trans(dev_str, fw): +def test_flow_from_cam_coords_id_image_and_object_trans(device, fw): # test data np.random.seed(0) cam_coords_1 = np.array( diff --git a/ivy_vision_tests/test_padding.py b/ivy_vision_tests/test_padding.py index 9cc270c5..d2b4066e 100644 --- a/ivy_vision_tests/test_padding.py +++ b/ivy_vision_tests/test_padding.py @@ -39,7 +39,7 @@ def __init__(self): td = PaddingTestData() -def test_pad_omni_image(dev_str, fw): +def test_pad_omni_image(device, fw): ivy.set_backend(fw) assert np.allclose( ivy_pad.pad_omni_image(ivy.array(td.omni_image), 1), diff --git a/ivy_vision_tests/test_projective_geometry.py b/ivy_vision_tests/test_projective_geometry.py index 153b7f73..e0a5c9db 100644 --- a/ivy_vision_tests/test_projective_geometry.py +++ b/ivy_vision_tests/test_projective_geometry.py @@ -21,7 +21,7 @@ def __init__(self): td = ProjectiveGeometryTestData() -def test_transform(dev_str, fw): +def test_transform(device, fw): ivy.set_backend(fw) assert np.allclose( ivy_pg.transform(ivy.array(td.world_coords), ivy.array(td.ext_mats)), @@ -36,7 +36,7 @@ def test_transform(dev_str, fw): ivy.previous_backend() -def test_projection_matrix_pseudo_inverse(dev_str, fw): +def test_projection_matrix_pseudo_inverse(device, fw): ivy.set_backend(fw) assert np.allclose( ivy_pg.projection_matrix_pseudo_inverse(ivy.array(td.ext_mats)), @@ -51,7 +51,7 @@ def test_projection_matrix_pseudo_inverse(dev_str, fw): ivy.previous_backend() -def test_projection_matrix_inverse(dev_str, fw): +def test_projection_matrix_inverse(device, fw): ivy.set_backend(fw) assert np.allclose( ivy_pg.projection_matrix_inverse(ivy.array(td.ext_mats)), @@ -66,7 +66,7 @@ def test_projection_matrix_inverse(dev_str, fw): ivy.previous_backend() -def test_solve_homogeneous_dlt(dev_str, fw): +def test_solve_homogeneous_dlt(device, fw): ivy.set_backend(fw) assert np.allclose(ivy_pg.solve_homogeneous_dlt(ivy.array(td.A)), td.X, atol=1e-6) assert np.allclose( diff --git a/ivy_vision_tests/test_quantization.py b/ivy_vision_tests/test_quantization.py index a02374e2..17c62aa2 100644 --- a/ivy_vision_tests/test_quantization.py +++ b/ivy_vision_tests/test_quantization.py @@ -162,7 +162,7 @@ # self.validity_mask = self.quantized_counter > 0 -# def test_quantize_pixel_coords(dev_str, fw): +# def test_quantize_pixel_coords(device, fw): # td = QuantizationTestData() # mean, var, counter = ivy_quant.quantize_to_image( # td.pixel_coords_to_scatter, @@ -176,7 +176,7 @@ # assert np.allclose(var[..., 2:], td.quantized_cov_values, atol=1e-3) -# def test_quantize_pixel_coordinates_with_var(dev_str, fw): +# def test_quantize_pixel_coordinates_with_var(device, fw): # td = QuantizationTestData() # mean, var, counter = ivy_quant.quantize_to_image( # td.pixel_coords_to_scatter, @@ -195,7 +195,7 @@ # td.quantized_cov_values_from_cov, atol=1.5, rtol=1) -# def test_quantize_pixel_coords_with_var_db(dev_str, fw): +# def test_quantize_pixel_coords_with_var_db(device, fw): # td = QuantizationTestData() # mean, var, counter = ivy_quant.quantize_to_image( # td.pixel_coords_to_scatter, diff --git a/ivy_vision_tests/test_sdf.py b/ivy_vision_tests/test_sdf.py index 0ce8de4b..4f7d7e23 100644 --- a/ivy_vision_tests/test_sdf.py +++ b/ivy_vision_tests/test_sdf.py @@ -41,7 +41,7 @@ def __init__(self): td = SDFTestData() -def test_sphere_signed_distance(dev_str, fw): +def test_sphere_signed_distance(device, fw): ivy.set_backend(fw) assert np.allclose( ivy_sdf.sphere_signed_distances( @@ -64,7 +64,7 @@ def test_sphere_signed_distance(dev_str, fw): ivy.previous_backend() -def test_cuboid_signed_distance(dev_str, fw): +def test_cuboid_signed_distance(device, fw): ivy.set_backend(fw) assert np.allclose( ivy_sdf.cuboid_signed_distances( diff --git a/ivy_vision_tests/test_single_view_geometry.py b/ivy_vision_tests/test_single_view_geometry.py index e8974bb9..afdc1fe5 100644 --- a/ivy_vision_tests/test_single_view_geometry.py +++ b/ivy_vision_tests/test_single_view_geometry.py @@ -51,7 +51,7 @@ def __init__(self): td = SingleViewGeometryTestData() -def test_create_uniform_pixel_coords_image(dev_str, fw): +def test_create_uniform_pixel_coords_image(device, fw): assert np.array_equal( ivy_svg.create_uniform_pixel_coords_image( td.image_dims, (td.batch_size, td.num_cameras) @@ -65,58 +65,58 @@ def test_create_uniform_pixel_coords_image(dev_str, fw): ivy_svg.create_uniform_pixel_coords_image(td.image_dims, (td.num_cameras,), True) -def test_persp_angles_to_focal_lengths(dev_str, fw): +def test_persp_angles_to_focal_lengths(device, fw): assert np.allclose( ivy_svg.persp_angles_to_focal_lengths( - td.persp_angles, td.image_dims, dev_str=dev_str + td.persp_angles, td.image_dims, device=device ), td.focal_lengths, atol=1e-6, ) assert np.allclose( ivy_svg.persp_angles_to_focal_lengths( - td.persp_angles[0], td.image_dims, dev_str=dev_str + td.persp_angles[0], td.image_dims, device=device ), td.focal_lengths[0], atol=1e-6, ) -def test_focal_lengths_to_persp_angles(dev_str, fw): +def test_focal_lengths_to_persp_angles(device, fw): assert np.allclose( ivy_svg.focal_lengths_to_persp_angles( - ivy.array(td.focal_lengths), td.image_dims, dev_str=dev_str + ivy.array(td.focal_lengths), td.image_dims, device=device ), td.persp_angles, atol=1e-6, ) assert np.allclose( ivy_svg.focal_lengths_to_persp_angles( - ivy.array(td.focal_lengths[0]), td.image_dims, dev_str=dev_str + ivy.array(td.focal_lengths[0]), td.image_dims, device=device ), td.persp_angles[0], atol=1e-6, ) -def test_focal_lengths_and_pp_offsets_to_calib_mats(dev_str, fw): +def test_focal_lengths_and_pp_offsets_to_calib_mats(device, fw): assert np.allclose( ivy_svg.focal_lengths_and_pp_offsets_to_calib_mat( - ivy.array(td.focal_lengths), ivy.array(td.pp_offsets), dev_str=dev_str + ivy.array(td.focal_lengths), ivy.array(td.pp_offsets), device=device ), td.calib_mats, atol=1e-6, ) assert np.allclose( ivy_svg.focal_lengths_and_pp_offsets_to_calib_mat( - ivy.array(td.focal_lengths[0]), ivy.array(td.pp_offsets[0]), dev_str=dev_str + ivy.array(td.focal_lengths[0]), ivy.array(td.pp_offsets[0]), device=device ), td.calib_mats[0], atol=1e-6, ) -def test_rot_mats_and_cam_centers_to_ext_mats(dev_str, fw): +def test_rot_mats_and_cam_centers_to_ext_mats(device, fw): assert np.allclose( ivy_svg.rot_mat_and_cam_center_to_ext_mat( ivy.array(td.Rs), ivy.array(td.C_hats) @@ -133,7 +133,7 @@ def test_rot_mats_and_cam_centers_to_ext_mats(dev_str, fw): ) -def test_depth_to_ds_pixel_coords(dev_str, fw): +def test_depth_to_ds_pixel_coords(device, fw): assert np.allclose( ivy_svg.depth_to_ds_pixel_coords( ivy.array(td.depth_maps), ivy.array(td.uniform_pixel_coords) @@ -155,7 +155,7 @@ def test_depth_to_ds_pixel_coords(dev_str, fw): ) -def test_depth_to_radial_depth(dev_str, fw): +def test_depth_to_radial_depth(device, fw): assert np.allclose( ivy_svg.depth_to_radial_depth( ivy.array(td.depth_maps), ivy.array(td.inv_calib_mats) @@ -179,7 +179,7 @@ def test_depth_to_radial_depth(dev_str, fw): ) -def test_ds_pixel_coords_to_radial_depth(dev_str, fw): +def test_ds_pixel_coords_to_radial_depth(device, fw): assert np.allclose( ivy_svg.ds_pixel_coords_to_radial_depth( ivy.array(td.pixel_coords_to_scatter), ivy.array(td.inv_calib_mats) @@ -203,7 +203,7 @@ def test_ds_pixel_coords_to_radial_depth(dev_str, fw): ) -def test_cam_to_ds_pixel_coords(dev_str, fw): +def test_cam_to_ds_pixel_coords(device, fw): assert np.allclose( ivy_svg.cam_to_ds_pixel_coords( ivy.array(td.cam_coords), ivy.array(td.calib_mats) @@ -220,7 +220,7 @@ def test_cam_to_ds_pixel_coords(dev_str, fw): ) -def test_cam_coords_to_depth(dev_str, fw): +def test_cam_coords_to_depth(device, fw): assert np.allclose( ivy_svg.cam_coords_to_depth(ivy.array(td.cam_coords), ivy.array(td.calib_mats)), td.depth_maps, @@ -235,12 +235,12 @@ def test_cam_coords_to_depth(dev_str, fw): ) -def test_ds_pixel_to_cam_coords(dev_str, fw): +def test_ds_pixel_to_cam_coords(device, fw): assert np.allclose( ivy_svg.ds_pixel_to_cam_coords( ivy.array(td.pixel_coords_to_scatter), ivy.array(td.inv_calib_mats), - dev_str=dev_str, + device=device, ), td.cam_coords, atol=1e-6, @@ -249,17 +249,17 @@ def test_ds_pixel_to_cam_coords(dev_str, fw): ivy_svg.ds_pixel_to_cam_coords( ivy.array(td.pixel_coords_to_scatter[0]), ivy.array(td.inv_calib_mats[0]), - dev_str=dev_str, + device=device, ), td.cam_coords[0], atol=1e-6, ) -def test_depth_to_cam_coords(dev_str, fw): +def test_depth_to_cam_coords(device, fw): assert np.allclose( ivy_svg.depth_to_cam_coords( - ivy.array(td.depth_maps), ivy.array(td.inv_calib_mats), dev_str=dev_str + ivy.array(td.depth_maps), ivy.array(td.inv_calib_mats), device=device ), td.cam_coords, atol=1e-6, @@ -268,48 +268,48 @@ def test_depth_to_cam_coords(dev_str, fw): ivy_svg.depth_to_cam_coords( ivy.array(td.depth_maps[0]), ivy.array(td.inv_calib_mats[0]), - dev_str=dev_str, + device=device, ), td.cam_coords[0], atol=1e-6, ) -def test_world_to_cam_coords(dev_str, fw): +def test_world_to_cam_coords(device, fw): assert np.allclose( ivy_svg.world_to_cam_coords( - ivy.array(td.world_coords), ivy.array(td.ext_mats), dev_str=dev_str + ivy.array(td.world_coords), ivy.array(td.ext_mats), device=device ), td.cam_coords, atol=1e-6, ) assert np.allclose( ivy_svg.world_to_cam_coords( - ivy.array(td.world_coords[0]), ivy.array(td.ext_mats[0]), dev_str=dev_str + ivy.array(td.world_coords[0]), ivy.array(td.ext_mats[0]), device=device ), td.cam_coords[0], atol=1e-6, ) -def test_cam_to_world_coords(dev_str, fw): +def test_cam_to_world_coords(device, fw): assert np.allclose( ivy_svg.cam_to_world_coords( - ivy.array(td.cam_coords), ivy.array(td.inv_ext_mats), dev_str=dev_str + ivy.array(td.cam_coords), ivy.array(td.inv_ext_mats), device=device ), td.world_coords, atol=1e-6, ) assert np.allclose( ivy_svg.cam_to_world_coords( - ivy.array(td.cam_coords[0]), ivy.array(td.inv_ext_mats[0]), dev_str=dev_str + ivy.array(td.cam_coords[0]), ivy.array(td.inv_ext_mats[0]), device=device ), td.world_coords[0], atol=1e-6, ) -def test_world_to_ds_pixel_coords(dev_str, fw): +def test_world_to_ds_pixel_coords(device, fw): assert np.allclose( ivy_svg.world_to_ds_pixel_coords( ivy.array(td.world_coords), ivy.array(td.full_mats) @@ -326,7 +326,7 @@ def test_world_to_ds_pixel_coords(dev_str, fw): ) -def test_world_coords_to_depth(dev_str, fw): +def test_world_coords_to_depth(device, fw): assert np.allclose( ivy_svg.world_coords_to_depth( ivy.array(td.world_coords), ivy.array(td.full_mats) @@ -343,7 +343,7 @@ def test_world_coords_to_depth(dev_str, fw): ) -def test_ds_pixel_to_world_coords(dev_str, fw): +def test_ds_pixel_to_world_coords(device, fw): # with 2D image dimensions assert np.allclose( ivy_svg.ds_pixel_to_world_coords( @@ -371,7 +371,7 @@ def test_ds_pixel_to_world_coords(dev_str, fw): ) -def test_depth_to_world_coords(dev_str, fw): +def test_depth_to_world_coords(device, fw): assert np.allclose( ivy_svg.depth_to_world_coords( ivy.array(td.depth_maps), ivy.array(td.inv_full_mats) @@ -388,7 +388,7 @@ def test_depth_to_world_coords(dev_str, fw): ) -def test_pixel_coords_to_world_rays(dev_str, fw): +def test_pixel_coords_to_world_rays(device, fw): assert np.allclose( ivy_svg.pixel_coords_to_world_ray_vectors( ivy.array(td.inv_full_mats), ivy.array(td.pixel_coords_to_scatter) @@ -405,7 +405,7 @@ def test_pixel_coords_to_world_rays(dev_str, fw): ) -def test_sphere_coords_to_world_ray_vectors(dev_str, fw): +def test_sphere_coords_to_world_ray_vectors(device, fw): assert np.allclose( ivy_svg.sphere_coords_to_world_ray_vectors( ivy.array(td.sphere_coords.data), ivy.array(td.inv_Rs) @@ -422,7 +422,7 @@ def test_sphere_coords_to_world_ray_vectors(dev_str, fw): ) -def test_bilinearly_interpolate_image(dev_str, fw): +def test_bilinearly_interpolate_image(device, fw): assert np.allclose( ivy_svg.bilinearly_interpolate_image( td.world_coords, td.uniform_pixel_coords[:, :, :, :, 0:2] @@ -444,7 +444,7 @@ def test_bilinearly_interpolate_image(dev_str, fw): ) -def test_inv_ext_mat_to_camera_center(dev_str, fw): +def test_inv_ext_mat_to_camera_center(device, fw): assert np.allclose( ivy_svg.inv_ext_mat_to_camera_center(td.inv_ext_mats), td.C_hats, atol=1e-6 ) @@ -455,7 +455,7 @@ def test_inv_ext_mat_to_camera_center(dev_str, fw): ) -def test_calib_and_ext_to_full_mat(dev_str, fw): +def test_calib_and_ext_to_full_mat(device, fw): assert np.allclose( ivy_svg.calib_and_ext_to_full_mat( ivy.array(td.calib_mats), ivy.array(td.ext_mats) @@ -472,7 +472,7 @@ def test_calib_and_ext_to_full_mat(dev_str, fw): ) -def test_cam_to_sphere_coords(dev_str, fw): +def test_cam_to_sphere_coords(device, fw): assert np.allclose( ivy_svg.cam_to_sphere_coords(ivy.array(td.cam_coords)), td.sphere_coords, @@ -485,7 +485,7 @@ def test_cam_to_sphere_coords(dev_str, fw): ) -def test_ds_pixel_to_sphere_coords(dev_str, fw): +def test_ds_pixel_to_sphere_coords(device, fw): assert np.allclose( ivy_svg.ds_pixel_to_sphere_coords( ivy.array(td.pixel_coords_to_scatter), ivy.array(td.inv_calib_mats) @@ -502,7 +502,7 @@ def test_ds_pixel_to_sphere_coords(dev_str, fw): ) -def test_angular_pixel_to_sphere_coords(dev_str, fw): +def test_angular_pixel_to_sphere_coords(device, fw): assert np.allclose( ivy_svg.angular_pixel_to_sphere_coords( ivy.array(td.angular_pixel_coords), td.pixels_per_degree @@ -519,20 +519,20 @@ def test_angular_pixel_to_sphere_coords(dev_str, fw): ) -def test_sphere_to_cam_coords(dev_str, fw): +def test_sphere_to_cam_coords(device, fw): assert np.allclose( - ivy_svg.sphere_to_cam_coords(ivy.array(td.sphere_coords.data), dev_str=dev_str), + ivy_svg.sphere_to_cam_coords(ivy.array(td.sphere_coords.data), device=device), td.cam_coords, atol=1e-3, ) assert np.allclose( - ivy_svg.sphere_to_cam_coords(ivy.array(td.sphere_coords[0]), dev_str=dev_str), + ivy_svg.sphere_to_cam_coords(ivy.array(td.sphere_coords[0]), device=device), td.cam_coords[0], atol=1e-3, ) -def test_sphere_to_ds_pixel_coords(dev_str, fw): +def test_sphere_to_ds_pixel_coords(device, fw): assert np.allclose( ivy_svg.sphere_to_ds_pixel_coords( ivy.array(td.sphere_coords.data), ivy.array(td.calib_mats) @@ -549,7 +549,7 @@ def test_sphere_to_ds_pixel_coords(dev_str, fw): ) -def test_sphere_to_angular_pixel_coords(dev_str, fw): +def test_sphere_to_angular_pixel_coords(device, fw): assert np.allclose( ivy_svg.sphere_to_angular_pixel_coords( ivy.array(td.sphere_coords.data), td.pixels_per_degree diff --git a/ivy_vision_tests/test_smoothing.py b/ivy_vision_tests/test_smoothing.py index ddc1db09..ca29346e 100644 --- a/ivy_vision_tests/test_smoothing.py +++ b/ivy_vision_tests/test_smoothing.py @@ -44,7 +44,7 @@ def __init__(self): td = SmoothingTestData() -def test_weighted_image_smooth(dev_str, fw): +def test_weighted_image_smooth(device, fw): if fw in ["numpy", "jax"]: # numpy and jax do not yet support depthwise 2d convolutions pytest.skip() @@ -54,7 +54,7 @@ def test_weighted_image_smooth(dev_str, fw): assert np.allclose(mean_ret, td.smoothed_img_from_weights, atol=1e-6) -def test_smooth_image_fom_var_image(dev_str, fw): +def test_smooth_image_fom_var_image(device, fw): if fw in ["numpy", "jax"]: # numpy and jax do not yet support depthwise 2d convolutions pytest.skip() diff --git a/ivy_vision_tests/test_two_view_geometry.py b/ivy_vision_tests/test_two_view_geometry.py index 3e735636..996d9827 100644 --- a/ivy_vision_tests/test_two_view_geometry.py +++ b/ivy_vision_tests/test_two_view_geometry.py @@ -73,7 +73,7 @@ def __init__(self): td = TwoViewGeometryTestData() -def test_pixel_to_pixel_coords(dev_str, fw): +def test_pixel_to_pixel_coords(device, fw): ivy.set_backend(fw) assert np.allclose( ivy_tvg.ds_pixel_to_ds_pixel_coords( @@ -94,7 +94,7 @@ def test_pixel_to_pixel_coords(dev_str, fw): ivy.previous_backend() -def test_angular_pixel_to_angular_pixel_coords(dev_str, fw): +def test_angular_pixel_to_angular_pixel_coords(device, fw): ivy.set_backend(fw) assert np.allclose( ivy_tvg.angular_pixel_to_angular_pixel_coords( @@ -117,7 +117,7 @@ def test_angular_pixel_to_angular_pixel_coords(dev_str, fw): ivy.previous_backend() -def test_cam_to_cam_coords(dev_str, fw): +def test_cam_to_cam_coords(device, fw): ivy.set_backend(fw) assert np.allclose( ivy_tvg.cam_to_cam_coords( @@ -136,7 +136,7 @@ def test_cam_to_cam_coords(dev_str, fw): ivy.previous_backend() -def test_sphere_to_sphere_coords(dev_str, fw): +def test_sphere_to_sphere_coords(device, fw): ivy.set_backend(fw) assert np.allclose( ivy_tvg.sphere_to_sphere_coords( @@ -155,7 +155,7 @@ def test_sphere_to_sphere_coords(dev_str, fw): ivy.previous_backend() -def test_get_fundamental_matrix(dev_str, fw): +def test_get_fundamental_matrix(device, fw): ivy.set_backend(fw) assert np.allclose( ivy_tvg.get_fundamental_matrix( @@ -174,7 +174,7 @@ def test_get_fundamental_matrix(dev_str, fw): ivy.previous_backend() -def test_closest_mutual_points_along_two_skew_rays(dev_str, fw): +def test_closest_mutual_points_along_two_skew_rays(device, fw): ivy.set_backend(fw) closest_mutual_points = ivy_tvg.closest_mutual_points_along_two_skew_rays( ivy.array(td.C_hats), ivy.array(td.tvg_world_rays) @@ -190,7 +190,7 @@ def test_closest_mutual_points_along_two_skew_rays(dev_str, fw): ivy.previous_backend() -def test_triangulate_depth_by_closest_mutual_points(dev_str, fw): +def test_triangulate_depth_by_closest_mutual_points(device, fw): ivy.set_backend(fw) assert np.allclose( ivy_tvg.triangulate_depth( @@ -215,7 +215,7 @@ def test_triangulate_depth_by_closest_mutual_points(dev_str, fw): ivy.previous_backend() -def test_triangulate_depth_by_homogeneous_dlt(dev_str, fw): +def test_triangulate_depth_by_homogeneous_dlt(device, fw): ivy.set_backend(fw) assert np.allclose( ivy_tvg.triangulate_depth( diff --git a/ivy_vision_tests/test_voxel_grids.py b/ivy_vision_tests/test_voxel_grids.py index 29b22060..a78a4158 100644 --- a/ivy_vision_tests/test_voxel_grids.py +++ b/ivy_vision_tests/test_voxel_grids.py @@ -1,6 +1,5 @@ # global import ivy -import pytest import ivy.functional.backends.numpy as ivy_np import numpy as np @@ -85,11 +84,7 @@ def __init__(self): td = VoxelGridsTestData() -def test_world_coords_to_bounding_voxel_grid(dev_str, fw): - if fw == "tensorflow_graph": - # the need to dynamically infer array shapes - # for scatter makes this only valid in eager mode currently - pytest.skip() +def test_world_coords_to_bounding_voxel_grid(device, fw): assert np.allclose( np.sum( ivy_vg.coords_to_voxel_grid(