Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix linter errors

edgarribaa763ce27b0a1
diff --git a/test/test_imgwarp.py b/test/test_imgwarp.py
index cfc41e7d9..a06528de8 100644
--- a/test/test_imgwarp.py
+++ b/test/test_imgwarp.py
@@ -21,15 +21,15 @@ class Tester(unittest.TestCase):
# create transformation (rotation)
M = torch.tensor([[
[torch.cos(alpha), -torch.sin(alpha), 0.],
- [torch.sin(alpha), torch.cos(alpha), 0.],
- [ 0., 0., 1.],
+ [torch.sin(alpha), torch.cos(alpha), 0.],
+ [0., 0., 1.],
]]) # Bx3x3
# apply transformation and inverse
_, _, h, w = patch.shape
patch_warped = tgm.warp_perspective(patch, M, dsize=(height, width))
patch_warped_inv = tgm.warp_perspective(patch_warped, tgm.inverse(M),
- dsize=(height, width))
+ dsize=(height, width))
# generate mask to compute error
mask = torch.ones_like(patch)
@@ -54,8 +54,8 @@ class Tester(unittest.TestCase):
# create transformation (rotation)
M = torch.tensor([[
[torch.cos(alpha), -torch.sin(alpha), 0.],
- [torch.sin(alpha), torch.cos(alpha), 0.],
- [ 0., 0., 1.],
+ [torch.sin(alpha), torch.cos(alpha), 0.],
+ [0., 0., 1.],
]]) # Bx3x3
M = utils.tensor_to_gradcheck_var(M, requires_grad=False) # to var
diff --git a/test/test_utils.py b/test/test_utils.py
index 17799aadf..819a57c4b 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -22,7 +22,7 @@ class Tester(unittest.TestCase):
self.assertIsInstance(tensor, torch.Tensor)
def test_create_meshgrid(self):
- height, width = 4, 6
+ height, width = 4, 6
normalized_coordinates = False
# create the meshgrid and verify shape
diff --git a/torchgeometry/depth_warper.py b/torchgeometry/depth_warper.py
index 2f454ab5e..f525b0e6d 100644
--- a/torchgeometry/depth_warper.py
+++ b/torchgeometry/depth_warper.py
@@ -131,7 +131,7 @@ accurate sampling of the depth cost volume, per camera.
def forward(self, inv_depth_ref, patch_i):
"""Warps an image or tensor from ith frame to reference given the
- inverse depth in the reference frame.
+ inverse depth in the reference frame.
Args:
inv_depth_ref (Tensor): The inverse depth in the reference frame.
@@ -191,7 +191,7 @@ def depth_warp(pinholes_i, pinhole_ref, inv_depth_ref, patch_i,
>>> pinhole_ref = torch.Tensor([1, 12]), # Nx12
>>> # warp the ith frame to reference by inverse depth in the reference
>>> inv_depth_ref = torch.ones(1, 1, 32, 32) # Nx1xHxW
- >>> img_ref = tgm.depth_warp( \
+ >>> img_ref = tgm.depth_warp(
>>> pinholes_i, pinhole_ref, inv_depth_ref, img_i) # NxCxHxW
"""
warper = DepthWarper(pinholes_i, width=width, height=height)
diff --git a/torchgeometry/homography_warper.py b/torchgeometry/homography_warper.py
index 4a6832968..3ac9b53aa 100644
--- a/torchgeometry/homography_warper.py
+++ b/torchgeometry/homography_warper.py
@@ -39,8 +39,8 @@ class HomographyWarper(nn.Module):
self.width = width
self.height = height
# create base grid to use for computing the flow
- self.grid = create_meshgrid(height, width,
- normalized_coordinates=True)
+ self.grid = create_meshgrid(
+ height, width, normalized_coordinates=True)
def warp_grid(self, H):
"""
@@ -118,8 +118,8 @@ class HomographyWarper(nn.Module):
raise TypeError("Patch and homography must be on the same device. \
Got patch.device: {} dst_H_src.device: {}."
.format(patch.device, dst_homo_src.device))
- return torch.nn.functional.grid_sample(patch,
- self.warp_grid(dst_homo_src), mode='bilinear',
+ return torch.nn.functional.grid_sample(
+ patch, self.warp_grid(dst_homo_src), mode='bilinear',
padding_mode=padding_mode)
# functional api
diff --git a/torchgeometry/imgwarp.py b/torchgeometry/imgwarp.py
index b57e416c5..1112556f0 100644
--- a/torchgeometry/imgwarp.py
+++ b/torchgeometry/imgwarp.py
@@ -12,39 +12,51 @@ __all__ = [
def center_transform(transform, height, width):
assert len(transform.shape) == 3, transform.shape
# move points to origin
- center_mat_origin = torch.unsqueeze(torch.eye(3,
- device=transform.device, dtype=transform.dtype), dim=0)
+ center_mat_origin = torch.unsqueeze(
+ torch.eye(
+ 3,
+ device=transform.device,
+ dtype=transform.dtype),
+ dim=0)
center_mat_origin[..., 0, 2] = float(width) / 2
center_mat_origin[..., 1, 2] = float(height) / 2
# move points from origin
- origin_mat_center = torch.unsqueeze(torch.eye(3,
- device=transform.device, dtype=transform.dtype), dim=0)
+ origin_mat_center = torch.unsqueeze(
+ torch.eye(
+ 3,
+ device=transform.device,
+ dtype=transform.dtype),
+ dim=0)
origin_mat_center[..., 0, 2] = -float(width) / 2
origin_mat_center[..., 1, 2] = -float(height) / 2
return torch.matmul(center_mat_origin,
- torch.matmul(transform, origin_mat_center))
+ torch.matmul(transform, origin_mat_center))
def normalize_transform_to_pix(transform, height, width):
assert len(transform.shape) == 3, transform.shape
normal_trans_pix = torch.tensor([[
- [2. / (width - 1), 0., -1.],
- [ 0., 2. / (height - 1), -1.],
- [ 0., 0., 1.]]],
+ [2. / (width - 1), 0., -1.],
+ [0., 2. / (height - 1), -1.],
+ [0., 0., 1.]]],
device=transform.device, dtype=transform.dtype) # 1x3x3
pix_trans_normal = inverse(normal_trans_pix) # 1x3x3
return torch.matmul(normal_trans_pix,
- torch.matmul(transform, pix_trans_normal))
+ torch.matmul(transform, pix_trans_normal))
def warp_perspective(src, M, dsize, flags='bilinear', border_mode=None,
border_value=0):
"""Applies a perspective transformation to an image.
- The function warpPerspective transforms the source image using the specified matrix:
+ The function warpPerspective transforms the source image using
+ the specified matrix:
.. math::
- dst(x, y) = src \left(\\frac{M_{11} x + M_{12} y + M_{33}}{M_{31} x + M_{32} y + M_{33}} , \\frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}}\\right)
+ dst(x, y) = src \left(
+ \\frac{M_{11} x + M_{12} y + M_{33}}{M_{31} x + M_{32} y + M_{33}} ,
+ \\frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}}
+ \\right)
Args:
src (Tensor): input image.
@@ -59,7 +71,8 @@ def warp_perspective(src, M, dsize, flags='bilinear', border_mode=None,
- Output: :math:`(B, C, H, W)`
.. note::
- See a working example `here <https://github.com/arraiy/torchgeometry/blob/master/examples/warp_perspective.ipynb>`_.
+ See a working example `here <https://github.com/arraiy/torchgeometry/
+ blob/master/examples/warp_perspective.ipynb>`_.
"""
if not torch.is_tensor(src):
raise TypeError("Input src type is not a torch.Tensor. Got {}"
diff --git a/torchgeometry/pinhole.py b/torchgeometry/pinhole.py
index d4b9e69aa..cda71503d 100644
--- a/torchgeometry/pinhole.py
+++ b/torchgeometry/pinhole.py
@@ -163,19 +163,19 @@ def get_optical_pose_base(pinholes):
def homography_i_H_ref(pinhole_i, pinhole_ref):
- """
- Homography from reference to ith pinhole
+ """Homography from reference to ith pinhole
.. math::
+
H_{ref}^{i} = K_{i} * T_{ref}^{i} * K_{ref}^{-1}
Args:
pinhole_i (Tensor): tensor with pinhole model for ith frame.
pinhole_ref (Tensor): tensor with pinhole model for reference frame.
- Return:
- Tensor: tensors that convert depth points (u, v, d) from pinhole_ref to
- pinhole_i (N, 4, 4).
+ Returns:
+ Tensor: tensors that convert depth points (u, v, d) from
+ pinhole_ref to pinhole_i.
Shape:
- Input: :math:`(N, 12)` and :math:`(N, 12)`