Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Fix unused variable found (#1250)

Edgar Riba2bd56d9db04e
diff --git a/kornia/augmentation/augmentation.py b/kornia/augmentation/augmentation.py
index 9f8706899..37a30c3ea 100644
--- a/kornia/augmentation/augmentation.py
+++ b/kornia/augmentation/augmentation.py
@@ -2047,7 +2047,6 @@ class RandomFisheye(GeometricAugmentationBase2D):
return data
def generate_parameters(self, shape: torch.Size) -> Dict[str, torch.Tensor]:
- B, _, _, _ = shape # batch_size
center_x = self.dist(self.center_x[:1], self.center_x[1:]).rsample(shape[:1])
center_y = self.dist(self.center_y[:1], self.center_y[1:]).rsample(shape[:1])
gamma = self.dist(self.gamma[:1], self.gamma[1:]).rsample(shape[:1])
@@ -2180,7 +2179,7 @@ class RandomThinPlateSpline(GeometricAugmentationBase2D):
self.dist = torch.distributions.Uniform(-scale, scale)
def generate_parameters(self, shape: torch.Size) -> Dict[str, torch.Tensor]:
- B, _, H, W = shape
+ B, _, _, _ = shape
src = torch.tensor([[[-1.0, -1.0], [-1.0, 1.0], [1.0, -1.0], [1.0, 1.0], [0.0, 0.0]]]).repeat(B, 1, 1) # Bx5x2
dst = src + self.dist.rsample(src.shape)
return dict(src=src, dst=dst)
diff --git a/kornia/color/rgb.py b/kornia/color/rgb.py
index b3b215b4d..b73d90c54 100644
--- a/kornia/color/rgb.py
+++ b/kornia/color/rgb.py
@@ -156,7 +156,7 @@ def rgba_to_rgb(image: torch.Tensor) -> torch.Tensor:
g_new: torch.Tensor = a_one * g + a * g
b_new: torch.Tensor = a_one * b + a * b
- return torch.cat([r, g, b], dim=-3)
+ return torch.cat([r_new, g_new, b_new], dim=-3)
def rgba_to_bgr(image: torch.Tensor) -> torch.Tensor:
diff --git a/kornia/enhance/equalization.py b/kornia/enhance/equalization.py
index f3e097430..0f5251274 100644
--- a/kornia/enhance/equalization.py
+++ b/kornia/enhance/equalization.py
@@ -182,7 +182,7 @@ def _map_luts(interp_tiles: torch.Tensor, luts: torch.Tensor) -> torch.Tensor:
# gh, gw -> 2x the number of tiles used to compute the histograms
# th, tw -> /2 the sizes of the tiles used to compute the histograms
- num_imgs, gh, gw, c, th, tw = interp_tiles.shape
+ num_imgs, gh, gw, c, _, _ = interp_tiles.shape
# precompute idxs for non corner regions (doing it in cpu seems slightly faster)
j_idxs = torch.empty(0, 4, dtype=torch.long)
diff --git a/kornia/enhance/histogram.py b/kornia/enhance/histogram.py
index eaeb5f1ec..625341927 100644
--- a/kornia/enhance/histogram.py
+++ b/kornia/enhance/histogram.py
@@ -143,8 +143,8 @@ def histogram2d(
torch.Size([2, 128, 128])
"""
- pdf1, kernel_values1 = marginal_pdf(x1.unsqueeze(2), bins, bandwidth, epsilon)
- pdf2, kernel_values2 = marginal_pdf(x2.unsqueeze(2), bins, bandwidth, epsilon)
+ _, kernel_values1 = marginal_pdf(x1.unsqueeze(2), bins, bandwidth, epsilon)
+ _, kernel_values2 = marginal_pdf(x2.unsqueeze(2), bins, bandwidth, epsilon)
pdf = joint_pdf(kernel_values1, kernel_values2)
@@ -215,19 +215,6 @@ def image_histogram2d(
if not isinstance(return_pdf, bool):
raise TypeError(f"Return_pdf type is not a bool. Got {type(return_pdf)}.")
- device = image.device
-
- if image.dim() == 4:
- batch_size, n_channels, height, width = image.size()
- elif image.dim() == 3:
- batch_size = 1
- n_channels, height, width = image.size()
- elif image.dim() == 2:
- height, width = image.size()
- batch_size, n_channels = 1, 1
- else:
- raise ValueError(f"Input values must be a tensor of the shape " f"BxCxHxW, CxHxW or HxW. Got {image.shape}.")
-
if bandwidth is None:
bandwidth = (max - min) / n_bins
if centers is None:
@@ -264,4 +251,4 @@ def image_histogram2d(
hist = hist.squeeze()
elif image.dim() == 3:
hist = hist.squeeze(0)
- return hist, torch.zeros_like(hist, dtype=hist.dtype, device=device)
+ return hist, torch.zeros_like(hist, dtype=hist.dtype, device=hist.device)
diff --git a/kornia/enhance/zca.py b/kornia/enhance/zca.py
index 35254c32a..2a913e84f 100644
--- a/kornia/enhance/zca.py
+++ b/kornia/enhance/zca.py
@@ -368,7 +368,6 @@ def linear_transform(
new_order: List[int] = perm.tolist()
inv_order: List[int] = perm_inv.tolist()
- N = inp_size[dim]
feature_sizes = torch.tensor(inp_size[0:dim] + inp_size[dim + 1 : :])
num_features: int = int(torch.prod(feature_sizes).item())
diff --git a/kornia/feature/affine_shape.py b/kornia/feature/affine_shape.py
index 494d362ba..05f33048c 100644
--- a/kornia/feature/affine_shape.py
+++ b/kornia/feature/affine_shape.py
@@ -48,7 +48,7 @@ class PatchAffineShapeEstimator(nn.Module):
raise TypeError(f"Input type is not a torch.Tensor. Got {type(patch)}")
if not len(patch.shape) == 4:
raise ValueError(f"Invalid input shape, we expect Bx1xHxW. Got: {patch.shape}")
- B, CH, W, H = patch.size()
+ _, CH, W, H = patch.size()
if (W != self.patch_size) or (H != self.patch_size) or (CH != 1):
raise TypeError(
"input shape should be must be [Bx1x{}x{}]. "
diff --git a/kornia/feature/laf.py b/kornia/feature/laf.py
index 9d7c21b84..63c73169f 100644
--- a/kornia/feature/laf.py
+++ b/kornia/feature/laf.py
@@ -343,7 +343,7 @@ def denormalize_laf(LAF: torch.Tensor, images: torch.Tensor) -> torch.Tensor:
- Output: :math:`(B, N, 2, 3)`
"""
raise_error_if_laf_is_not_valid(LAF)
- n, ch, h, w = images.size()
+ _, _, h, w = images.size()
wf = float(w)
hf = float(h)
min_size = min(hf, wf)
@@ -375,7 +375,7 @@ def normalize_laf(LAF: torch.Tensor, images: torch.Tensor) -> torch.Tensor:
- Output: :math:`(B, N, 2, 3)`
"""
raise_error_if_laf_is_not_valid(LAF)
- n, ch, h, w = images.size()
+ n, _, h, w = images.size()
wf: float = float(w)
hf: float = float(h)
min_size = min(hf, wf)
@@ -431,7 +431,7 @@ def extract_patches_simple(
nlaf: torch.Tensor = normalize_laf(laf, img)
else:
nlaf = laf
- num, ch, h, w = img.size()
+ _, ch, h, w = img.size()
B, N, _, _ = laf.size()
out = []
# for loop temporarily, to be refactored
@@ -470,7 +470,7 @@ def extract_patches_from_pyramid(
else:
nlaf = laf
B, N, _, _ = laf.size()
- num, ch, h, w = img.size()
+ _, ch, h, w = img.size()
scale = 2.0 * get_laf_scale(denormalize_laf(nlaf, img)) / float(PS)
half: float = 0.5
pyr_idx = (scale.log2() + half).relu().long()
@@ -478,7 +478,7 @@ def extract_patches_from_pyramid(
cur_pyr_level = 0
out = torch.zeros(B, N, ch, PS, PS).to(nlaf.dtype).to(nlaf.device)
while min(cur_img.size(2), cur_img.size(3)) >= PS:
- num, ch, h, w = cur_img.size()
+ _, ch, h, w = cur_img.size()
# for loop temporarily, to be refactored
for i in range(B):
scale_mask = (pyr_idx[i] == cur_pyr_level).squeeze()
@@ -512,7 +512,7 @@ def laf_is_inside_image(laf: torch.Tensor, images: torch.Tensor, border: int = 0
mask with shape :math:`(B, N)`.
"""
raise_error_if_laf_is_not_valid(laf)
- n, ch, h, w = images.size()
+ n, _, h, w = images.size()
pts: torch.Tensor = laf_to_boundary_points(laf, 12)
good_lafs_mask: torch.Tensor = (
(pts[..., 0] >= border) * (pts[..., 0] <= w - border) * (pts[..., 1] >= border) * (pts[..., 1] <= h - border)
diff --git a/kornia/feature/scale_space_detector.py b/kornia/feature/scale_space_detector.py
index ed49e2904..daa55cb6c 100644
--- a/kornia/feature/scale_space_detector.py
+++ b/kornia/feature/scale_space_detector.py
@@ -29,7 +29,6 @@ def _scale_index_to_scale(max_coords: torch.Tensor, sigmas: torch.Tensor, num_le
# Reshape for grid shape
B, N, _ = max_coords.shape
- L: int = sigmas.size(1)
scale_coords = max_coords[:, :, 0].contiguous().view(-1, 1, 1, 1)
# Replace the scale_x_y
out = torch.cat(
@@ -130,12 +129,11 @@ class ScaleSpaceDetector(nn.Module):
) -> Tuple[torch.Tensor, torch.Tensor]:
dev: torch.device = img.device
dtype: torch.dtype = img.dtype
- sp, sigmas, pix_dists = self.scale_pyr(img)
+ sp, sigmas, _ = self.scale_pyr(img)
all_responses = []
all_lafs = []
for oct_idx, octave in enumerate(sp):
sigmas_oct = sigmas[oct_idx]
- pix_dists_oct = pix_dists[oct_idx]
B, CH, L, H, W = octave.size()
# Run response function
diff --git a/kornia/geometry/camera/pinhole.py b/kornia/geometry/camera/pinhole.py
index f93f3954c..6f4fff3a5 100644
--- a/kornia/geometry/camera/pinhole.py
+++ b/kornia/geometry/camera/pinhole.py
@@ -602,7 +602,6 @@ def cam2pixel(cam_coords_src: torch.Tensor, dst_proj_src: torch.Tensor, eps: flo
)
if not len(dst_proj_src.shape) == 3 and dst_proj_src.shape[-2:] == (4, 4):
raise ValueError("Input dst_proj_src has to be in the shape of " "Bx4x4. Got {}".format(dst_proj_src.shape))
- b, h, w, _ = cam_coords_src.shape
# apply projection matrix to points
point_coords: torch.Tensor = transform_points(dst_proj_src[:, None], cam_coords_src)
x_coord: torch.Tensor = point_coords[..., 0]
diff --git a/kornia/geometry/depth.py b/kornia/geometry/depth.py
index 7bd409e79..daa978400 100644
--- a/kornia/geometry/depth.py
+++ b/kornia/geometry/depth.py
@@ -48,7 +48,7 @@ def depth_to_3d(depth: torch.Tensor, camera_matrix: torch.Tensor, normalize_poin
raise ValueError(f"Input camera_matrix must have a shape (B, 3, 3). " f"Got: {camera_matrix.shape}.")
# create base coordinates grid
- batch_size, _, height, width = depth.shape
+ _, _, height, width = depth.shape
points_2d: torch.Tensor = create_meshgrid(height, width, normalized_coordinates=False) # 1xHxWx2
points_2d = points_2d.to(depth.device).to(depth.dtype)
diff --git a/kornia/geometry/epipolar/projection.py b/kornia/geometry/epipolar/projection.py
index cb0edce0b..3ec574712 100644
--- a/kornia/geometry/epipolar/projection.py
+++ b/kornia/geometry/epipolar/projection.py
@@ -25,7 +25,7 @@ def intrinsics_like(focal: float, input: torch.Tensor) -> torch.Tensor:
if focal <= 0:
raise AssertionError(focal)
- B, _, H, W = input.shape
+ _, _, H, W = input.shape
intrinsics = numeric.eye_like(3, input)
intrinsics[..., 0, 0] *= focal
@@ -174,7 +174,7 @@ def _nullspace(A):
Return the smallest singular value and the corresponding vector.
"""
- u, s, vh = torch.svd(A)
+ _, s, vh = torch.svd(A)
return s[..., -1], vh[..., -1]
diff --git a/kornia/geometry/epipolar/triangulation.py b/kornia/geometry/epipolar/triangulation.py
index 29a23dca7..7e55352c5 100644
--- a/kornia/geometry/epipolar/triangulation.py
+++ b/kornia/geometry/epipolar/triangulation.py
@@ -58,7 +58,7 @@ def triangulate_points(
# 1. Solve the system Ax=0 with smallest eigenvalue
# 2. Return homogeneous coordinates
- U, S, V = torch.svd(X)
+ _, _, V = torch.svd(X)
points3d_h = V[..., -1]
points3d: torch.Tensor = kornia.convert_points_from_homogeneous(points3d_h)
diff --git a/kornia/geometry/homography.py b/kornia/geometry/homography.py
index 4eae988ee..6acb6c449 100644
--- a/kornia/geometry/homography.py
+++ b/kornia/geometry/homography.py
@@ -137,7 +137,7 @@ def find_homography_dlt(
A = A.transpose(-2, -1) @ w_diag @ A
try:
- U, S, V = torch.svd(A)
+ _, _, V = torch.svd(A)
except:
warnings.warn('SVD did not converge', RuntimeWarning)
return torch.empty((points1_norm.size(0), 3, 3), device=device, dtype=dtype)
@@ -169,7 +169,7 @@ def find_homography_dlt_iterated(
'''Function, which finds homography via iteratively-reweighted
least squares ToDo: add citation'''
H: torch.Tensor = find_homography_dlt(points1, points2, weights)
- for i in range(n_iter - 1):
+ for _ in range(n_iter - 1):
errors: torch.Tensor = symmetric_transfer_error(points1, points2, H, False)
weights_new: torch.Tensor = torch.exp(-errors / (2.0 * (soft_inl_th ** 2)))
H = find_homography_dlt(points1, points2, weights_new)
diff --git a/kornia/geometry/subpix/spatial_soft_argmax.py b/kornia/geometry/subpix/spatial_soft_argmax.py
index 029f1d0f7..f9987e928 100644
--- a/kornia/geometry/subpix/spatial_soft_argmax.py
+++ b/kornia/geometry/subpix/spatial_soft_argmax.py
@@ -597,7 +597,6 @@ def conv_quad_interp3d(
raise ValueError(f"Invalid input shape, we expect BxCxDxHxW. Got: {input.shape}")
B, CH, D, H, W = input.shape
- dev: torch.device = input.device
grid_global: torch.Tensor = create_meshgrid3d(D, H, W, False, device=input.device).permute(0, 4, 1, 2, 3)
grid_global = grid_global.to(input.dtype)
diff --git a/kornia/geometry/transform/elastic_transform.py b/kornia/geometry/transform/elastic_transform.py
index 279c31a93..9d11d4339 100644
--- a/kornia/geometry/transform/elastic_transform.py
+++ b/kornia/geometry/transform/elastic_transform.py
@@ -87,7 +87,7 @@ def elastic_transform2d(
disp = torch.cat([disp_x, disp_y], dim=1).permute(0, 2, 3, 1)
# Warp image based on displacement matrix
- b, c, h, w = image.shape
+ _, _, h, w = image.shape
grid = kornia.utils.create_meshgrid(h, w, device=image.device).to(image.dtype)
warped = F.grid_sample(image, (grid + disp).clamp(-1, 1), align_corners=align_corners, mode=mode)
diff --git a/kornia/geometry/transform/imgwarp.py b/kornia/geometry/transform/imgwarp.py
index a5b274c8c..4b320f130 100644
--- a/kornia/geometry/transform/imgwarp.py
+++ b/kornia/geometry/transform/imgwarp.py
@@ -100,7 +100,7 @@ def warp_perspective(
# set default value for align corners
align_corners = True
- B, C, H, W = src.size()
+ B, _, H, W = src.size()
h_out, w_out = dsize
# we normalize the 3x3 transformation matrix and convert to 3x4
@@ -278,7 +278,7 @@ def get_perspective_transform(src, dst):
)
# solve the system Ax = b
- X, LU = _torch_solve_cast(b, A)
+ X, _ = _torch_solve_cast(b, A)
# create variable to return
batch_size = src.shape[0]
@@ -779,7 +779,6 @@ def get_shear_matrix3d(
def _compute_shear_matrix_3d(sxy_tan, sxz_tan, syx_tan, syz_tan, szx_tan, szy_tan):
- zeros = torch.zeros_like(sxy_tan) # type: ignore
ones = torch.ones_like(sxy_tan) # type: ignore
m00, m10, m20 = ones, sxy_tan, sxz_tan
diff --git a/kornia/geometry/transform/projwarp.py b/kornia/geometry/transform/projwarp.py
index b8bf8af38..973cebe45 100644
--- a/kornia/geometry/transform/projwarp.py
+++ b/kornia/geometry/transform/projwarp.py
@@ -294,7 +294,7 @@ def get_perspective_transform3d(src: torch.Tensor, dst: torch.Tensor) -> torch.T
)
# solve the system Ax = b
- X, LU = _torch_solve_cast(b, A)
+ X, _ = _torch_solve_cast(b, A)
# create variable to return
batch_size = src.shape[0]
diff --git a/kornia/geometry/transform/pyramid.py b/kornia/geometry/transform/pyramid.py
index ab8e3ac84..d8edf3341 100644
--- a/kornia/geometry/transform/pyramid.py
+++ b/kornia/geometry/transform/pyramid.py
@@ -184,7 +184,7 @@ class ScalePyramid(nn.Module):
return cur_level, cur_sigma, pixel_distance
def forward(self, x: torch.Tensor) -> Tuple[List, List, List]: # type: ignore
- bs, ch, h, w = x.size()
+ bs, ch, _, _ = x.size()
cur_level, cur_sigma, pixel_distance = self.get_first_level(x)
sigmas = [cur_sigma * torch.ones(bs, self.n_levels + self.extra_levels).to(x.device).to(x.dtype)]
@@ -250,10 +250,11 @@ def pyrdown(input: torch.Tensor, border_type: str = 'reflect', align_corners: bo
if not len(input.shape) == 4:
raise ValueError(f"Invalid input shape, we expect BxCxHxW. Got: {input.shape}")
kernel: torch.Tensor = _get_pyramid_gaussian_kernel()
- b, c, height, width = input.shape
+ _, _, height, width = input.shape
# blur image
x_blur: torch.Tensor = filter2d(input, kernel, border_type)
+ # TODO: use kornia.geometry.resize/rescale
# downsample.
out: torch.Tensor = F.interpolate(
x_blur, size=(height // 2, width // 2), mode='bilinear', align_corners=align_corners
@@ -287,7 +288,8 @@ def pyrup(input: torch.Tensor, border_type: str = 'reflect', align_corners: bool
raise ValueError(f"Invalid input shape, we expect BxCxHxW. Got: {input.shape}")
kernel: torch.Tensor = _get_pyramid_gaussian_kernel()
# upsample tensor
- b, c, height, width = input.shape
+ _, _, height, width = input.shape
+ # TODO: use kornia.geometry.resize/rescale
x_up: torch.Tensor = F.interpolate(
input, size=(height * 2, width * 2), mode='bilinear', align_corners=align_corners
)
diff --git a/kornia/geometry/warp/depth_warper.py b/kornia/geometry/warp/depth_warper.py
index 2347919bb..ec9d8cf19 100644
--- a/kornia/geometry/warp/depth_warper.py
+++ b/kornia/geometry/warp/depth_warper.py
@@ -10,7 +10,7 @@ __all__ = ["depth_warp", "DepthWarper"]
class DepthWarper(_DepthWarper):
- __doc__ = _DepthWarper.__doc__
+ __doc__ = _DepthWarper.__doc__ # skipcq: PYL-W0612
def __init__(
self,
diff --git a/kornia/geometry/warp/homography_warper.py b/kornia/geometry/warp/homography_warper.py
index 3c1d93835..46936211c 100644
--- a/kornia/geometry/warp/homography_warper.py
+++ b/kornia/geometry/warp/homography_warper.py
@@ -19,7 +19,7 @@ __all__ = [
def warp_grid(grid: torch.Tensor, src_homo_dst: torch.Tensor) -> torch.Tensor:
- __doc__ = HMW.warp_grid.__doc__
+ __doc__ = HMW.warp_grid.__doc__ # skipcq: PYL-W0612
warnings.warn(
"`warp_grid` is deprecated and will be removed > 0.6.0. "
"Please use `kornia.geometry.transform.warp_grid instead.`",
@@ -30,7 +30,7 @@ def warp_grid(grid: torch.Tensor, src_homo_dst: torch.Tensor) -> torch.Tensor:
def warp_grid3d(grid: torch.Tensor, src_homo_dst: torch.Tensor) -> torch.Tensor:
- __doc__ = HMW.warp_grid3d.__doc__
+ __doc__ = HMW.warp_grid3d.__doc__ # skipcq: PYL-W0612
warnings.warn(
"`warp_grid3d` is deprecated. Please use `kornia.geometry.transform.warp_grid3d instead.`",
DeprecationWarning,
@@ -49,7 +49,7 @@ def homography_warp(
align_corners: bool = False,
normalized_coordinates: bool = True,
) -> torch.Tensor:
- __doc__ = HMW.homography_warp.__doc__
+ __doc__ = HMW.homography_warp.__doc__ # skipcq: PYL-W0612
warnings.warn(
"`homography_warp` is deprecated and will be removed > 0.6.0."
"Please use `kornia.geometry.transform.homography_warp instead.`",
@@ -70,7 +70,7 @@ def homography_warp3d(
align_corners: bool = False,
normalized_coordinates: bool = True,
) -> torch.Tensor:
- __doc__ = HMW.homography_warp3d.__doc__
+ __doc__ = HMW.homography_warp3d.__doc__ # skipcq: PYL-W0612
warnings.warn(
"`homography_warp3d` is deprecated and will be removed > 0.6.0. "
"Please use `kornia.geometry.transform.homography_warp3d instead.`",
@@ -83,7 +83,7 @@ def homography_warp3d(
class HomographyWarper(HMW.HomographyWarper):
- __doc__ = HMW.HomographyWarper.__doc__
+ __doc__ = HMW.HomographyWarper.__doc__ # skipcq: PYL-W0612
def __init__(
self,
@@ -110,7 +110,7 @@ def normal_transform_pixel(
device: Optional[torch.device] = None,
dtype: Optional[torch.dtype] = None,
) -> torch.Tensor:
- __doc__ = HMW.normal_transform_pixel.__doc__
+ __doc__ = HMW.normal_transform_pixel.__doc__ # skipcq: PYL-W0612
warnings.warn(
"`normal_transform_pixel` is deprecated and will be removed > 0.6.0."
"Please use `kornia.geometry.transform.normal_transform_pixel instead.`",
@@ -128,7 +128,7 @@ def normal_transform_pixel3d(
device: Optional[torch.device] = None,
dtype: Optional[torch.dtype] = None,
) -> torch.Tensor:
- __doc__ = HMW.normal_transform_pixel3d.__doc__
+ __doc__ = HMW.normal_transform_pixel3d.__doc__ # skipcq: PYL-W0612
warnings.warn(
"`normal_transform_pixel3d` is deprecated and will be removed > 0.6.0. "
"Please use `kornia.geometry.transform.normal_transform_pixel3d instead.`",
@@ -141,7 +141,7 @@ def normal_transform_pixel3d(
def normalize_homography(
dst_pix_trans_src_pix: torch.Tensor, dsize_src: Tuple[int, int], dsize_dst: Tuple[int, int]
) -> torch.Tensor:
- __doc__ = HMW.normalize_homography.__doc__
+ __doc__ = HMW.normalize_homography.__doc__ # skipcq: PYL-W0612
warnings.warn(
"`normalize_homography` is deprecated and will be removed > 0.6.0. "
"Please use `kornia.geometry.transform.normalize_homography instead.`",
@@ -154,7 +154,7 @@ def normalize_homography(
def normalize_homography3d(
dst_pix_trans_src_pix: torch.Tensor, dsize_src: Tuple[int, int, int], dsize_dst: Tuple[int, int, int]
) -> torch.Tensor:
- __doc__ = HMW.normalize_homography3d.__doc__
+ __doc__ = HMW.normalize_homography3d.__doc__ # skipcq: PYL-W0612
warnings.warn(
"`normalize_homography3d` is deprecated and will be removed > 0.6.0. "
"Please use `kornia.geometry.transform.normalize_homography3d instead.`",
diff --git a/test/augmentation/test_augmentation.py b/test/augmentation/test_augmentation.py
index 2ff86bfc6..5484e8bff 100644
--- a/test/augmentation/test_augmentation.py
+++ b/test/augmentation/test_augmentation.py
@@ -216,14 +216,12 @@ class CommonTests(BaseTester):
def _test_random_p_0_implementation(self, params):
augmentation = self._create_augmentation_from_params(**params, p=0.0, return_transform=False)
- expected_output_shape = torch.Size((2, 3, 4, 5))
test_input = torch.rand((2, 3, 4, 5), device=self.device, dtype=self.dtype)
output = augmentation(test_input)
assert (output == test_input).all()
def _test_random_p_0_return_transform_implementation(self, params):
augmentation = self._create_augmentation_from_params(**params, p=0.0, return_transform=True)
- expected_output_shape = torch.Size((2, 3, 4, 5))
expected_transformation_shape = torch.Size((2, 3, 3))
test_input = torch.rand((2, 3, 4, 5), device=self.device, dtype=self.dtype)
output, transformation = augmentation(test_input)
diff --git a/test/augmentation/test_augmentation_mix.py b/test/augmentation/test_augmentation_mix.py
index 873a57b7a..945730b39 100644
--- a/test/augmentation/test_augmentation_mix.py
+++ b/test/augmentation/test_augmentation_mix.py
@@ -42,7 +42,8 @@ class TestRandomMixUp:
[torch.ones(1, 3, 4, device=device, dtype=dtype), torch.zeros(1, 3, 4, device=device, dtype=dtype)]
)
label = torch.tensor([1, 0], device=device)
- lam = torch.tensor([0.0, 0.0], device=device, dtype=dtype)
+ # TODO(jian): where is it used ?
+ # lam = torch.tensor([0.0, 0.0], device=device, dtype=dtype)
expected = input.clone()
@@ -111,7 +112,8 @@ class TestRandomCutMix:
[torch.ones(1, 3, 4, device=device, dtype=dtype), torch.zeros(1, 3, 4, device=device, dtype=dtype)]
)
label = torch.tensor([1, 0], device=device)
- lam = torch.tensor([0.1320, 0.3074], device=device, dtype=dtype)
+ # TODO(jian): where is it used ?
+ # lam = torch.tensor([0.1320, 0.3074], device=device, dtype=dtype)
expected = torch.tensor(
[
@@ -215,7 +217,8 @@ class TestRandomCutMix:
[torch.ones(1, 3, 4, device=device, dtype=dtype), torch.zeros(1, 3, 4, device=device, dtype=dtype)]
)
label = torch.tensor([1, 0], device=device)
- lam = torch.tensor([0.0885, 0.0885], device=device, dtype=dtype)
+ # TODO(jian): where is it used ?
+ # lam = torch.tensor([0.0885, 0.0885], device=device, dtype=dtype)
expected = torch.tensor(
[
diff --git a/test/augmentation/test_backward.py b/test/augmentation/test_backward.py
index 174c7bde2..64a38de09 100644
--- a/test/augmentation/test_backward.py
+++ b/test/augmentation/test_backward.py
@@ -22,7 +22,6 @@ class TestColorJitterBackward:
@pytest.mark.parametrize("return_transform", [True, False])
@pytest.mark.parametrize("same_on_batch", [True, False])
def test_param(self, brightness, contrast, saturation, hue, return_transform, same_on_batch, device, dtype):
- count = 0
_brightness = (
brightness
diff --git a/test/augmentation/test_base.py b/test/augmentation/test_base.py
index ab1207d94..1ae78f7f3 100644
--- a/test/augmentation/test_base.py
+++ b/test/augmentation/test_base.py
@@ -163,8 +163,6 @@ class TestAugmentationBase2D:
augmentation = AugmentationBase2D(return_transform=True, p=1.0)
with patch.object(augmentation, "apply_transform", autospec=True) as apply_transform, patch.object(
- augmentation, "generate_parameters", autospec=True
- ) as generate_parameters, patch.object(
augmentation, "compute_transformation", autospec=True
) as compute_transformation:
diff --git a/test/augmentation/test_container.py b/test/augmentation/test_container.py
index 847ef4e66..dfe30c7b8 100644
--- a/test/augmentation/test_container.py
+++ b/test/augmentation/test_container.py
@@ -39,8 +39,8 @@ class TestVideoSequential:
def test_exception(self, shape, data_format, device, dtype):
aug_list = K.VideoSequential(K.ColorJitter(0.1, 0.1, 0.1, 0.1), data_format=data_format, same_on_frame=True)
with pytest.raises(AssertionError):
- input = torch.randn(*shape, device=device, dtype=dtype)
- output = aug_list(input)
+ img = torch.randn(*shape, device=device, dtype=dtype)
+ aug_list(img)
@pytest.mark.parametrize(
'augmentation',
@@ -193,7 +193,7 @@ class TestSequential:
)
out = aug(inp)
if aug.return_label:
- out, label = out
+ out, _ = out
if isinstance(out, (tuple,)):
assert out[0].shape == inp.shape
else:
@@ -227,7 +227,7 @@ class TestAugmentationSequential:
)
out = aug(inp)
if aug.return_label:
- out, label = out
+ out, _ = out
if return_transform and isinstance(out, (tuple, list)):
out = out[0]
assert out.shape[-3:] == inp.shape[-3:]
@@ -437,7 +437,7 @@ class TestPatchSequential:
input = torch.randn(*shape, device=device, dtype=dtype)
out = seq(input)
if seq.return_label:
- out, label = out
+ out, _ = out
assert out.shape[-3:] == input.shape[-3:]
reproducibility_test(input, seq)
diff --git a/test/augmentation/test_random_generator.py b/test/augmentation/test_random_generator.py
index d32967f12..6fafd25a0 100644
--- a/test/augmentation/test_random_generator.py
+++ b/test/augmentation/test_random_generator.py
@@ -468,7 +468,6 @@ class TestRandomCropGen(RandomGeneratorBaseTests):
def test_random_gen(self, device, dtype):
torch.manual_seed(42)
- degrees = torch.tensor([10, 20], device=device, dtype=dtype)
res = random_crop_generator(
batch_size=2,
input_size=(100, 100),
@@ -494,7 +493,6 @@ class TestRandomCropGen(RandomGeneratorBaseTests):
def test_same_on_batch(self, device, dtype):
torch.manual_seed(42)
- degrees = torch.tensor([10, 20], device=device, dtype=dtype)
res = random_crop_generator(
batch_size=2,
input_size=(100, 100),
@@ -589,7 +587,6 @@ class TestRandomCropSizeGen(RandomGeneratorBaseTests):
def test_same_on_batch(self, device, dtype):
torch.manual_seed(42)
- degrees = torch.tensor([10, 20])
res = random_crop_size_generator(
batch_size=8,
size=(100, 100),
diff --git a/test/enhance/test_adjust.py b/test/enhance/test_adjust.py
index 7556f6a59..b269c253c 100644
--- a/test/enhance/test_adjust.py
+++ b/test/enhance/test_adjust.py
@@ -781,19 +781,21 @@ class TestSharpness(BaseTester):
@pytest.mark.skip(reason="union type input")
@pytest.mark.jit
def test_jit(self, device, dtype):
- op = torch.jit.script(kornia.enhance.adjust.sharpness)
- op_script = torch.jit.script(op)
- inputs = torch.rand(2, 1, 3, 3).to(device=device, dtype=dtype)
- expected = op(input, 0.8)
- actual = op_script(input, 0.8)
+ op = TestSharpness.f
+ op_script = torch.jit.script(TestSharpness.f)
+ img = torch.rand(2, 1, 3, 3).to(device=device, dtype=dtype)
+ expected = op(img, 0.8)
+ actual = op_script(img, 0.8)
assert_close(actual, expected)
+ # TODO: update with module when exists
@pytest.mark.skip(reason="Not having it yet.")
@pytest.mark.nn
def test_module(self, device, dtype):
img = torch.ones(2, 3, 4, 4, device=device, dtype=dtype)
- # gray_ops = kornia.enhance.sharpness().to(device, dtype)
- # assert_close(gray_ops(img), f(img))
+ ops = TestSharpness.f
+ mod = TestSharpness.f
+ assert_close(ops(img), mod(img))
@pytest.mark.skipif(kornia.xla_is_available(), reason="issues with xla device")
@@ -871,20 +873,21 @@ class TestSolarize(BaseTester):
@pytest.mark.skip(reason="union type input")
@pytest.mark.jit
def test_jit(self, device, dtype):
- op = torch.jit.script(kornia.enhance.adjust.solarize)
+ op = TestSolarize.f
op_script = torch.jit.script(op)
- inputs = torch.rand(2, 1, 3, 3).to(device=device, dtype=dtype)
- expected = op(input, 0.8)
- actual = op_script(input, 0.8)
+ img = torch.rand(2, 1, 3, 3).to(device=device, dtype=dtype)
+ expected = op(img, 0.8)
+ actual = op_script(img, 0.8)
assert_close(actual, expected)
- # TODO: implement me
+ # TODO: update with module when exists
@pytest.mark.skip(reason="Not having it yet.")
@pytest.mark.nn
def test_module(self, device, dtype):
img = torch.ones(2, 3, 4, 4, device=device, dtype=dtype)
- # gray_ops = kornia.enhance.sharpness().to(device, dtype)
- # assert_close(gray_ops(img), f(img))
+ ops = TestSolarize.f
+ mod = TestSolarize.f
+ assert_close(ops(img), mod(img))
class TestPosterize(BaseTester):
@@ -952,17 +955,18 @@ class TestPosterize(BaseTester):
@pytest.mark.skip(reason="union type input")
@pytest.mark.jit
def test_jit(self, device, dtype):
- op = torch.jit.script(kornia.enhance.adjust.posterize)
+ op = TestPosterize.f
op_script = torch.jit.script(op)
- inputs = torch.rand(2, 1, 3, 3).to(device=device, dtype=dtype)
- expected = op(input, 8)
- actual = op_script(input, 8)
+ img = torch.rand(2, 1, 3, 3).to(device=device, dtype=dtype)
+ expected = op(img, 8)
+ actual = op_script(img, 8)
assert_close(actual, expected)
- # TODO: implement me
+ # TODO: update with module when exists
@pytest.mark.skip(reason="Not having it yet.")
@pytest.mark.nn
def test_module(self, device, dtype):
img = torch.ones(2, 3, 4, 4, device=device, dtype=dtype)
- # gray_ops = kornia.enhance.sharpness().to(device, dtype)
- # assert_close(gray_ops(img), f(img))
+ ops = TestPosterize.f
+ mod = TestPosterize.f
+ assert_close(ops(img), mod(img))
diff --git a/test/enhance/test_histogram.py b/test/enhance/test_histogram.py
index 3fa4e4309..c5e1a4bc0 100644
--- a/test/enhance/test_histogram.py
+++ b/test/enhance/test_histogram.py
@@ -45,7 +45,7 @@ class TestImageHistogram2d:
@pytest.mark.parametrize("kernel", ["triangular", "gaussian", "uniform", "epanechnikov"])
def test_jit(self, device, dtype, kernel):
input = torch.linspace(0, 255, 10, device=device, dtype=dtype)
- input_x, input_y = torch.meshgrid(input, input)
+ input_x, _ = torch.meshgrid(input, input)
inputs = (input_x, 0.0, 255.0, 10, None, None, False, kernel)
op = TestImageHistogram2d.fcn
@@ -56,19 +56,19 @@ class TestImageHistogram2d:
@pytest.mark.parametrize("kernel", ["triangular", "gaussian", "uniform", "epanechnikov"])
def test_uniform_hist(self, device, dtype, kernel):
input = torch.linspace(0, 255, 10, device=device, dtype=dtype)
- input_x, input_y = torch.meshgrid(input, input)
+ input_x, _ = torch.meshgrid(input, input)
if kernel == "gaussian":
bandwidth = 2 * 0.4 ** 2
else:
bandwidth = None
- hist, pdf = TestImageHistogram2d.fcn(input_x, 0.0, 255.0, 10, bandwidth=bandwidth, centers=input, kernel=kernel)
+ hist, _ = TestImageHistogram2d.fcn(input_x, 0.0, 255.0, 10, bandwidth=bandwidth, centers=input, kernel=kernel)
ans = 10 * torch.ones_like(hist)
assert_close(ans, hist)
@pytest.mark.parametrize("kernel", ["triangular", "gaussian", "uniform", "epanechnikov"])
def test_uniform_dist(self, device, dtype, kernel):
input = torch.linspace(0, 255, 10, device=device, dtype=dtype)
- input_x, input_y = torch.meshgrid(input, input)
+ input_x, _ = torch.meshgrid(input, input)
if kernel == "gaussian":
bandwidth = 2 * 0.4 ** 2
else:
diff --git a/test/feature/test_nms.py b/test/feature/test_nms.py
index 1fcba943e..ae331739d 100644
--- a/test/feature/test_nms.py
+++ b/test/feature/test_nms.py
@@ -50,7 +50,6 @@ class TestNMS2d:
assert_close(scores, expected, atol=1e-4, rtol=1e-3)
def test_gradcheck(self, device):
- k = 0.04
batch_size, channels, height, width = 1, 2, 5, 4
img = torch.rand(batch_size, channels, height, width, device=device)
img = utils.tensor_to_gradcheck_var(img) # to var
diff --git a/test/filters/test_blur.py b/test/filters/test_blur.py
index 19edaf855..e9c52c737 100644
--- a/test/filters/test_blur.py
+++ b/test/filters/test_blur.py
@@ -121,7 +121,6 @@ class TestBoxBlur:
kernel_size = (3, 3)
actual = kornia.filters.box_blur(inp, kernel_size)
- expected = actual
assert_close(actual, actual)
def test_gradcheck(self, device, dtype):
diff --git a/test/filters/test_blur_pool.py b/test/filters/test_blur_pool.py
index 34a655598..32b94cbaf 100644
--- a/test/filters/test_blur_pool.py
+++ b/test/filters/test_blur_pool.py
@@ -26,7 +26,6 @@ class TestMaxBlurPool:
kernel_size = 3
actual = kornia.filters.max_blur_pool2d(inp, kernel_size)
- expected = actual
assert_close(actual, actual)
def test_gradcheck(self, device, dtype):
@@ -77,7 +76,6 @@ class TestBlurPool:
kernel_size = 3
actual = kornia.filters.blur_pool2d(inp, kernel_size)
- expected = actual
assert_close(actual, actual)
def test_gradcheck(self, device, dtype):
diff --git a/test/filters/test_canny.py b/test/filters/test_canny.py
index 88392dff9..fe3bb7cd1 100644
--- a/test/filters/test_canny.py
+++ b/test/filters/test_canny.py
@@ -283,6 +283,6 @@ class TestCanny:
op = kornia.filters.canny
op_module = kornia.filters.Canny()
expected_magnitude, expected_edges = op(img)
- actual_magnitude, actual_edges = op(img)
+ actual_magnitude, actual_edges = op_module(img)
assert_close(actual_magnitude, expected_magnitude)
assert_close(actual_edges, expected_edges)
diff --git a/test/filters/test_filters.py b/test/filters/test_filters.py
index ecbbfebe0..23bdb3565 100644
--- a/test/filters/test_filters.py
+++ b/test/filters/test_filters.py
@@ -176,7 +176,6 @@ class TestFilter2D:
kernel = torch.ones(1, 2, 2, device=device, dtype=dtype)
actual = kornia.filter2d(inp, kernel)
- expected = actual
assert_close(actual, actual)
def test_gradcheck(self, device):
diff --git a/test/filters/test_median.py b/test/filters/test_median.py
index 3445eca9d..d27e73c06 100644
--- a/test/filters/test_median.py
+++ b/test/filters/test_median.py
@@ -49,7 +49,6 @@ class TestMedianBlur:
kernel_size = (3, 3)
actual = kornia.filters.median_blur(inp, kernel_size)
- expected = actual
assert_close(actual, actual)
@pytest.mark.xfail(reason="this tests is a bit unstable")
diff --git a/test/filters/test_motion.py b/test/filters/test_motion.py
index 19d9ec944..30ba78a40 100644
--- a/test/filters/test_motion.py
+++ b/test/filters/test_motion.py
@@ -42,7 +42,6 @@ class TestMotionBlur:
angle = 200.0
direction = 0.3
actual = kornia.filters.motion_blur(inp, kernel_size, angle, direction)
- expected = actual
assert_close(actual, actual)
def test_gradcheck(self, device, dtype):
diff --git a/test/geometry/calibration/test_undistort.py b/test/geometry/calibration/test_undistort.py
index 1c0f8a2c7..c635c38c2 100644
--- a/test/geometry/calibration/test_undistort.py
+++ b/test/geometry/calibration/test_undistort.py
@@ -31,7 +31,7 @@ class TestUndistortion:
distCoeff = torch.rand(B, Ndist, device=device, dtype=dtype)
pointsu = undistort_points(points, K, distCoeff)
- assert points.shape == (B, N, 2)
+ assert pointsu.shape == (B, N, 2)
def test_opencv_five_coeff(self, device, dtype):
# Test using 5 distortion coefficients
diff --git a/test/geometry/epipolar/test_essential.py b/test/geometry/epipolar/test_essential.py
index 6d5fd01eb..61a0651e8 100644
--- a/test/geometry/epipolar/test_essential.py
+++ b/test/geometry/epipolar/test_essential.py
@@ -315,7 +315,7 @@ class TestMotionFromEssentialChooseSolution:
R, t = epi.relative_camera_motion(scene['R1'], scene['t1'], scene['R2'], scene['t2'])
t = torch.nn.functional.normalize(t, dim=1)
- R_hat, t_hat, X_hat = epi.motion_from_essential_choose_solution(
+ R_hat, t_hat, _ = epi.motion_from_essential_choose_solution(
E_mat, scene['K1'], scene['K2'], scene['x1'], scene['x2']
)
diff --git a/test/geometry/epipolar/test_fundamental.py b/test/geometry/epipolar/test_fundamental.py
index 2b19fb940..0cb183794 100644
--- a/test/geometry/epipolar/test_fundamental.py
+++ b/test/geometry/epipolar/test_fundamental.py
@@ -28,7 +28,7 @@ class TestNormalizePoints:
def test_mean_std(self, device, dtype):
points = torch.tensor([[[0.0, 0.0], [0.0, 2.0], [1.0, 1.0], [1.0, 3.0]]], device=device, dtype=dtype)
- points_norm, trans = epi.normalize_points(points)
+ points_norm, _ = epi.normalize_points(points)
points_std, points_mean = torch.std_mean(points_norm, dim=1)
assert_close(points_mean, torch.zeros_like(points_mean))
diff --git a/test/geometry/test_conversions.py b/test/geometry/test_conversions.py
index 84ee5c0e7..d1f3a9ee9 100644
--- a/test/geometry/test_conversions.py
+++ b/test/geometry/test_conversions.py
@@ -971,7 +971,6 @@ def test_deg2rad(batch_shape, device, dtype, atol, rtol):
assert_close(x_deg, x_rad_to_deg, atol=atol, rtol=rtol)
- eps = torch.finfo(dtype).eps
assert gradcheck(kornia.deg2rad, (tensor_to_gradcheck_var(x_deg),), raise_exception=True)
diff --git a/test/geometry/test_linalg.py b/test/geometry/test_linalg.py
index 0a3d21839..f88cb052f 100644
--- a/test/geometry/test_linalg.py
+++ b/test/geometry/test_linalg.py
@@ -370,7 +370,7 @@ class TestTransformLAFs:
def test_gradcheck(self, device, dtype):
# generate input data
- batch_size, num_points, num_dims = 2, 3, 2
+ batch_size, num_points = 2, 3
eye_size = 3
points_src = torch.rand(batch_size, num_points, 2, 3, device=device, dtype=dtype)
dst_homo_src = utils.create_random_homography(batch_size, eye_size).to(device=device, dtype=dtype)
diff --git a/test/geometry/transform/test_affine.py b/test/geometry/transform/test_affine.py
index 8a3e3582a..1386e22b1 100644
--- a/test/geometry/transform/test_affine.py
+++ b/test/geometry/transform/test_affine.py
@@ -682,7 +682,7 @@ class TestAffine2d:
from torch import Tensor as T
- batch_size, ch, height, width = 1, 1, 96, 96
+ batch_size, _, height, width = 1, 1, 96, 96
angle, translations = 6.971339922894188, (0.0, -4.0)
scale, shear = [0.7785685905190581, 0.7785685905190581], [11.8235607082617, 7.06797949691645]
matrix_expected = T([[1.27536969, 4.26828945e-01, -3.2876e01], [2.18297196e-03, 1.29424165e00, -1.1717e01]])
diff --git a/test/geometry/transform/test_homography_warper.py b/test/geometry/transform/test_homography_warper.py
index 04d70ca95..0eef5b6e2 100644
--- a/test/geometry/transform/test_homography_warper.py
+++ b/test/geometry/transform/test_homography_warper.py
@@ -194,7 +194,7 @@ class TestHomographyWarper:
# instantiate warper
warper = kornia.HomographyWarper(height, width, align_corners=True)
- for i in range(self.num_tests):
+ for _ in range(self.num_tests):
# generate homography noise
homo_delta = torch.rand_like(dst_homo_src) * 0.3
@@ -254,7 +254,7 @@ class TestHomographyWarper:
# create base homography
dst_homo_src = utils.create_eye_batch(batch_size, eye_size, device=device, dtype=dtype)
- for i in range(self.num_tests):
+ for _ in range(self.num_tests):
# generate homography noise
homo_delta = torch.rand_like(dst_homo_src) * 0.3
diff --git a/test/geometry/transform/test_imgwarp.py b/test/geometry/transform/test_imgwarp.py
index 933db4fce..64751683b 100644
--- a/test/geometry/transform/test_imgwarp.py
+++ b/test/geometry/transform/test_imgwarp.py
@@ -459,7 +459,7 @@ class TestRemap:
grid = kornia.utils.create_meshgrid(height, width, normalized_coordinates=False, device=device).to(dtype)
grid += 1.0 # apply some shift
input_tuple = (img, grid[..., 0], grid[..., 1])
- op_traced = torch.jit.trace(op_script, input_tuple)
+ _ = torch.jit.trace(op_script, input_tuple)
# 2. Generate different input
batch_size, channels, height, width = 2, 2, 2, 5
diff --git a/test/geometry/transform/test_projwarp.py b/test/geometry/transform/test_projwarp.py
index 2cec00c27..b253ad188 100644
--- a/test/geometry/transform/test_projwarp.py
+++ b/test/geometry/transform/test_projwarp.py
@@ -278,10 +278,10 @@ class TestPerspectiveTransform3D:
@pytest.mark.parametrize("batch_size", [1, 2, 5])
def test_get_perspective_transform3d(self, batch_size, device, dtype):
# generate input data
- d_max, h_max, w_max = 16, 64, 32 # height, width
- d = torch.ceil(d_max * torch.rand(batch_size, device=device, dtype=dtype))
- h = torch.ceil(h_max * torch.rand(batch_size, device=device, dtype=dtype))
- w = torch.ceil(w_max * torch.rand(batch_size, device=device, dtype=dtype))
+ # d_max, h_max, w_max = 16, 64, 32 # height, width
+ # d = torch.ceil(d_max * torch.rand(batch_size, device=device, dtype=dtype))
+ # h = torch.ceil(h_max * torch.rand(batch_size, device=device, dtype=dtype))
+ # w = torch.ceil(w_max * torch.rand(batch_size, device=device, dtype=dtype))
norm = torch.rand(batch_size, 8, 3, device=device, dtype=dtype)
points_src = torch.rand_like(norm, device=device, dtype=dtype)
diff --git a/test/geometry/transform/test_pyramid.py b/test/geometry/transform/test_pyramid.py
index 2b6310335..85e05872c 100644
--- a/test/geometry/transform/test_pyramid.py
+++ b/test/geometry/transform/test_pyramid.py
@@ -73,27 +73,27 @@ class TestScalePyramid:
def test_shape_batch(self, device, dtype):
inp = torch.zeros(3, 2, 31, 31, device=device, dtype=dtype)
SP = kornia.geometry.ScalePyramid(n_levels=1)
- sp, sigmas, pd = SP(inp)
+ sp, _, _ = SP(inp)
assert sp[0].shape == (3, 2, 3 + 1, 31, 31)
def test_shape_batch_double(self, device, dtype):
inp = torch.zeros(3, 2, 31, 31, device=device, dtype=dtype)
SP = kornia.geometry.ScalePyramid(n_levels=1, double_image=True)
- sp, sigmas, pd = SP(inp)
+ sp, _, _ = SP(inp)
assert sp[0].shape == (3, 2, 1 + 3, 62, 62)
def test_n_levels_shape(self, device, dtype):
inp = torch.zeros(1, 1, 32, 32, device=device, dtype=dtype)
SP = kornia.geometry.ScalePyramid(n_levels=3)
- sp, sigmas, pd = SP(inp)
+ sp, _, _ = SP(inp)
assert sp[0].shape == (1, 1, 3 + 3, 32, 32)
def test_blur_order(self, device, dtype):
inp = torch.rand(1, 1, 31, 31, device=device, dtype=dtype)
SP = kornia.geometry.ScalePyramid(n_levels=3)
- sp, sigmas, pd = SP(inp)
- for i, pyr_level in enumerate(sp):
- for ii, img in enumerate(pyr_level):
+ sp, _, _ = SP(inp)
+ for _, pyr_level in enumerate(sp):
+ for _, img in enumerate(pyr_level):
img = img.squeeze().view(3, -1)
max_per_blur_level_val, _ = img.max(dim=1)
assert torch.argmax(max_per_blur_level_val).item() == 0
@@ -104,9 +104,9 @@ class TestScalePyramid:
inp = torch.zeros(1, 1, PS, PS, device=device, dtype=dtype)
inp[..., PS // 2 - R : PS // 2 + R, PS // 2 - R : PS // 2 + R] = 1.0
SP = kornia.geometry.ScalePyramid(n_levels=3)
- sp, sigmas, pd = SP(inp)
- for i, pyr_level in enumerate(sp):
- for ii, img in enumerate(pyr_level):
+ sp, _, _ = SP(inp)
+ for _, pyr_level in enumerate(sp):
+ for _, img in enumerate(pyr_level):
img = img.squeeze()
assert_close(img, img.flip(1))
assert_close(img, img.flip(2))
@@ -117,7 +117,7 @@ class TestScalePyramid:
from kornia.geometry import ScalePyramid as SP
def sp_tuple(img):
- sp, sigmas, pd = SP()(img)
+ sp, _, _ = SP()(img)
return tuple(sp)
assert gradcheck(sp_tuple, (img,), raise_exception=True, nondet_tol=1e-4)
diff --git a/test/geometry/transform/test_thin_plate_spline.py b/test/geometry/transform/test_thin_plate_spline.py
index e63cffae0..121cd1e1f 100644
--- a/test/geometry/transform/test_thin_plate_spline.py
+++ b/test/geometry/transform/test_thin_plate_spline.py
@@ -36,7 +36,7 @@ class TestTransformParameters:
batch_size, 1, 1
)
dst = src.clone() * 2.0
- kernel, affine = kornia.get_tps_transform(src, dst)
+ kernel, _ = kornia.get_tps_transform(src, dst)
assert_close(kernel, torch.zeros_like(kernel), atol=1e-4, rtol=1e-4)
@pytest.mark.parametrize('batch_size', [1, 3])
diff --git a/test/integration/test_focal.py b/test/integration/test_focal.py
index c9d956f2a..9f7e509a7 100644
--- a/test/integration/test_focal.py
+++ b/test/integration/test_focal.py
@@ -48,7 +48,7 @@ class TestIntegrationFocalLoss:
# NOTE: uncomment to compare against vanilla cross entropy
# criterion = nn.CrossEntropyLoss()
- for iter_id in range(self.num_iterations):
+ for _ in range(self.num_iterations):
sample = self.generate_sample(target).to(device)
output = m(sample)
loss = criterion(output, target.to(device))
diff --git a/test/integration/test_soft_argmax2d.py b/test/integration/test_soft_argmax2d.py
index d7d5898a4..43a4a41e9 100644
--- a/test/integration/test_soft_argmax2d.py
+++ b/test/integration/test_soft_argmax2d.py
@@ -48,7 +48,7 @@ class TestIntegrationSoftArgmax2d:
# NOTE: check where this comes from
temperature = (self.height * self.width) ** (0.5)
- for iter_id in range(self.num_iterations):
+ for _ in range(self.num_iterations):
x = params
sample = self.generate_sample(target).to(device)
pred = soft_argmax2d(temperature * x)
diff --git a/test/integration/test_warp.py b/test/integration/test_warp.py
index e66f92af8..da4c2ea5b 100644
--- a/test/integration/test_warp.py
+++ b/test/integration/test_warp.py
@@ -37,7 +37,7 @@ class TestWarping:
learning_rate = self.lr
optimizer = optim.Adam(dst_homo_src.parameters(), lr=learning_rate)
- for iter_idx in range(self.num_iterations):
+ for _ in range(self.num_iterations):
# warp the reference image to the destiny with current homography
img_src_to_dst = warper(img_src_t, dst_homo_src())
diff --git a/test/performance/test_imgwarp_speed.py b/test/performance/test_imgwarp_speed.py
index 4784329f8..67f9e0025 100644
--- a/test/performance/test_imgwarp_speed.py
+++ b/test/performance/test_imgwarp_speed.py
@@ -23,6 +23,6 @@ def test_performance_speed(device, dtype):
As += 0.1 * torch.rand(As.size()).to(device)
torch.cuda.synchronize(device)
t = time()
- kornia_wa = kornia.warp_affine(inpt, As, (PS, PS))
+ _ = kornia.warp_affine(inpt, As, (PS, PS))
print(f"inp={input_shape}, PS={PS}, dev={device}, {time() - t}, sec")
torch.cuda.synchronize(device)
diff --git a/test/performance/test_project_points_speed.py b/test/performance/test_project_points_speed.py
index 6c8954b04..87a9fab93 100644
--- a/test/performance/test_project_points_speed.py
+++ b/test/performance/test_project_points_speed.py
@@ -17,7 +17,6 @@ def test_performance_speed(device, dtype):
print("Benchmarking project_points")
for input_shape in points_shapes:
- BS = input_shape[0]
inpt = torch.rand(input_shape).to(device)
pose = torch.rand((1, 4, 4)).to(device)
torch.cuda.synchronize(device)
diff --git a/test/test_losses.py b/test/test_losses.py
index e4710a97c..cfd965ca5 100644
--- a/test/test_losses.py
+++ b/test/test_losses.py
@@ -277,7 +277,7 @@ class TestDepthSmoothnessLoss:
depth = torch.rand(data_shape, device=device, dtype=dtype)
criterion = kornia.losses.InverseDepthSmoothnessLoss()
- loss = criterion(depth, image)
+ assert criterion(depth, image) is not None
def test_jit(self, device, dtype):
image = torch.rand(1, 2, 3, 4, device=device, dtype=dtype)
@@ -562,13 +562,13 @@ class TestTotalVariation:
# Expect ValueError to be raised when tensors of ndim != 3 or 4 are passed
@pytest.mark.parametrize('input', [torch.rand(2, 3, 4, 5, 3), torch.rand(3, 1)])
def test_tv_on_invalid_dims(self, device, dtype, input):
- with pytest.raises(ValueError) as ex_info:
+ with pytest.raises(ValueError):
kornia.losses.total_variation(input.to(device, dtype))
# Expect TypeError to be raised when non-torch tensors are passed
@pytest.mark.parametrize('input', [1, [1, 2]])
def test_tv_on_invalid_types(self, device, dtype, input):
- with pytest.raises(TypeError) as ex_info:
+ with pytest.raises(TypeError):
kornia.losses.total_variation(input)
def test_jit(self, device, dtype):
@@ -607,14 +607,14 @@ class TestPSNRLoss:
# Expecting an exception
# since we pass integers instead of torch tensors
criterion = kornia.losses.PSNRLoss(1.0).to(device, dtype)
- with pytest.raises(Exception) as e:
+ with pytest.raises(Exception):
criterion(1, 2)
def test_shape(self, device, dtype):
# Expecting an exception
# since we pass tensors of different shapes
criterion = kornia.losses.PSNRLoss(1.0).to(device, dtype)
- with pytest.raises(Exception) as e:
+ with pytest.raises(Exception):
criterion(torch.rand(2, 3, 3, 2), torch.rand(2, 3, 3))
def test_metric(self, device, dtype):
diff --git a/test/utils/test_grid.py b/test/utils/test_grid.py
index 5214a0e7a..4c3ae7e04 100644
--- a/test/utils/test_grid.py
+++ b/test/utils/test_grid.py
@@ -26,7 +26,6 @@ def test_normalize_pixel_grid(device, dtype):
pytest.skip('"inverse_cuda" not implemented for "Half"')
# generate input data
- batch_size = 1
height, width = 2, 4
# create points grid
diff --git a/test/utils/test_helpers.py b/test/utils/test_helpers.py
index fca83484d..5d71eb7b8 100644
--- a/test/utils/test_helpers.py
+++ b/test/utils/test_helpers.py
@@ -100,7 +100,7 @@ class TestSolveCast:
A = torch.randn(2, 3, 1, 4, 4, device=device, dtype=dtype)
B = torch.randn(2, 3, 1, 4, 6, device=device, dtype=dtype)
- X, LU = _torch_solve_cast(B, A)
+ X, _ = _torch_solve_cast(B, A)
error = torch.dist(B, A.matmul(X))
tol_val: float = 1e-1 if dtype == torch.float16 else 1e-4