Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix: resolve RUF059 & RUF043 linting violations for unused unpacked variables (#3324)

Meggison Oritsemisan713b71f3c5ee
diff --git a/docs/generate_examples.py b/docs/generate_examples.py
index f3b77a3a8..c5b868fba 100644
--- a/docs/generate_examples.py
+++ b/docs/generate_examples.py
@@ -667,7 +667,7 @@ def main():
kah = K.feature.KeyNetAffNetHardNet(512).eval()
with torch.no_grad():
- lafs, resps, descs = kah(K.color.rgb_to_grayscale(img_outdoor))
+ lafs, _resps, _descs = kah(K.color.rgb_to_grayscale(img_outdoor))
fig1, ax = visualize_LAF(img_outdoor, lafs, color="lime", return_fig_ax=True, draw_ori=False)
ax.set_title("KeyNetAffNet 512 LAFs")
cur_fname = str(OUTPUT_PATH / "keynet_affnet.jpg")
@@ -676,7 +676,7 @@ def main():
keynet = K.feature.KeyNetDetector(True, 512).eval()
with torch.no_grad():
- lafs, resps = keynet(K.color.rgb_to_grayscale(img_outdoor))
+ lafs, _resps = keynet(K.color.rgb_to_grayscale(img_outdoor))
xy = K.feature.get_laf_center(lafs).detach().cpu().numpy().reshape(-1, 2)
cur_fname = str(OUTPUT_PATH / "keynet.jpg")
plt.figure()
diff --git a/kornia/augmentation/container/augment.py b/kornia/augmentation/container/augment.py
index bed225407..3e10fb0fa 100644
--- a/kornia/augmentation/container/augment.py
+++ b/kornia/augmentation/container/augment.py
@@ -517,7 +517,7 @@ class AugmentationSequential(TransformMatrixMinIn, ImageSequential):
in_data_keys: Optional[List[DataKey]]
if len(inputs) == 1 and isinstance(inputs[0], dict):
- original_keys, in_data_keys, inputs, invalid_data = self._preproc_dict_data(inputs[0])
+ original_keys, in_data_keys, inputs, _invalid_data = self._preproc_dict_data(inputs[0])
else:
in_data_keys = kwargs.get("data_keys", self.data_keys)
data_keys = self.transform_op.preproc_datakeys(in_data_keys)
diff --git a/kornia/color/hsv.py b/kornia/color/hsv.py
index b2e617863..25f4a0cd0 100644
--- a/kornia/color/hsv.py
+++ b/kornia/color/hsv.py
@@ -55,7 +55,7 @@ def rgb_to_hsv(image: torch.Tensor, eps: float = 1e-8) -> torch.Tensor:
raise ValueError(f"Input size must have a shape of (*, 3, H, W). Got {image.shape}")
max_rgb, argmax_rgb = image.max(-3)
- min_rgb, argmin_rgb = image.min(-3)
+ min_rgb, _argmin_rgb = image.min(-3)
deltac = max_rgb - min_rgb
v = max_rgb
diff --git a/kornia/contrib/models/rt_detr/architecture/rtdetr_head.py b/kornia/contrib/models/rt_detr/architecture/rtdetr_head.py
index 28320af84..b70b2245c 100644
--- a/kornia/contrib/models/rt_detr/architecture/rtdetr_head.py
+++ b/kornia/contrib/models/rt_detr/architecture/rtdetr_head.py
@@ -349,7 +349,7 @@ class RTDETRHead(Module):
# prepare denoising training
denoising_class, denoising_bbox_unact, attn_mask = None, None, None
- target, init_ref_points_unact, enc_topk_bboxes, enc_topk_logits = self._get_decoder_input(
+ target, init_ref_points_unact, _enc_topk_bboxes, _enc_topk_logits = self._get_decoder_input(
memory, spatial_shapes, denoising_class, denoising_bbox_unact
)
diff --git a/kornia/contrib/models/sam/architecture/transformer.py b/kornia/contrib/models/sam/architecture/transformer.py
index 576a79b88..d95b17f45 100644
--- a/kornia/contrib/models/sam/architecture/transformer.py
+++ b/kornia/contrib/models/sam/architecture/transformer.py
@@ -91,7 +91,7 @@ class TwoWayTransformer(Module):
"""
# BxCxHxW -> BxHWxC == B x N_image_tokens x C
- bs, c, h, w = image_embedding.shape
+ _bs, _c, _h, _w = image_embedding.shape
image_embedding = image_embedding.flatten(2).permute(0, 2, 1)
image_pe = image_pe.flatten(2).permute(0, 2, 1)
diff --git a/kornia/enhance/jpeg.py b/kornia/enhance/jpeg.py
index 6c7ad7bbd..d318dd689 100644
--- a/kornia/enhance/jpeg.py
+++ b/kornia/enhance/jpeg.py
@@ -108,7 +108,7 @@ def _unpatchify_8x8(input: Tensor, H: int, W: int) -> Tensor:
"""
# Get input shape
- B, N = input.shape[:2]
+ B, _N = input.shape[:2]
# Unpatch to [B, H, W]
output: Tensor = input.view(B, H // 8, W // 8, 8, 8).permute(0, 1, 3, 2, 4).reshape(B, H, W)
return output
diff --git a/kornia/feature/adalam/adalam.py b/kornia/feature/adalam/adalam.py
index 70c170879..70179fff1 100644
--- a/kornia/feature/adalam/adalam.py
+++ b/kornia/feature/adalam/adalam.py
@@ -296,7 +296,7 @@ class AdalamFilter:
scores = dd12[:, 0] / dd12[:, 1].clamp_min_(1e-3)
if self.config["force_seed_mnn"]:
- dd21, nn21 = torch.min(distmat, dim=0) # (n2,)
+ _dd21, nn21 = torch.min(distmat, dim=0) # (n2,)
mnn = nn21[putative_matches] == torch.arange(_k1.shape[0], device=self.config["device"])
else:
mnn = None
diff --git a/kornia/feature/adalam/ransac.py b/kornia/feature/adalam/ransac.py
index 223e48d84..a3995ec2d 100644
--- a/kornia/feature/adalam/ransac.py
+++ b/kornia/feature/adalam/ransac.py
@@ -147,7 +147,7 @@ def ransac(
# minimal fit for sampled_x @ A^T = sampled_y
affinities_fit = torch.transpose(batch_2x2_inv(sampled_x, check_dets=True) @ sampled_y, -1, -2)
if not refit:
- eigenvals, eigenvecs = batch_2x2_ellipse(affinities_fit)
+ eigenvals, _eigenvecs = batch_2x2_ellipse(affinities_fit)
bad_ones = (eigenvals[..., 1] < 1 / DET_THR**2) | (eigenvals[..., 0] > DET_THR**2)
affinities_fit[bad_ones] = torch.eye(2, device=dv)
y_pred = (affinities_fit[:, ransidx] @ xsamples.unsqueeze(-1)).squeeze(-1)
@@ -185,7 +185,7 @@ def ransac(
)
# Filter out degenerate affinities with large scale changes
- eigenvals, eigenvecs = batch_2x2_ellipse(refit_affinity)
+ eigenvals, _eigenvecs = batch_2x2_ellipse(refit_affinity)
bad_ones = (eigenvals[..., 1] < 1 / DET_THR**2) | (eigenvals[..., 0] > DET_THR**2)
refit_affinity[bad_ones] = torch.eye(2, device=dv, dtype=refit_affinity.dtype)
y_pred = (refit_affinity[ransidx] @ xsamples.unsqueeze(-1)).squeeze(-1)
diff --git a/kornia/feature/dedode/decoder.py b/kornia/feature/dedode/decoder.py
index 137e4ead8..fec6891ac 100644
--- a/kornia/feature/dedode/decoder.py
+++ b/kornia/feature/dedode/decoder.py
@@ -106,7 +106,7 @@ class ConvRefiner(nn.Module):
return nn.Sequential(conv1, norm, relu, conv2)
def forward(self, feats: Tensor) -> Tensor:
- b, c, hs, ws = feats.shape
+ _b, _c, _hs, _ws = feats.shape
with torch.autocast("cuda", enabled=self.amp, dtype=self.amp_dtype):
x0 = self.block1(feats)
x = self.hidden_blocks(x0)
diff --git a/kornia/feature/dedode/dedode.py b/kornia/feature/dedode/dedode.py
index 5261a4edd..aa2c0ad23 100644
--- a/kornia/feature/dedode/dedode.py
+++ b/kornia/feature/dedode/dedode.py
@@ -104,7 +104,7 @@ class DeDoDe(Module):
"""
if apply_imagenet_normalization:
images = self.normalizer(images)
- B, C, H, W = images.shape
+ _B, _C, H, W = images.shape
h, w = images.shape[2:]
if pad_if_not_divisible:
pd_h = 14 - h % 14 if h % 14 > 0 else 0
@@ -142,7 +142,7 @@ class DeDoDe(Module):
"""
KORNIA_CHECK_SHAPE(images, ["B", "3", "H", "W"])
self.train(False)
- B, C, H, W = images.shape
+ B, _C, H, W = images.shape
if pad_if_not_divisible:
h, w = images.shape[2:]
pd_h = 14 - h % 14 if h % 14 > 0 else 0
@@ -184,7 +184,7 @@ class DeDoDe(Module):
"""
KORNIA_CHECK_SHAPE(images, ["B", "3", "H", "W"])
- B, C, H, W = images.shape
+ _B, _C, H, W = images.shape
if keypoints is not None:
KORNIA_CHECK_SHAPE(keypoints, ["B", "N", "2"])
if apply_imagenet_normalization:
diff --git a/kornia/feature/dedode/encoder.py b/kornia/feature/dedode/encoder.py
index f1915e832..93c56fc21 100644
--- a/kornia/feature/dedode/encoder.py
+++ b/kornia/feature/dedode/encoder.py
@@ -70,7 +70,7 @@ class FrozenDINOv2(Module):
self.dinov2_vitl14 = [dinov2_vitl14] # ugly hack to not show parameters to DDP
def forward(self, x: Tensor): # type: ignore[no-untyped-def]
- B, C, H, W = x.shape
+ B, _C, H, W = x.shape
if self.dinov2_vitl14[0].device != x.device:
self.dinov2_vitl14[0] = self.dinov2_vitl14[0].to(x.device).to(self.amp_dtype)
with torch.inference_mode():
diff --git a/kornia/feature/dedode/transformer/dinov2.py b/kornia/feature/dedode/transformer/dinov2.py
index d1b52dd1d..cb61e6b84 100644
--- a/kornia/feature/dedode/transformer/dinov2.py
+++ b/kornia/feature/dedode/transformer/dinov2.py
@@ -211,7 +211,7 @@ class DinoVisionTransformer(nn.Module):
return torch.cat((class_pos_embed.unsqueeze(0), patch_pos_embed), dim=1).to(previous_dtype)
def prepare_tokens_with_masks(self, x, masks=None):
- B, nc, w, h = x.shape
+ _B, _nc, w, h = x.shape
x = self.patch_embed(x)
if masks is not None:
x = torch.where(masks.unsqueeze(-1), self.mask_token.to(x.dtype).unsqueeze(0), x)
diff --git a/kornia/feature/dedode/transformer/layers/block.py b/kornia/feature/dedode/transformer/layers/block.py
index 66643dc8c..324c8889e 100644
--- a/kornia/feature/dedode/transformer/layers/block.py
+++ b/kornia/feature/dedode/transformer/layers/block.py
@@ -131,7 +131,7 @@ def drop_add_residual_stochastic_depth(
) -> Tensor:
"""Add residual connection."""
# 1) extract subset using permutation
- b, n, d = x.shape
+ b, _n, _d = x.shape
sample_subset_size = max(int(b * (1 - sample_drop_ratio)), 1)
brange = (torch.randperm(b, device=x.device))[:sample_subset_size]
x_subset = x[brange]
@@ -151,7 +151,7 @@ def drop_add_residual_stochastic_depth(
def get_branges_scales(x, sample_drop_ratio=0.0):
"""Add bernoulli sampled range and scale."""
- b, n, d = x.shape
+ b, _n, _d = x.shape
sample_subset_size = max(int(b * (1 - sample_drop_ratio)), 1)
brange = (torch.randperm(b, device=x.device))[:sample_subset_size]
residual_scale_factor = b / sample_subset_size
diff --git a/kornia/feature/laf.py b/kornia/feature/laf.py
index 7fed16e12..3a66bd977 100644
--- a/kornia/feature/laf.py
+++ b/kornia/feature/laf.py
@@ -121,7 +121,7 @@ def set_laf_orientation(LAF: Tensor, angles_degrees: Tensor) -> Tensor:
"""
KORNIA_CHECK_LAF(LAF)
- B, N = LAF.shape[:2]
+ _B, _N = LAF.shape[:2]
ori = get_laf_orientation(LAF).reshape_as(angles_degrees)
return rotate_laf(LAF, angles_degrees - ori)
diff --git a/kornia/feature/loftr/loftr.py b/kornia/feature/loftr/loftr.py
index 0841c2f00..72f1db9fc 100644
--- a/kornia/feature/loftr/loftr.py
+++ b/kornia/feature/loftr/loftr.py
@@ -165,11 +165,11 @@ class LoFTR(Module):
# feat_c0 = rearrange(self.pos_encoding(feat_c0), 'n c h w -> n (h w) c')
# feat_c1 = rearrange(self.pos_encoding(feat_c1), 'n c h w -> n (h w) c')
feat_c0 = self.pos_encoding(feat_c0).permute(0, 2, 3, 1)
- n, h, w, c = feat_c0.shape
+ n, _h, _w, c = feat_c0.shape
feat_c0 = feat_c0.reshape(n, -1, c)
feat_c1 = self.pos_encoding(feat_c1).permute(0, 2, 3, 1)
- n1, h1, w1, c1 = feat_c1.shape
+ n1, _h1, _w1, c1 = feat_c1.shape
feat_c1 = feat_c1.reshape(n1, -1, c1)
mask_c0 = mask_c1 = None # mask is useful in training
diff --git a/kornia/feature/matching.py b/kornia/feature/matching.py
index 7083388af..1a082668f 100644
--- a/kornia/feature/matching.py
+++ b/kornia/feature/matching.py
@@ -286,7 +286,7 @@ def match_fginn(
candidates_xy = xy2[idxs_in_2]
kdist = torch.norm(candidates_xy - candidates_xy[0:1], p=2, dim=2)
fginn_vals = vals_cand[:, 1:] + (kdist[:, 1:] < spatial_th).to(dtype) * BIG_NUMBER
- fginn_vals_best, fginn_idxs_best = fginn_vals.min(dim=1)
+ fginn_vals_best, _fginn_idxs_best = fginn_vals.min(dim=1)
# orig_idxs = idxs_in_2.gather(1, fginn_idxs_best.unsqueeze(1))[0]
# if you need to know fginn indexes - uncomment
diff --git a/kornia/feature/siftdesc.py b/kornia/feature/siftdesc.py
index 95c772806..2f888ab2c 100644
--- a/kornia/feature/siftdesc.py
+++ b/kornia/feature/siftdesc.py
@@ -312,7 +312,7 @@ class DenseSIFTDescriptor(Module):
def forward(self, input: Tensor) -> Tensor:
KORNIA_CHECK_SHAPE(input, ["B", "1", "H", "W"])
- B, CH, W, H = input.size()
+ _B, _CH, _W, _H = input.size()
self.bin_pooling_kernel = self.bin_pooling_kernel.to(input.dtype).to(input.device)
self.PoolingConv = self.PoolingConv.to(input.dtype).to(input.device)
grads = spatial_gradient(input, "diff")
diff --git a/kornia/feature/sold2/sold2.py b/kornia/feature/sold2/sold2.py
index cfee7935c..a275b468a 100644
--- a/kornia/feature/sold2/sold2.py
+++ b/kornia/feature/sold2/sold2.py
@@ -234,7 +234,7 @@ class WunschLineMatcher(Module):
line_points: an N x num_samples x 2 Tensor.
valid_points: a boolean N x num_samples Tensor.
"""
- N, _, _ = line_seg.shape
+ _N, _, _ = line_seg.shape
M = self.num_samples
dev = line_seg.device
diff --git a/kornia/geometry/line.py b/kornia/geometry/line.py
index a903b1928..2a7d93cc3 100644
--- a/kornia/geometry/line.py
+++ b/kornia/geometry/line.py
@@ -255,7 +255,7 @@ def fit_line(points: Tensor, weights: Optional[Tensor] = None) -> ParametrizedLi
KORNIA_CHECK_IS_TENSOR(points, "points must be a tensor")
KORNIA_CHECK_SHAPE(points, ["B", "N", "D"])
- B, N, D = points.shape
+ _B, _N, D = points.shape
# Fast path: use OLS for unweighted 2D case
if D == 2:
diff --git a/tests/augmentation/test_augmentation.py b/tests/augmentation/test_augmentation.py
index 041cf3987..d95e29bce 100644
--- a/tests/augmentation/test_augmentation.py
+++ b/tests/augmentation/test_augmentation.py
@@ -4035,28 +4035,28 @@ class TestRandomSaltAndPepperNoise(BaseTester):
RandomSaltAndPepperNoise(salt_vs_pepper=[0.4, 0.6])
with pytest.raises(
ValueError,
- match="The length of salt_vs_pepper must be greater than 0 \
- and less than or equal to 2, and it should be a tuple.",
+ match=r"The length of salt_vs_pepper must be greater than 0\s+and less than or equal to 2, "
+ r"and it should be a tuple\.",
):
RandomSaltAndPepperNoise(salt_vs_pepper=(0.1, 0.2, 0.3))
with pytest.raises(
Exception,
- match="False not true.\nSalt_vs_pepper values must be between 0 and 1. \
- Recommended value 0.5.",
+ match=r"False not true\.\s*Salt_vs_pepper values must be between 0 and 1\.\s+"
+ r"Recommended value 0\.5\.",
):
RandomSaltAndPepperNoise(salt_vs_pepper=(0.4, 3))
with pytest.raises(ValueError, match="amount must be a tuple or a float"):
RandomSaltAndPepperNoise(amount=[0.01, 0.06])
with pytest.raises(
ValueError,
- match="The length of amount must be greater than 0 \
- and less than or equal to 2, and it should be a tuple.",
+ match=r"The length of amount must be greater than 0\s+and less than or equal to 2, "
+ r"and it should be a tuple\.",
):
RandomSaltAndPepperNoise(amount=())
with pytest.raises(
Exception,
- match="False not true.\namount of noise values must be between 0 and 1. \
- Recommended values less than 0.2.",
+ match=r"False not true\.\s*amount of noise values must be between 0 and 1\.\s+"
+ r"Recommended values less than 0\.2\.",
):
RandomSaltAndPepperNoise(amount=(0.05, 3))
@@ -4132,17 +4132,17 @@ class TestRandomGaussianIllumination(BaseTester):
with pytest.raises(
Exception,
- match="gain values must be between 0 and 1. Recommended values less than 0.2.",
+ match=r"gain values must be between 0 and 1. Recommended values less than 0.2.",
):
RandomGaussianIllumination(gain=(0.01, 2))
- with pytest.raises(Exception, match="sigma of gaussian value must be between 0 and 1."):
+ with pytest.raises(Exception, match=r"sigma of gaussian value must be between 0 and 1."):
RandomGaussianIllumination(sigma=(0.01, 2))
- with pytest.raises(Exception, match="center of gaussian value must be between 0 and 1."):
+ with pytest.raises(Exception, match=r"center of gaussian value must be between 0 and 1."):
RandomGaussianIllumination(center=(0.01, 2))
- with pytest.raises(Exception, match="sign of gaussian value must be between -1 and 1."):
+ with pytest.raises(Exception, match=r"sign of gaussian value must be between -1 and 1."):
RandomGaussianIllumination(sign=(0.01, 2))
@pytest.mark.parametrize("channel_shape, batch_shape", [(1, 1), (3, 2), (5, 3)])
@@ -4212,11 +4212,11 @@ class TestRandomLinearIllumination(BaseTester):
with pytest.raises(
Exception,
- match="gain values must be between 0 and 1. Recommended values less than 0.2.",
+ match=r"gain values must be between 0 and 1. Recommended values less than 0.2.",
):
RandomLinearIllumination(gain=(0.01, 2))
- with pytest.raises(Exception, match="sign of linear value must be between -1 and 1."):
+ with pytest.raises(Exception, match=r"sign of linear value must be between -1 and 1."):
RandomLinearIllumination(sign=(0.01, 2))
@pytest.mark.parametrize("channel_shape, batch_shape", [(1, 1), (3, 2), (5, 3)])
@@ -4278,11 +4278,11 @@ class TestRandomLinearCornerIllumination(BaseTester):
with pytest.raises(
Exception,
- match="gain values must be between 0 and 1. Recommended values less than 0.2.",
+ match=r"gain values must be between 0 and 1. Recommended values less than 0.2.",
):
RandomLinearCornerIllumination(gain=(0.01, 2))
- with pytest.raises(Exception, match="sign of linear value must be between -1 and 1."):
+ with pytest.raises(Exception, match=r"sign of linear value must be between -1 and 1."):
RandomLinearCornerIllumination(sign=(0.01, 2))
@pytest.mark.parametrize("channel_shape, batch_shape", [(1, 1), (3, 2), (5, 3)])
@@ -4339,7 +4339,7 @@ class TestRandomChannelDropout(BaseTester):
input_tensor = torch.ones(1, 3, 3, 3, device=device, dtype=dtype)
with pytest.raises(
Exception,
- match="Invalid value in `num_drop_channels`. Cannot be greater than the number of channels of `input`.",
+ match=r"Invalid value in `num_drop_channels`. Cannot be greater than the number of channels of `input`.",
):
RandomChannelDropout(num_drop_channels=num_drop_channels, p=1.0)(input_tensor)
diff --git a/tests/augmentation/test_augmentation_mix.py b/tests/augmentation/test_augmentation_mix.py
index aead5e8d0..bfb64c99f 100644
--- a/tests/augmentation/test_augmentation_mix.py
+++ b/tests/augmentation/test_augmentation_mix.py
@@ -619,7 +619,7 @@ class TestRandomTransplantation(BaseTester):
with pytest.raises(Exception, match="excluded_labels must be a 1-dimensional"):
RandomTransplantation(p=1.0, excluded_labels=torch.tensor([[0, 1]], device=device, dtype=dtype))
- with pytest.raises(Exception, match="Length of keys.*does not match number of inputs"):
+ with pytest.raises(Exception, match=r"Length of keys.*does not match number of inputs"):
f = RandomTransplantation(p=1.0)
f(image, mask, data_keys=["input", "mask", "mask"])
diff --git a/tests/feature/test_integrated.py b/tests/feature/test_integrated.py
index b9d8564b3..7567736b9 100644
--- a/tests/feature/test_integrated.py
+++ b/tests/feature/test_integrated.py
@@ -171,8 +171,8 @@ class TestLocalFeature(BaseTester):
desc = SIFTDescriptor(PS)
local_feature = LocalFeature(det, LAFDescriptor(desc, PS), 1.0).to(device, dtype)
local_feature2 = LocalFeature(det, LAFDescriptor(desc, PS), 2.0).to(device, dtype)
- lafs, responses, descs = local_feature(img)
- lafs2, responses2, descs2 = local_feature2(img)
+ lafs, _responses, _descs = local_feature(img)
+ lafs2, _responses2, _descs2 = local_feature2(img)
self.assert_close(get_laf_center(lafs), get_laf_center(lafs2))
self.assert_close(get_laf_orientation(lafs), get_laf_orientation(lafs2))
self.assert_close(2.0 * get_laf_scale(lafs), get_laf_scale(lafs2))
diff --git a/tests/feature/test_matching.py b/tests/feature/test_matching.py
index a3dd841ef..a6605d32f 100644
--- a/tests/feature/test_matching.py
+++ b/tests/feature/test_matching.py
@@ -380,10 +380,10 @@ class TestAdalam(BaseTester):
# This is not unit test, but that is quite good integration test
data_dev = dict_to(data, device, dtype)
with torch.no_grad():
- dists, idxs = match_adalam(
+ _dists, _idxs = match_adalam(
data_dev["descs1"], data_dev["descs2"][:1], data_dev["lafs1"], data_dev["lafs2"][:, :1]
)
- dists, idxs = match_adalam(
+ _dists, _idxs = match_adalam(
data_dev["descs1"][:1], data_dev["descs2"], data_dev["lafs1"][:, :1], data_dev["lafs2"]
)
@@ -395,12 +395,11 @@ class TestAdalam(BaseTester):
data_dev = dict_to(data, device, dtype)
adalam_config = {"device": device}
with torch.no_grad():
- dists, idxs = match_adalam(
- data_dev["descs1"][:4],
- data_dev["descs2"][:4],
- data_dev["lafs1"][:, :4],
- data_dev["lafs2"][:, :4],
- config=adalam_config,
+ _dists, _idxs = match_adalam(
+ data_dev["descs1"], data_dev["descs2"][:1], data_dev["lafs1"], data_dev["lafs2"][:, :1]
+ )
+ _dists, _idxs = match_adalam(
+ data_dev["descs1"], data_dev["descs2"], data_dev["lafs1"], data_dev["lafs2"], config=adalam_config
)
@pytest.mark.slow
@@ -410,13 +409,13 @@ class TestAdalam(BaseTester):
# This is not unit test, but that is quite good integration test
data_dev = dict_to(data, device, dtype)
with torch.no_grad():
- dists, idxs = match_adalam(
+ _dists, _idxs = match_adalam(
data_dev["descs1"],
torch.empty(0, 128, device=device, dtype=dtype),
data_dev["lafs1"],
torch.empty(0, 0, 2, 3, device=device, dtype=dtype),
)
- dists, idxs = match_adalam(
+ _dists, _idxs = match_adalam(
torch.empty(0, 128, device=device, dtype=dtype),
data_dev["descs2"],
torch.empty(0, 0, 2, 3, device=device, dtype=dtype),
@@ -430,7 +429,7 @@ class TestAdalam(BaseTester):
# This is not unit test, but that is quite good integration test
data_dev = dict_to(data, device, dtype)
with torch.no_grad():
- dists, idxs = match_adalam(
+ _dists, _idxs = match_adalam(
data_dev["descs1"][:4], data_dev["descs2"][:4], data_dev["lafs1"][:, :4], data_dev["lafs2"][:, :4]
)
@@ -441,7 +440,7 @@ class TestAdalam(BaseTester):
# This is not unit test, but that is quite good integration test
data_dev = dict_to(data, device, dtype)
with torch.no_grad():
- dists, idxs = match_adalam(
+ _dists, _idxs = match_adalam(
data_dev["descs1"][:100],
data_dev["descs2"][:100],
data_dev["lafs1"][:, :100],
@@ -494,8 +493,8 @@ class TestLightGlueDISK(BaseTester):
data_dev = dict_to(data, device, dtype)
lg = LightGlueMatcher("disk").to(device, dtype).eval()
with torch.no_grad():
- dists, idxs = lg(data_dev["descs1"], data_dev["descs2"][:1], data_dev["lafs1"], data_dev["lafs2"][:, :1])
- dists, idxs = lg(data_dev["descs1"][:1], data_dev["descs2"], data_dev["lafs1"][:, :1], data_dev["lafs2"])
+ _dists, _idxs = lg(data_dev["descs1"], data_dev["descs2"][:1], data_dev["lafs1"], data_dev["lafs2"][:, :1])
+ _dists, _idxs = lg(data_dev["descs1"][:1], data_dev["descs2"], data_dev["lafs1"][:, :1], data_dev["lafs2"])
@pytest.mark.slow
@pytest.mark.parametrize("data", ["lightglue_idxs"], indirect=True)
@@ -505,13 +504,13 @@ class TestLightGlueDISK(BaseTester):
data_dev = dict_to(data, device, dtype)
lg = LightGlueMatcher("disk").to(device, dtype).eval()
with torch.no_grad():
- dists, idxs = lg(
+ _dists, _idxs = lg(
data_dev["descs1"],
torch.empty(0, 256, device=device, dtype=dtype),
data_dev["lafs1"],
torch.empty(0, 0, 2, 3, device=device, dtype=dtype),
)
- dists, idxs = lg(
+ _dists, _idxs = lg(
torch.empty(0, 256, device=device, dtype=dtype),
data_dev["descs2"],
torch.empty(0, 0, 2, 3, device=device, dtype=dtype),
@@ -539,7 +538,7 @@ class TestMatchSteererGlobal(BaseTester):
steerer=steerer, steerer_order=3, steer_mode="global", match_mode=matching_mode
)
- dists, idxs, num_rot = matcher(
+ dists, idxs, _num_rot = matcher(
desc1,
desc2,
subset_size=max(1, min(num_desc1 // 2, num_desc2 // 2)) if fast else None,
@@ -581,7 +580,7 @@ class TestMatchSteererLocal(BaseTester):
matcher = DescriptorMatcherWithSteerer(steerer=steerer, steerer_order=3, steer_mode="local", match_mode="mnn")
- dists, idxs, num_rot = matcher(desc1, desc2)
+ dists, idxs, _num_rot = matcher(desc1, desc2)
assert dists.shape[1] == 1
assert idxs.shape == (dists.shape[0], 2)
assert dists.shape[0] == num_desc1
diff --git a/tests/filters/test_in_range.py b/tests/filters/test_in_range.py
index 00638bde9..e38675bfc 100644
--- a/tests/filters/test_in_range.py
+++ b/tests/filters/test_in_range.py
@@ -78,17 +78,17 @@ class TestInRange(BaseTester):
def test_exception(self, device, dtype):
input_tensor = torch.rand(1, 3, 3, 3, device=device, dtype=dtype)
- with pytest.raises(Exception, match="Invalid `lower` and `upper` format. Should be tuple or Tensor."):
+ with pytest.raises(Exception, match=r"Invalid `lower` and `upper` format. Should be tuple or Tensor."):
InRange(lower=3, upper=3)(input_tensor)
- with pytest.raises(Exception, match="Invalid `lower` and `upper` format. Should be tuple or Tensor."):
+ with pytest.raises(Exception, match=r"Invalid `lower` and `upper` format. Should be tuple or Tensor."):
InRange(lower=[0.2, 0.2], upper=[0.2, 0.2])(input_tensor)
- with pytest.raises(Exception, match="Invalid `lower` and `upper` format. Should be tuple or Tensor."):
+ with pytest.raises(Exception, match=r"Invalid `lower` and `upper` format. Should be tuple or Tensor."):
InRange(lower=(0.2), upper=(0.2))(input_tensor)
with pytest.raises(
- ValueError, match="Shape of `lower`, `upper` and `input` image channels must have same shape."
+ ValueError, match=r"Shape of `lower`, `upper` and `input` image channels must have same shape."
):
InRange(lower=(0.2,), upper=(0.2,))(input_tensor)
@@ -102,7 +102,7 @@ class TestInRange(BaseTester):
upper = torch.tensor([0.6, 0.6, 0.6])
InRange(lower=lower, upper=upper)(input_tensor)
- with pytest.raises(Exception, match="Invalid `return_mask` format. Should be boolean."):
+ with pytest.raises(Exception, match=r"Invalid `return_mask` format. Should be boolean."):
lower = torch.tensor([0.2, 0.2, 0.2])
upper = torch.tensor([0.6, 0.6, 0.6])
InRange(lower=lower, upper=upper, return_mask=2)(input_tensor)
diff --git a/tests/filters/test_motion.py b/tests/filters/test_motion.py
index f6c05cd5a..b040babb6 100644
--- a/tests/filters/test_motion.py
+++ b/tests/filters/test_motion.py
@@ -38,7 +38,7 @@ class TestMotionBlur(BaseTester):
@pytest.mark.parametrize("mode", ["bilinear", "nearest"])
@pytest.mark.parametrize("params_as_tensor", [True, False])
def test_smoke(self, shape, kernel_size, angle, direction, mode, params_as_tensor, device, dtype):
- B, C, H, W = shape
+ B, _C, _H, _W = shape
data = torch.rand(shape, device=device, dtype=dtype)
if params_as_tensor is True:
@@ -127,7 +127,7 @@ class TestMotionBlur3D(BaseTester):
@pytest.mark.parametrize("mode", ["bilinear", "nearest"])
@pytest.mark.parametrize("params_as_tensor", [True, False])
def test_smoke(self, shape, kernel_size, angle, direction, mode, params_as_tensor, device, dtype):
- B, C, D, H, W = shape
+ B, _C, _D, _H, _W = shape
data = torch.rand(shape, device=device, dtype=dtype)
if params_as_tensor is True:
diff --git a/tests/filters/test_otsu_thresholding.py b/tests/filters/test_otsu_thresholding.py
index 692f6451f..9d847c896 100644
--- a/tests/filters/test_otsu_thresholding.py
+++ b/tests/filters/test_otsu_thresholding.py
@@ -27,7 +27,7 @@ class TestOtsuThreshold(BaseTester):
def test_smoke(self, device, dtype):
img = torch.rand(1, 3, 5, 5, device=device, dtype=dtype)
op = OtsuThreshold()
- thresh_result, thresh_value = op(img, nbins=4)
+ thresh_result, _thresh_value = op(img, nbins=4)
assert thresh_result.shape == img.shape
@pytest.mark.parametrize("input_shape", [(3, 3), (1, 3, 3), (1, 1, 3, 3), (2, 1, 1, 3, 3)])
@@ -41,8 +41,8 @@ class TestOtsuThreshold(BaseTester):
def test_otsu_threshold_consistency(self, device, dtype):
torch.manual_seed(0)
img = torch.rand(1, 4, 6, 1, device=device, dtype=dtype)
- out_func_tensor, out_func_value = otsu_threshold(img, nbins=3, return_mask=False)
- out_class_tensor, out_class_value = OtsuThreshold()(img, nbins=3)
+ out_func_tensor, _out_func_value = otsu_threshold(img, nbins=3, return_mask=False)
+ out_class_tensor, _out_class_value = OtsuThreshold()(img, nbins=3)
assert_close(out_func_tensor, out_class_tensor)
def test_invalid_dim(self, device, dtype):
@@ -61,8 +61,8 @@ class TestOtsuThreshold(BaseTester):
input = differentiable_input.clone().detach().requires_grad_(False)
op = OtsuThreshold()
- diff_thresh_result, diff_thresh_value = op(input, slow_and_differentiable=True)
- thresh_result, thresh_value = op(input)
+ diff_thresh_result, _diff_thresh_value = op(input, slow_and_differentiable=True)
+ thresh_result, _thresh_value = op(input)
self.assert_close(diff_thresh_result, thresh_result)
def test_threshold_result(self, device, dtype):
@@ -75,7 +75,7 @@ class TestOtsuThreshold(BaseTester):
)
op = OtsuThreshold()
- thresh_result, thresh_value = op(input)
+ thresh_result, _thresh_value = op(input)
self.assert_close(thresh_result, expected)
def test_gradual_threshold(self, device, dtype):
@@ -84,7 +84,7 @@ class TestOtsuThreshold(BaseTester):
expected = torch.tensor([[0, 0, 0], [0, 50, 60], [70, 80, 90]], device=device, dtype=dtype)
op = OtsuThreshold()
- thresh_result, thresh_value = op(input)
+ thresh_result, _thresh_value = op(input)
self.assert_close(thresh_result, expected)
def test_uniform_result(self, device, dtype):
@@ -97,7 +97,7 @@ class TestOtsuThreshold(BaseTester):
)
op = OtsuThreshold()
- thresh_result, thresh_value = op(input)
+ thresh_result, _thresh_value = op(input)
self.assert_close(thresh_result, expected)
@@ -106,12 +106,12 @@ def test_mask(device, dtype):
expected = torch.tensor([[0, 0, 0], [0, 1, 1], [1, 1, 1]], device=device, dtype=torch.bool)
- thresh_result, thresh_value = otsu_threshold(input, return_mask=True)
+ thresh_result, _thresh_value = otsu_threshold(input, return_mask=True)
assert_close(thresh_result, expected)
@pytest.mark.parametrize("shape", [(1, 3, 5, 5), (2, 1, 10, 10)])
def test_otsu_threshold_basic(shape, device, dtype):
img = torch.rand(shape, device=device, dtype=dtype)
- thresh_result, thresh_value = otsu_threshold(img)
+ thresh_result, _thresh_value = otsu_threshold(img)
assert thresh_result.shape == img.shape
diff --git a/tests/geometry/transform/test_homography_warper.py b/tests/geometry/transform/test_homography_warper.py
index ba380a60d..19a6cf7a0 100644
--- a/tests/geometry/transform/test_homography_warper.py
+++ b/tests/geometry/transform/test_homography_warper.py
@@ -267,7 +267,7 @@ class TestHomographyWarper(BaseTester):
patch_src = torch.rand(batch_shape, device=device, dtype=dtype)
# create base homography
- batch_size, _, height, width = patch_src.shape
+ _batch_size, _, height, width = patch_src.shape
dst_homo_src = eye_like(eye_size, patch_src)
# instantiate warper
diff --git a/tests/utils/test_helpers.py b/tests/utils/test_helpers.py
index a9508aab8..fb816ff23 100644
--- a/tests/utils/test_helpers.py
+++ b/tests/utils/test_helpers.py
@@ -157,7 +157,7 @@ class TestSolveWithMask:
A = torch.ones(10, 3, 3, device=device, dtype=dtype)
B = torch.ones(10, 3, device=device, dtype=dtype)
- X, _, mask = safe_solve_with_mask(B, A)
+ _X, _, mask = safe_solve_with_mask(B, A)
assert torch.equal(mask, torch.zeros_like(mask))
@@ -174,5 +174,5 @@ class TestInverseWithMask:
def test_all_bad(self, device, dtype):
A = torch.ones(10, 3, 3, device=device, dtype=dtype)
- X, mask = safe_inverse_with_mask(A)
+ _X, mask = safe_inverse_with_mask(A)
assert torch.equal(mask, torch.zeros_like(mask))