From 41c778a958c1efcd5e8448485ccc8714f31bbc9c Mon Sep 17 00:00:00 2001 From: haruishi43 Date: Wed, 17 Jan 2024 02:47:06 +0000 Subject: [PATCH] revise clipping for numpy and pytorch; now clips according to the input; also added argument for all functions --- equilib/cube2equi/base.py | 24 +++++++++++++++++++++--- equilib/cube2equi/numpy.py | 12 ++++++------ equilib/cube2equi/torch.py | 5 +++-- equilib/equi2cube/base.py | 9 ++++++++- equilib/equi2cube/numpy.py | 8 ++++---- equilib/equi2cube/torch.py | 12 +++++++----- equilib/equi2equi/base.py | 14 ++++++++++++-- equilib/equi2equi/numpy.py | 8 ++++---- equilib/equi2equi/torch.py | 8 ++++---- equilib/equi2pers/base.py | 7 +++++++ equilib/equi2pers/numpy.py | 8 ++------ equilib/equi2pers/torch.py | 8 ++------ equilib/grid_sample/torch/bicubic.py | 1 - equilib/grid_sample/torch/bilinear.py | 1 - scripts/draw_bfov.py | 1 - tests/cube2equi/numpy_run_baselines.py | 2 -- tests/cube2equi/torch_run.py | 3 --- tests/equi2cube/numpy_run_baselines.py | 4 +--- tests/equi2cube/torch_run.py | 6 ++---- tests/equi2equi/numpy_run_baselines.py | 2 -- tests/equi2equi/torch_run.py | 2 -- tests/equi2pers/numpy_convert_grid.py | 1 - tests/equi2pers/numpy_inv.py | 1 - tests/equi2pers/numpy_matmul.py | 1 - tests/equi2pers/numpy_run_baselines.py | 2 -- tests/equi2pers/torch_run.py | 2 -- tests/grid_sample/helpers.py | 6 ------ tests/grid_sample/numpy/baselines.py | 2 -- tests/grid_sample/torch/bicubic.py | 2 -- tests/grid_sample/torch/bilinear.py | 2 -- tests/grid_sample/torch/nearest.py | 3 --- tests/helpers/image_io.py | 3 --- tests/test_cube2equi/test_base.py | 2 -- tests/test_cube2equi/test_numpy.py | 1 - tests/test_cube2equi/test_torch.py | 2 -- tests/test_equi2cube/test_base.py | 2 -- tests/test_equi2cube/test_numpy.py | 3 +-- tests/test_equi2cube/test_torch.py | 6 ++---- tests/test_equi2equi/test_base.py | 2 -- tests/test_equi2equi/test_numpy.py | 1 - tests/test_equi2equi/test_torch.py | 2 -- tests/test_equi2pers/test_base.py | 2 -- tests/test_equi2pers/test_numpy.py | 1 - tests/test_equi2pers/test_torch.py | 2 -- tests/test_grid_sample/test_numpy.py | 3 --- tests/test_grid_sample/test_torch.py | 8 -------- 46 files changed, 86 insertions(+), 121 deletions(-) diff --git a/equilib/cube2equi/base.py b/equilib/cube2equi/base.py index 50171f32..db50ebde 100644 --- a/equilib/cube2equi/base.py +++ b/equilib/cube2equi/base.py @@ -46,11 +46,17 @@ class Cube2Equi(object): """ def __init__( - self, height: int, width: int, cube_format: str, mode: str = "bilinear" + self, + height: int, + width: int, + cube_format: str, + clip_output: bool = True, + mode: str = "bilinear", ) -> None: self.height = height self.width = width self.cube_format = cube_format + self.clip_output = clip_output self.mode = mode def __call__(self, cubemap: CubeMaps, **kwargs) -> ArrayLike: @@ -59,6 +65,7 @@ def __call__(self, cubemap: CubeMaps, **kwargs) -> ArrayLike: cube_format=self.cube_format, width=self.width, height=self.height, + clip_output=self.clip_output, mode=self.mode, **kwargs, ) @@ -69,6 +76,7 @@ def cube2equi( cube_format: str, height: int, width: int, + clip_output: bool = True, mode: str = "bilinear", **kwargs, ) -> ArrayLike: @@ -124,14 +132,24 @@ def cube2equi( cubemap=cubemap, cube_format=cube_format ) out = run_numpy( - horizon=horizon, height=height, width=width, mode=mode, **kwargs + horizon=horizon, + height=height, + width=width, + clip_output=clip_output, + mode=mode, + **kwargs, ) elif _type == "torch": horizon = convert2horizon_torch( cubemap=cubemap, cube_format=cube_format ) out = run_torch( - horizon=horizon, height=height, width=width, mode=mode, **kwargs + horizon=horizon, + height=height, + width=width, + clip_output=clip_output, + mode=mode, + **kwargs, ) else: raise ValueError("Oops something went wrong here") diff --git a/equilib/cube2equi/numpy.py b/equilib/cube2equi/numpy.py index 0f8bde4c..103c6deb 100644 --- a/equilib/cube2equi/numpy.py +++ b/equilib/cube2equi/numpy.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -from typing import Any, Callable, Dict, List, Optional, Union +from typing import Any, Callable, Dict, List, Optional, Tuple, Union import numpy as np @@ -153,8 +153,7 @@ def create_equi_grid( w_face: int, batch: int, dtype: np.dtype = np.dtype(np.float32), -) -> np.ndarray: - +) -> Tuple[np.ndarray, np.ndarray]: w_ratio = (w_out - 1) / w_out h_ratio = (h_out - 1) / h_out theta = np.linspace( @@ -224,7 +223,6 @@ def numpy_grid_sample( # FIXME: any way to do efficient batch? for i in range(b): - for y in range(grid_h): for x in range(grid_w): if ( @@ -258,6 +256,7 @@ def run( height: int, width: int, mode: str, + clip_output: bool = True, override_func: Optional[Callable[[], Any]] = None, ) -> np.ndarray: """Run Cube2Equi @@ -320,10 +319,11 @@ def run( img=horizon, grid=grid, out=out, cube_face_id=tp ) + # clip by the input out = ( out.astype(horizon_dtype) - if horizon_dtype == np.dtype(np.uint8) - else np.clip(out, np.nanmin(out), np.nanmax(out)) + if horizon_dtype == np.dtype(np.uint8) or not clip_output + else np.clip(out, np.min(horizon), np.max(horizon)) ) return out diff --git a/equilib/cube2equi/torch.py b/equilib/cube2equi/torch.py index 792f7430..20fdac34 100644 --- a/equilib/cube2equi/torch.py +++ b/equilib/cube2equi/torch.py @@ -250,6 +250,7 @@ def run( height: int, width: int, mode: str, + clip_output: bool = True, backend: str = "native", ) -> torch.Tensor: """Run Cube2Equi @@ -349,8 +350,8 @@ def run( out = ( out.type(horizon_dtype) - if horizon_dtype == torch.uint8 - else torch.clip(out, 0.0, 1.0) + if horizon_dtype == torch.uint8 or not clip_output + else torch.clip(out, torch.min(horizon), torch.max(horizon)) ) return out diff --git a/equilib/equi2cube/base.py b/equilib/equi2cube/base.py index 6182b64d..13d7bd7a 100644 --- a/equilib/equi2cube/base.py +++ b/equilib/equi2cube/base.py @@ -53,21 +53,25 @@ def __init__( w_face: int, cube_format: str, z_down: bool = False, + clip_output: bool = True, mode: str = "bilinear", ) -> None: self.w_face = w_face self.cube_format = cube_format self.z_down = z_down + self.clip_output = clip_output self.mode = mode - def __call__(self, equi: ArrayLike, rots: Rot) -> CubeMaps: + def __call__(self, equi: ArrayLike, rots: Rot, **kwargs) -> CubeMaps: return equi2cube( equi=equi, rots=rots, w_face=self.w_face, cube_format=self.cube_format, z_down=self.z_down, + clip_output=self.clip_output, mode=self.mode, + **kwargs, ) @@ -77,6 +81,7 @@ def equi2cube( w_face: int, cube_format: str, z_down: bool = False, + clip_output: bool = True, mode: str = "bilinear", **kwargs, ) -> CubeMaps: @@ -120,6 +125,7 @@ def equi2cube( w_face=w_face, cube_format=cube_format, z_down=z_down, + clip_output=clip_output, mode=mode, **kwargs, ) @@ -130,6 +136,7 @@ def equi2cube( w_face=w_face, cube_format=cube_format, z_down=z_down, + clip_output=clip_output, mode=mode, **kwargs, ) diff --git a/equilib/equi2cube/numpy.py b/equilib/equi2cube/numpy.py index c2f89516..820c9ab0 100644 --- a/equilib/equi2cube/numpy.py +++ b/equilib/equi2cube/numpy.py @@ -62,7 +62,6 @@ def cube_h2dice(cube_h: np.ndarray) -> np.ndarray: def matmul(m: np.ndarray, R: np.ndarray, method: str = "faster") -> np.ndarray: - if method == "robust": # When target image size is smaller, it might be faster with `matmul` # but not by much @@ -89,7 +88,6 @@ def matmul(m: np.ndarray, R: np.ndarray, method: str = "faster") -> np.ndarray: def convert_grid( xyz: np.ndarray, h_equi: int, w_equi: int, method: str = "robust" ) -> np.ndarray: - # convert to rotation phi = np.arcsin(xyz[..., 2] / np.linalg.norm(xyz, axis=-1)) theta = np.arctan2(xyz[..., 1], xyz[..., 0]) @@ -129,6 +127,7 @@ def run( cube_format: str, z_down: bool, mode: str, + clip_output: bool = True, override_func: Optional[Callable[[], Any]] = None, ) -> Union[np.ndarray, List[List[np.ndarray]], List[Dict[str, np.ndarray]]]: """Call Equi2Cube @@ -203,10 +202,11 @@ def run( else: out = numpy_grid_sample(img=equi, grid=grid, out=out, mode=mode) + # clip by input out = ( out.astype(equi_dtype) - if equi_dtype == np.dtype(np.uint8) - else np.clip(out, np.nanmin(out), np.nanmax(out)) + if equi_dtype == np.dtype(np.uint8) or not clip_output + else np.clip(out, np.min(equi), np.max(equi)) ) # reformat the output diff --git a/equilib/equi2cube/torch.py b/equilib/equi2cube/torch.py index 0df45e44..717730c2 100644 --- a/equilib/equi2cube/torch.py +++ b/equilib/equi2cube/torch.py @@ -76,7 +76,6 @@ def cube_h2dice(cube_h: torch.Tensor) -> torch.Tensor: def matmul(m: torch.Tensor, R: torch.Tensor) -> torch.Tensor: - M = torch.matmul(R[:, None, None, ...], m) M = M.squeeze(-1) @@ -86,7 +85,6 @@ def matmul(m: torch.Tensor, R: torch.Tensor) -> torch.Tensor: def convert_grid( xyz: torch.Tensor, h_equi: int, w_equi: int, method: str = "robust" ) -> torch.Tensor: - # convert to rotation phi = torch.asin(xyz[..., 2] / torch.norm(xyz, dim=-1)) theta = torch.atan2(xyz[..., 1], xyz[..., 0]) @@ -118,8 +116,11 @@ def run( cube_format: str, z_down: bool, mode: str, + clip_output: bool = True, backend: str = "native", -) -> Union[torch.Tensor, List[torch.Tensor], List[Dict[str, torch.Tensor]]]: +) -> Union[ + torch.Tensor, List[List[torch.Tensor]], List[Dict[str, torch.Tensor]] +]: """Run Equi2Cube params: @@ -232,10 +233,11 @@ def run( img=equi, grid=grid, out=out, mode=mode, backend=backend ) + # clip by input out = ( out.type(equi_dtype) - if equi_dtype == torch.uint8 - else torch.clip(out, 0.0, 1.0) + if equi_dtype == torch.uint8 or not clip_output + else torch.clip(out, torch.min(equi), torch.max(equi)) ) # reformat the output diff --git a/equilib/equi2equi/base.py b/equilib/equi2equi/base.py index b6ba17f6..1e1f7421 100644 --- a/equilib/equi2equi/base.py +++ b/equilib/equi2equi/base.py @@ -19,7 +19,7 @@ class Equi2Equi(object): """ params: - w_out, h_out (optional int): equi image size - - sampling_method (str): defaults to "default" + - clip_output (bool) whether to clip values in the range of input - mode (str): interpolation mode, defaults to "bilinear" - z_down (bool) @@ -35,23 +35,31 @@ def __init__( self, height: Optional[int] = None, width: Optional[int] = None, + clip_output: bool = True, mode: str = "bilinear", z_down: bool = False, ) -> None: self.height = height self.width = width + self.clip_output = clip_output self.mode = mode self.z_down = z_down def __call__(self, src: ArrayLike, rots: Rot, **kwargs) -> ArrayLike: return equi2equi( - src=src, rots=rots, mode=self.mode, z_down=self.z_down, **kwargs + src=src, + rots=rots, + clip_output=self.clip_output, + mode=self.mode, + z_down=self.z_down, + **kwargs, ) def equi2equi( src: ArrayLike, rots: Rot, + clip_output: bool = True, mode: str = "bilinear", z_down: bool = False, height: Optional[int] = None, @@ -98,6 +106,7 @@ def equi2equi( z_down=z_down, height=height, width=width, + clip_output=clip_output, **kwargs, ) elif _type == "torch": @@ -108,6 +117,7 @@ def equi2equi( z_down=z_down, height=height, width=width, + clip_output=clip_output, **kwargs, ) else: diff --git a/equilib/equi2equi/numpy.py b/equilib/equi2equi/numpy.py index 19f7828b..efd45007 100644 --- a/equilib/equi2equi/numpy.py +++ b/equilib/equi2equi/numpy.py @@ -9,7 +9,6 @@ def matmul(m: np.ndarray, R: np.ndarray, method: str = "faster") -> np.ndarray: - if method == "robust": # When target image size is smaller, it might be faster with `matmul` # but not by much @@ -36,7 +35,6 @@ def matmul(m: np.ndarray, R: np.ndarray, method: str = "faster") -> np.ndarray: def convert_grid( M: np.ndarray, h_equi: int, w_equi: int, method: str = "robust" ) -> np.ndarray: - # convert to rotation phi = np.arcsin(M[..., 2] / np.linalg.norm(M, axis=-1)) theta = np.arctan2(M[..., 1], M[..., 0]) @@ -81,6 +79,7 @@ def run( mode: str, height: Optional[int] = None, width: Optional[int] = None, + clip_output: bool = True, override_func: Optional[Callable[[], Any]] = None, ) -> np.ndarray: """Run Equi2Equi @@ -169,10 +168,11 @@ def run( else: out = numpy_grid_sample(img=src, grid=grid, out=out, mode=mode) + # clip by input out = ( out.astype(src_dtype) - if src_dtype == np.dtype(np.uint8) - else np.clip(out, np.nanmin(out), np.nanmax(out)) + if src_dtype == np.dtype(np.uint8) or not clip_output + else np.clip(out, np.min(src), np.max(src)) ) return out diff --git a/equilib/equi2equi/torch.py b/equilib/equi2equi/torch.py index 27a39fa6..2ef2ab26 100644 --- a/equilib/equi2equi/torch.py +++ b/equilib/equi2equi/torch.py @@ -14,7 +14,6 @@ def matmul(m: torch.Tensor, R: torch.Tensor) -> torch.Tensor: - M = torch.matmul(R[:, None, None, ...], m) M = M.squeeze(-1) @@ -24,7 +23,6 @@ def matmul(m: torch.Tensor, R: torch.Tensor) -> torch.Tensor: def convert_grid( M: torch.Tensor, h_equi: int, w_equi: int, method: str = "robust" ) -> torch.Tensor: - # convert to rotation phi = torch.asin(M[..., 2] / torch.norm(M, dim=-1)) theta = torch.atan2(M[..., 1], M[..., 0]) @@ -61,6 +59,7 @@ def run( mode: str, height: Optional[int] = None, width: Optional[int] = None, + clip_output: bool = True, backend: str = "native", ) -> torch.Tensor: """Run Equi2Equi @@ -191,10 +190,11 @@ def run( # NOTE: we assume that `out` keeps it's dtype + # clip by input out = ( out.type(src_dtype) - if src_dtype == torch.uint8 - else torch.clip(out, 0.0, 1.0) + if src_dtype == torch.uint8 or not clip_output + else torch.clip(out, torch.min(src), torch.max(src)) ) return out diff --git a/equilib/equi2pers/base.py b/equilib/equi2pers/base.py index c92055c5..749543ce 100644 --- a/equilib/equi2pers/base.py +++ b/equilib/equi2pers/base.py @@ -24,6 +24,7 @@ class Equi2Pers(object): - sampling_method (str) - z_down (bool) - mode (str) + - clip_output (bool) inputs: - equi (np.ndarray, torch.Tensor) @@ -42,6 +43,7 @@ def __init__( skew: float = 0.0, z_down: bool = False, mode: str = "bilinear", + clip_output: bool = True, ) -> None: self.height = height self.width = width @@ -49,6 +51,7 @@ def __init__( self.skew = skew self.mode = mode self.z_down = z_down + self.clip_output = clip_output # FIXME: maybe do useful stuff like precalculating the grid or something def __call__(self, equi: ArrayLike, rots: Rot, **kwargs) -> ArrayLike: @@ -65,6 +68,7 @@ def __call__(self, equi: ArrayLike, rots: Rot, **kwargs) -> ArrayLike: skew=self.skew, z_down=self.z_down, mode=self.mode, + clip_output=self.clip_output, **kwargs, ) @@ -89,6 +93,7 @@ def equi2pers( skew: float = 0.0, mode: str = "bilinear", z_down: bool = False, + clip_output: bool = True, **kwargs, ) -> ArrayLike: """ @@ -133,6 +138,7 @@ def equi2pers( fov_x=fov_x, skew=skew, z_down=z_down, + clip_output=clip_output, mode=mode, **kwargs, ) @@ -145,6 +151,7 @@ def equi2pers( fov_x=fov_x, skew=skew, z_down=z_down, + clip_output=clip_output, mode=mode, **kwargs, ) diff --git a/equilib/equi2pers/numpy.py b/equilib/equi2pers/numpy.py index 3799e6ff..19ecd733 100644 --- a/equilib/equi2pers/numpy.py +++ b/equilib/equi2pers/numpy.py @@ -22,7 +22,6 @@ def create_cam2global_matrix( skew: float = 0.0, dtype: np.dtype = np.dtype(np.float32), ) -> np.ndarray: - K = create_intrinsic_matrix( height=height, width=width, fov_x=fov_x, skew=skew, dtype=dtype ) @@ -42,7 +41,6 @@ def prep_matrices( skew: float = 0.0, dtype: np.dtype = np.dtype(np.float32), ) -> Tuple[np.ndarray, np.ndarray]: - m = create_grid(height=height, width=width, batch=batch, dtype=dtype) m = m[..., np.newaxis] G = create_cam2global_matrix( @@ -55,7 +53,6 @@ def prep_matrices( def matmul( m: np.ndarray, G: np.ndarray, R: np.ndarray, method: str = "faster" ) -> np.ndarray: - if method == "robust": # When target image size is smaller, it might be faster with `matmul` # but not by much @@ -83,7 +80,6 @@ def matmul( def convert_grid( M: np.ndarray, h_equi: int, w_equi: int, method: str = "robust" ) -> np.ndarray: - # convert to rotation phi = np.arcsin(M[..., 2] / np.linalg.norm(M, axis=-1)) theta = np.arctan2(M[..., 1], M[..., 0]) @@ -130,8 +126,8 @@ def run( skew: float, z_down: bool, mode: str, - override_func: Optional[Callable[[], Any]] = None, clip_output: bool = True, + override_func: Optional[Callable[[], Any]] = None, ) -> np.ndarray: """Run Equi2Pers @@ -226,7 +222,7 @@ def run( out = ( out.astype(equi_dtype) if equi_dtype == np.dtype(np.uint8) or not clip_output - else np.clip(out, np.nanmin(out), np.nanmax(out)) + else np.clip(out, np.min(equi), np.max(equi)) ) return out diff --git a/equilib/equi2pers/torch.py b/equilib/equi2pers/torch.py index 5ebf0923..4227bbd5 100644 --- a/equilib/equi2pers/torch.py +++ b/equilib/equi2pers/torch.py @@ -26,7 +26,6 @@ def create_cam2global_matrix( dtype: torch.dtype = torch.float32, device: torch.device = torch.device("cpu"), ) -> torch.Tensor: - K = create_intrinsic_matrix( height=height, width=width, @@ -49,7 +48,6 @@ def prep_matrices( dtype: torch.dtype = torch.float32, device: torch.device = torch.device("cpu"), ) -> Tuple[torch.Tensor, torch.Tensor]: - m = create_grid( height=height, width=width, batch=batch, dtype=dtype, device=device ) @@ -67,7 +65,6 @@ def prep_matrices( def matmul(m: torch.Tensor, G: torch.Tensor, R: torch.Tensor) -> torch.Tensor: - M = torch.matmul(torch.matmul(R, G)[:, None, None, ...], m) M = M.squeeze(-1) @@ -77,7 +74,6 @@ def matmul(m: torch.Tensor, G: torch.Tensor, R: torch.Tensor) -> torch.Tensor: def convert_grid( M: torch.Tensor, h_equi: int, w_equi: int, method: str = "robust" ) -> torch.Tensor: - # convert to rotation phi = torch.asin(M[..., 2] / torch.norm(M, dim=-1)) theta = torch.atan2(M[..., 1], M[..., 0]) @@ -116,8 +112,8 @@ def run( skew: float, z_down: bool, mode: str, - backend: str = "native", clip_output: bool = True, + backend: str = "native", ) -> torch.Tensor: """Run Equi2Pers @@ -244,7 +240,7 @@ def run( out = ( out.type(equi_dtype) if equi_dtype == torch.uint8 or not clip_output - else torch.clip(out, 0.0, 1.0) + else torch.clip(out, torch.min(equi), torch.max(equi)) ) return out diff --git a/equilib/grid_sample/torch/bicubic.py b/equilib/grid_sample/torch/bicubic.py index 27656231..cbe6f0e5 100644 --- a/equilib/grid_sample/torch/bicubic.py +++ b/equilib/grid_sample/torch/bicubic.py @@ -25,7 +25,6 @@ def kernel(s, a): def bicubic( img: torch.Tensor, grid: torch.Tensor, out: torch.Tensor ) -> torch.Tensor: - # FIXME: out being initialized doesn't really matter? b_in, c_in, h_in, w_in = img.shape diff --git a/equilib/grid_sample/torch/bilinear.py b/equilib/grid_sample/torch/bilinear.py index 37ca555a..b66705c6 100644 --- a/equilib/grid_sample/torch/bilinear.py +++ b/equilib/grid_sample/torch/bilinear.py @@ -18,7 +18,6 @@ def interp2d(q00, q10, q01, q11, dy, dx): def bilinear( img: torch.Tensor, grid: torch.Tensor, out: torch.Tensor ) -> torch.Tensor: - b, _, h, w = img.shape min_grid = torch.floor(grid).type(torch.int64) diff --git a/scripts/draw_bfov.py b/scripts/draw_bfov.py index 721e4963..baa22250 100644 --- a/scripts/draw_bfov.py +++ b/scripts/draw_bfov.py @@ -41,7 +41,6 @@ def preprocess( def draw_lines( equi: np.ndarray, points: np.ndarray, to_cv2: bool = False ) -> np.ndarray: - if to_cv2: equi = cv2.cvtColor(equi, cv2.COLOR_RGB2BGR) diff --git a/tests/cube2equi/numpy_run_baselines.py b/tests/cube2equi/numpy_run_baselines.py index 2f32b75a..40960cd8 100644 --- a/tests/cube2equi/numpy_run_baselines.py +++ b/tests/cube2equi/numpy_run_baselines.py @@ -49,7 +49,6 @@ def bench_baselines( dtype: np.dtype = np.dtype(np.float32), save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, (height, width):", bs, (height, width)) @@ -137,7 +136,6 @@ def bench_baselines( if __name__ == "__main__": - # parameters save_outputs = True diff --git a/tests/cube2equi/torch_run.py b/tests/cube2equi/torch_run.py index 0a859c69..f704c3a3 100644 --- a/tests/cube2equi/torch_run.py +++ b/tests/cube2equi/torch_run.py @@ -68,7 +68,6 @@ def bench_cpu( dtype: np.dtype = np.dtype(np.float32), save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, grid(height, width):", bs, (height, width)) @@ -184,7 +183,6 @@ def bench_gpu( torch_dtype: torch.dtype = torch.float32, save_outputs: bool = False, ) -> None: - device = torch.device("cuda") assert torch_dtype in (torch.float16, torch.float32, torch.float64) @@ -297,7 +295,6 @@ def bench_gpu( if __name__ == "__main__": - # parameters save_outputs = True diff --git a/tests/equi2cube/numpy_run_baselines.py b/tests/equi2cube/numpy_run_baselines.py index 2fa387ca..4bffbd89 100644 --- a/tests/equi2cube/numpy_run_baselines.py +++ b/tests/equi2cube/numpy_run_baselines.py @@ -56,7 +56,6 @@ def bench_baselines( rotation: str = "forward", save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, w_face:", bs, w_face) @@ -192,7 +191,7 @@ def bench_baselines( assert isinstance(out, list) for b in range(bs): assert isinstance(out[b], list) - for (i, face) in enumerate(["F", "R", "B", "L", "U", "D"]): + for i, face in enumerate(["F", "R", "B", "L", "U", "D"]): print() print(f">>> Testing batch: {b}, face: {face}") _out = out[b][i] @@ -343,7 +342,6 @@ def bench_baselines( if __name__ == "__main__": - # parameters save_outputs = True rotation = "pitch" # ('forward', 'pitch', 'yaw') diff --git a/tests/equi2cube/torch_run.py b/tests/equi2cube/torch_run.py index 19ca688e..7ced201f 100644 --- a/tests/equi2cube/torch_run.py +++ b/tests/equi2cube/torch_run.py @@ -71,7 +71,6 @@ def bench_cpu( rotation: str = "forward", save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, w_face:", bs, w_face) @@ -209,7 +208,7 @@ def bench_cpu( assert isinstance(native_out, list) for b in range(bs): assert isinstance(native_out[b], list) - for (i, face) in enumerate(["F", "R", "B", "L", "U", "D"]): + for i, face in enumerate(["F", "R", "B", "L", "U", "D"]): print() print(f">>> Testing batch: {b}, face: {face}") _numpy_out = torch.from_numpy(numpy_out[b][i]) @@ -370,7 +369,6 @@ def bench_gpu( rotation: str = "forward", save_outputs: bool = False, ) -> None: - device = torch.device("cuda") assert torch_dtype in (torch.float16, torch.float32, torch.float64) @@ -508,7 +506,7 @@ def bench_gpu( assert isinstance(native_out, list) for b in range(bs): assert isinstance(native_out[b], list) - for (i, face) in enumerate(["F", "R", "B", "L", "U", "D"]): + for i, face in enumerate(["F", "R", "B", "L", "U", "D"]): print() print(f">>> Testing batch: {b}, face: {face}") _numpy_out = ( diff --git a/tests/equi2equi/numpy_run_baselines.py b/tests/equi2equi/numpy_run_baselines.py index 761c08a3..ab8016a9 100644 --- a/tests/equi2equi/numpy_run_baselines.py +++ b/tests/equi2equi/numpy_run_baselines.py @@ -61,7 +61,6 @@ def bench_baselines( rotation: str = "forward", save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, grid(height, width):", bs, (height, width)) @@ -182,7 +181,6 @@ def bench_baselines( if __name__ == "__main__": - # parameters save_outputs = True rotation = "pitch" # ('forward', 'pitch', 'yaw') diff --git a/tests/equi2equi/torch_run.py b/tests/equi2equi/torch_run.py index 49be2ec2..b46f685a 100644 --- a/tests/equi2equi/torch_run.py +++ b/tests/equi2equi/torch_run.py @@ -76,7 +76,6 @@ def bench_cpu( rotation: str = "forward", save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, grid(height, width):", bs, (height, width)) @@ -218,7 +217,6 @@ def bench_gpu( rotation: str = "forward", save_outputs: bool = False, ) -> None: - device = torch.device("cuda") assert torch_dtype in (torch.float16, torch.float32, torch.float64) diff --git a/tests/equi2pers/numpy_convert_grid.py b/tests/equi2pers/numpy_convert_grid.py index 31dcf708..4cce699b 100644 --- a/tests/equi2pers/numpy_convert_grid.py +++ b/tests/equi2pers/numpy_convert_grid.py @@ -143,7 +143,6 @@ def refine_v4(phi, theta, h_equi, w_equi): def bench(): - h_equi = 2000 w_equi = 4000 diff --git a/tests/equi2pers/numpy_inv.py b/tests/equi2pers/numpy_inv.py index 4c14851a..a99d8e35 100644 --- a/tests/equi2pers/numpy_inv.py +++ b/tests/equi2pers/numpy_inv.py @@ -95,7 +95,6 @@ def vecinv(A): if __name__ == "__main__": - from numpy.linalg import inv as npinv # noqa np.random.seed(0) diff --git a/tests/equi2pers/numpy_matmul.py b/tests/equi2pers/numpy_matmul.py index 6362c32c..e50cb588 100644 --- a/tests/equi2pers/numpy_matmul.py +++ b/tests/equi2pers/numpy_matmul.py @@ -296,7 +296,6 @@ def bench_time(): def compare_accuracy(): - data = DATA[3] m, G, R = example(**data) args = {"R": R, "G": G, "m": m} diff --git a/tests/equi2pers/numpy_run_baselines.py b/tests/equi2pers/numpy_run_baselines.py index 668bbfed..4129960d 100644 --- a/tests/equi2pers/numpy_run_baselines.py +++ b/tests/equi2pers/numpy_run_baselines.py @@ -71,7 +71,6 @@ def bench_baselines( rotation: str = "forward", save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, grid(height, width, fov_x):", bs, (height, width, fov_x)) @@ -197,7 +196,6 @@ def bench_baselines( if __name__ == "__main__": - # parameters save_outputs = True rotation = "pitch" # ('forward', 'pitch', 'yaw') diff --git a/tests/equi2pers/torch_run.py b/tests/equi2pers/torch_run.py index be066f23..780533c6 100644 --- a/tests/equi2pers/torch_run.py +++ b/tests/equi2pers/torch_run.py @@ -79,7 +79,6 @@ def bench_cpu( rotation: str = "forward", save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, grid(height, width, fov_x):", bs, (height, width, fov_x)) @@ -231,7 +230,6 @@ def bench_gpu( rotation: str = "forward", save_outputs: bool = False, ) -> None: - device = torch.device("cuda") assert torch_dtype in (torch.float16, torch.float32, torch.float64) diff --git a/tests/grid_sample/helpers.py b/tests/grid_sample/helpers.py index 1d9792b1..8c80263a 100644 --- a/tests/grid_sample/helpers.py +++ b/tests/grid_sample/helpers.py @@ -34,7 +34,6 @@ def create_single_data( dtype_img: np.dtype = np.dtype(np.uint8), dtype_grid: np.dtype = np.dtype(np.float32), ) -> Tuple[np.ndarray, np.ndarray, np.ndarray]: - img = create_single_img(c=c, h=h, w=w, rand=rand_img, dtype=dtype_img) grid = create_single_grid( @@ -65,7 +64,6 @@ def create_batch_data( dtype_img: np.dtype = np.dtype(np.uint8), dtype_grid: np.dtype = np.dtype(np.float32), ) -> Tuple[np.ndarray, np.ndarray, np.ndarray]: - img = create_batch_img(b=b, c=c, h=h, w=w, rand=rand_img, dtype=dtype_img) grid = create_batch_grid( @@ -111,7 +109,6 @@ def create_single_img( rand: bool = False, dtype: np.dtype = np.dtype(np.uint8), ) -> np.ndarray: - if rand: img = (np.random.rand(c, h, w) * 255).astype(dtype) else: @@ -140,7 +137,6 @@ def create_batch_img( rand: bool = False, dtype: np.dtype = np.dtype(np.uint8), ) -> np.ndarray: - imgs = np.empty((b, c, h, w), dtype=dtype) for i in range(b): imgs[i, ...] = create_single_img(c, h, w, rand=rand, dtype=dtype) @@ -157,7 +153,6 @@ def create_single_grid( move: bool = False, dtype: np.dtype = np.dtype(np.float32), ) -> np.ndarray: - assert h >= h_grid and w >= w_grid assert dtype in NP_FLOATS @@ -220,7 +215,6 @@ def create_batch_grid( move: bool = False, dtype: np.dtype = np.dtype(np.float32), ) -> np.ndarray: - grids = np.empty((b, 2, h_grid, w_grid), dtype=dtype) for i in range(b): grids[i, ...] = create_single_grid( diff --git a/tests/grid_sample/numpy/baselines.py b/tests/grid_sample/numpy/baselines.py index d15f1a14..ec25f5cb 100644 --- a/tests/grid_sample/numpy/baselines.py +++ b/tests/grid_sample/numpy/baselines.py @@ -115,7 +115,6 @@ def old_scipy(img: np.ndarray, grid: np.ndarray, order: int = 1) -> np.ndarray: def grid_sample_scipy( img: np.ndarray, grid: np.ndarray, out: np.ndarray, mode: str = "bilinear" ) -> np.ndarray: - if mode == "nearest": out = baseline_scipy_nearest(img, grid, out) elif mode == "bilinear": @@ -182,7 +181,6 @@ def baseline_cv2( def grid_sample_cv2( img: np.ndarray, grid: np.ndarray, out: np.ndarray, mode: str = "bilinear" ) -> np.ndarray: - if mode == "nearest": out = baseline_cv2_nearest(img, grid, out) elif mode == "bilinear": diff --git a/tests/grid_sample/torch/bicubic.py b/tests/grid_sample/torch/bicubic.py index 83d4636a..8681de73 100644 --- a/tests/grid_sample/torch/bicubic.py +++ b/tests/grid_sample/torch/bicubic.py @@ -22,7 +22,6 @@ def naive_bicubic(img: torch.Tensor, grid: torch.Tensor) -> torch.Tensor: def faster_bicubic( img: torch.Tensor, grid: torch.Tensor, out: torch.Tensor ) -> torch.Tensor: - b_in, c_in, h_in, w_in = img.shape b_out, _, h_out, w_out = out.shape dtype = out.dtype @@ -143,7 +142,6 @@ def kernel(s, a): def compare_baseline(): - dtype_img = dtype_grid = np.dtype(np.float32) b = 1 c = 3 diff --git a/tests/grid_sample/torch/bilinear.py b/tests/grid_sample/torch/bilinear.py index 0cf39fcb..e7764e72 100644 --- a/tests/grid_sample/torch/bilinear.py +++ b/tests/grid_sample/torch/bilinear.py @@ -20,7 +20,6 @@ def naive_bilinear(img: torch.Tensor, grid: torch.Tensor) -> torch.Tensor: def faster_bilinear( img: torch.Tensor, grid: torch.Tensor, out: torch.Tensor ) -> torch.Tensor: - b_in, _, h_in, w_in = img.shape min_grid = torch.floor(grid).type(torch.int64) @@ -61,7 +60,6 @@ def interp2d(q00, q10, q01, q11, dy, dx): def compare_baseline(): - dtype_img = dtype_grid = np.dtype(np.float32) b = 16 c = 3 diff --git a/tests/grid_sample/torch/nearest.py b/tests/grid_sample/torch/nearest.py index 9927c8c0..6e50ab67 100644 --- a/tests/grid_sample/torch/nearest.py +++ b/tests/grid_sample/torch/nearest.py @@ -16,7 +16,6 @@ def old_naive_nearest(img: torch.Tensor, grid: torch.Tensor) -> torch.Tensor: - b_in, c_in, h_in, w_in = img.shape b_out, _, h_out, w_out = grid.shape dtype = img.dtype @@ -39,7 +38,6 @@ def old_naive_nearest(img: torch.Tensor, grid: torch.Tensor) -> torch.Tensor: def naive_nearest( img: torch.Tensor, grid: torch.Tensor, out: torch.Tensor ) -> torch.Tensor: - b_in, c_in, h_in, w_in = img.shape b_out, _, h_out, w_out = out.shape @@ -153,7 +151,6 @@ def check_gpu(): def compare_baseline(): - dtype_img = dtype_grid = np.dtype(np.float32) b = 2 c = 3 diff --git a/tests/helpers/image_io.py b/tests/helpers/image_io.py index d06328be..a9bec19c 100644 --- a/tests/helpers/image_io.py +++ b/tests/helpers/image_io.py @@ -52,7 +52,6 @@ def _open_as_cv2(img_path: str) -> np.ndarray: def load2numpy( img_path: str, dtype: np.dtype, is_cv2: bool = False ) -> np.ndarray: - assert os.path.exists(img_path), f"{img_path} doesn't exist" if is_cv2: # FIXME: currently only supports RGB @@ -79,7 +78,6 @@ def load2numpy( def load2torch( img_path: str, dtype: torch.dtype, is_cv2: bool = False ) -> torch.Tensor: - assert os.path.exists(img_path), f"{img_path} doesn't exist" if is_cv2: # FIXME: currently only supports RGB @@ -133,7 +131,6 @@ def _numpy2PIL(img: np.ndarray) -> Image.Image: def _torch2PIL(img: torch.Tensor) -> Image.Image: - if img.device == "cuda": # move to cpu img = img.to("cpu") diff --git a/tests/test_cube2equi/test_base.py b/tests/test_cube2equi/test_base.py index fad379ec..7a507755 100644 --- a/tests/test_cube2equi/test_base.py +++ b/tests/test_cube2equi/test_base.py @@ -98,7 +98,6 @@ def numpy_single( mode: str, dtype: np.dtype, ) -> None: - # print parameters for debugging print() print("grid(height, width):", (height, width)) @@ -127,7 +126,6 @@ def torch_single( mode: str, dtype: torch.dtype, ) -> None: - # print parameters for debugging print() print("grid(height, width):", (height, width)) diff --git a/tests/test_cube2equi/test_numpy.py b/tests/test_cube2equi/test_numpy.py index 61f0f89c..cec62f6a 100644 --- a/tests/test_cube2equi/test_numpy.py +++ b/tests/test_cube2equi/test_numpy.py @@ -56,7 +56,6 @@ def bench_baselines( dtype: np.dtype = np.dtype(np.float32), save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, (height, width):", bs, (height, width)) diff --git a/tests/test_cube2equi/test_torch.py b/tests/test_cube2equi/test_torch.py index 4bf09930..408eee58 100644 --- a/tests/test_cube2equi/test_torch.py +++ b/tests/test_cube2equi/test_torch.py @@ -72,7 +72,6 @@ def bench_cpu( dtype: np.dtype = np.dtype(np.float32), save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, grid(height, width):", bs, (height, width)) @@ -188,7 +187,6 @@ def bench_gpu( torch_dtype: torch.dtype = torch.float32, save_outputs: bool = False, ) -> None: - device = torch.device("cuda") assert torch_dtype in (torch.float16, torch.float32, torch.float64) diff --git a/tests/test_equi2cube/test_base.py b/tests/test_equi2cube/test_base.py index 766de338..33c764ef 100644 --- a/tests/test_equi2cube/test_base.py +++ b/tests/test_equi2cube/test_base.py @@ -62,7 +62,6 @@ def numpy_single( mode: str, dtype: np.dtype, ) -> None: - # print parameters for debugging print() print("w_face:", w_face) @@ -113,7 +112,6 @@ def torch_single( mode: str, dtype: torch.dtype, ) -> None: - # print parameters for debugging print() print("w_face:", w_face) diff --git a/tests/test_equi2cube/test_numpy.py b/tests/test_equi2cube/test_numpy.py index 6ef93df0..4f5984ad 100644 --- a/tests/test_equi2cube/test_numpy.py +++ b/tests/test_equi2cube/test_numpy.py @@ -69,7 +69,6 @@ def bench_baselines( rotation: str = "forward", save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, w_face:", bs, w_face) @@ -205,7 +204,7 @@ def bench_baselines( assert isinstance(out, list) for b in range(bs): assert isinstance(out[b], list) - for (i, face) in enumerate(["F", "R", "B", "L", "U", "D"]): + for i, face in enumerate(["F", "R", "B", "L", "U", "D"]): print() print(f">>> Testing batch: {b}, face: {face}") _out = out[b][i] diff --git a/tests/test_equi2cube/test_torch.py b/tests/test_equi2cube/test_torch.py index 0a203743..cda73262 100644 --- a/tests/test_equi2cube/test_torch.py +++ b/tests/test_equi2cube/test_torch.py @@ -79,7 +79,6 @@ def bench_cpu( rotation: str = "forward", save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, w_face:", bs, w_face) @@ -217,7 +216,7 @@ def bench_cpu( assert isinstance(native_out, list) for b in range(bs): assert isinstance(native_out[b], list) - for (i, face) in enumerate(["F", "R", "B", "L", "U", "D"]): + for i, face in enumerate(["F", "R", "B", "L", "U", "D"]): print() print(f">>> Testing batch: {b}, face: {face}") _numpy_out = torch.from_numpy(numpy_out[b][i]) @@ -378,7 +377,6 @@ def bench_gpu( rotation: str = "forward", save_outputs: bool = False, ) -> None: - device = torch.device("cuda") assert torch_dtype in (torch.float16, torch.float32, torch.float64) @@ -516,7 +514,7 @@ def bench_gpu( assert isinstance(native_out, list) for b in range(bs): assert isinstance(native_out[b], list) - for (i, face) in enumerate(["F", "R", "B", "L", "U", "D"]): + for i, face in enumerate(["F", "R", "B", "L", "U", "D"]): print() print(f">>> Testing batch: {b}, face: {face}") _numpy_out = ( diff --git a/tests/test_equi2equi/test_base.py b/tests/test_equi2equi/test_base.py index 74fbdf79..03d0ceb4 100644 --- a/tests/test_equi2equi/test_base.py +++ b/tests/test_equi2equi/test_base.py @@ -62,7 +62,6 @@ def numpy_single( mode: str, dtype: np.dtype, ) -> None: - # print parameters for debugging print() print("grid(height, width):", (height, width)) @@ -98,7 +97,6 @@ def torch_single( mode: str, dtype: torch.dtype, ) -> None: - # print parameters for debugging print() print("grid(height, width):", (height, width)) diff --git a/tests/test_equi2equi/test_numpy.py b/tests/test_equi2equi/test_numpy.py index 1ebfa995..bdffa190 100644 --- a/tests/test_equi2equi/test_numpy.py +++ b/tests/test_equi2equi/test_numpy.py @@ -70,7 +70,6 @@ def bench_baselines( rotation: str = "forward", save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, grid(height, width):", bs, (height, width)) diff --git a/tests/test_equi2equi/test_torch.py b/tests/test_equi2equi/test_torch.py index 341b008e..56192f51 100644 --- a/tests/test_equi2equi/test_torch.py +++ b/tests/test_equi2equi/test_torch.py @@ -80,7 +80,6 @@ def bench_cpu( rotation: str = "forward", save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, grid(height, width):", bs, (height, width)) @@ -225,7 +224,6 @@ def bench_gpu( rotation: str = "forward", save_outputs: bool = False, ) -> None: - device = torch.device("cuda") assert torch_dtype in (torch.float16, torch.float32, torch.float64) diff --git a/tests/test_equi2pers/test_base.py b/tests/test_equi2pers/test_base.py index c47718d3..72df7886 100644 --- a/tests/test_equi2pers/test_base.py +++ b/tests/test_equi2pers/test_base.py @@ -63,7 +63,6 @@ def numpy_single( mode: str, dtype: np.dtype, ) -> None: - # print parameters for debugging print() print("grid(height, width, fov_x):", (height, width, fov_x)) @@ -102,7 +101,6 @@ def torch_single( mode: str, dtype: torch.dtype, ) -> None: - # print parameters for debugging print() print("grid(height, width, fov_x):", (height, width, fov_x)) diff --git a/tests/test_equi2pers/test_numpy.py b/tests/test_equi2pers/test_numpy.py index 283f8f82..b64dc0f3 100644 --- a/tests/test_equi2pers/test_numpy.py +++ b/tests/test_equi2pers/test_numpy.py @@ -70,7 +70,6 @@ def bench_baselines( rotation: str = "forward", save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, grid(height, width, fov_x):", bs, (height, width, fov_x)) diff --git a/tests/test_equi2pers/test_torch.py b/tests/test_equi2pers/test_torch.py index 4733a194..b76ccf71 100644 --- a/tests/test_equi2pers/test_torch.py +++ b/tests/test_equi2pers/test_torch.py @@ -80,7 +80,6 @@ def bench_cpu( rotation: str = "forward", save_outputs: bool = False, ) -> None: - # print parameters for debugging print() print("bs, grid(height, width, fov_x):", bs, (height, width, fov_x)) @@ -229,7 +228,6 @@ def bench_gpu( rotation: str = "forward", save_outputs: bool = False, ) -> None: - device = torch.device("cuda") assert torch_dtype in (torch.float16, torch.float32, torch.float64) diff --git a/tests/test_grid_sample/test_numpy.py b/tests/test_grid_sample/test_numpy.py index 81d11375..0aa8d1e3 100644 --- a/tests/test_grid_sample/test_numpy.py +++ b/tests/test_grid_sample/test_numpy.py @@ -64,7 +64,6 @@ def test_against_bench( rand_img: bool, rand_grid: bool, ) -> None: - print("\n") print("dtype_img:", dtype_img, "dtype_grid:", dtype_grid) print("move:", move_grid) @@ -231,7 +230,6 @@ def test_against_cv2( rand_img: bool, rand_grid: bool, ) -> None: - print("\n") print("dtype_img:", dtype_img, "dtype_grid:", dtype_grid) print("move:", move_grid) @@ -342,7 +340,6 @@ def test_against_scipy( rand_img: bool, rand_grid: bool, ) -> None: - print("\n") print("dtype_img:", dtype_img, "dtype_grid:", dtype_grid) print("move:", move_grid) diff --git a/tests/test_grid_sample/test_torch.py b/tests/test_grid_sample/test_torch.py index 795fc020..165ac504 100644 --- a/tests/test_grid_sample/test_torch.py +++ b/tests/test_grid_sample/test_torch.py @@ -66,7 +66,6 @@ def test_faster_vs_pure_cpu( rand_grid: bool, dtype_tensor: torch.dtype, ) -> None: - print("\n") print("dtype_img:", dtype_img, "dtype_grid:", dtype_grid) print("move:", move_grid) @@ -188,7 +187,6 @@ def test_faster_vs_pure_gpu( rand_grid: bool, dtype_tensor: torch.dtype, ) -> None: - print("\n") print("dtype_img:", dtype_img, "dtype_grid:", dtype_grid) print("move:", move_grid) @@ -316,7 +314,6 @@ def test_native_vs_pure_cpu( rand_grid: bool, dtype_tensor: torch.dtype, ) -> None: - print("\n") print("dtype_img:", dtype_img, "dtype_grid:", dtype_grid) print("move:", move_grid) @@ -435,7 +432,6 @@ def test_native_vs_pure_gpu( rand_grid: bool, dtype_tensor: torch.dtype, ) -> None: - print("\n") print("dtype_img:", dtype_img, "dtype_grid:", dtype_grid) print("dtype_tensor:", dtype_tensor) @@ -555,7 +551,6 @@ def test_native_vs_cv2_cpu( rand_grid: bool, dtype_tensor: torch.dtype, ) -> None: - print("\n") print("dtype_img:", dtype_img, "dtype_grid:", dtype_grid) print("dtype_tensor:", dtype_tensor) @@ -679,7 +674,6 @@ def test_native_vs_cv2_gpu( rand_grid: bool, dtype_tensor: torch.dtype, ) -> None: - print("\n") print("dtype_img:", dtype_img, "dtype_grid:", dtype_grid) print("dtype_tensor:", dtype_tensor) @@ -805,7 +799,6 @@ def test_native_vs_scipy_cpu( rand_grid: bool, dtype_tensor: torch.dtype, ) -> None: - print("\n") print("dtype_img:", dtype_img, "dtype_grid:", dtype_grid) print("dtype_tensor:", dtype_tensor) @@ -932,7 +925,6 @@ def test_native_vs_scipy_gpu( rand_grid: bool, dtype_tensor: torch.dtype, ) -> None: - print("\n") print("dtype_img:", dtype_img, "dtype_grid:", dtype_grid) print("dtype_tensor:", dtype_tensor)