diff --git a/pytorch3d/common/compat.py b/pytorch3d/common/compat.py index f2edde0e..5f25a185 100644 --- a/pytorch3d/common/compat.py +++ b/pytorch3d/common/compat.py @@ -19,7 +19,7 @@ def solve(A: torch.Tensor, B: torch.Tensor) -> torch.Tensor: # pragma: no cover Like torch.linalg.solve, tries to return X such that AX=B, with A square. """ - if hasattr(torch.linalg, "solve"): + if hasattr(torch, "linalg") and hasattr(torch.linalg, "solve"): # PyTorch version >= 1.8.0 return torch.linalg.solve(A, B) @@ -31,7 +31,7 @@ def lstsq(A: torch.Tensor, B: torch.Tensor) -> torch.Tensor: # pragma: no cover Like torch.linalg.lstsq, tries to return X such that AX=B. """ - if hasattr(torch.linalg, "lstsq"): + if hasattr(torch, "linalg") and hasattr(torch.linalg, "lstsq"): # PyTorch version >= 1.9 return torch.linalg.lstsq(A, B).solution @@ -45,7 +45,7 @@ def qr(A: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]: # pragma: no cove """ Like torch.linalg.qr. """ - if hasattr(torch.linalg, "qr"): + if hasattr(torch, "linalg") and hasattr(torch.linalg, "qr"): # PyTorch version >= 1.9 return torch.linalg.qr(A) return torch.qr(A) diff --git a/pytorch3d/renderer/cameras.py b/pytorch3d/renderer/cameras.py index b36e1cee..217974d6 100644 --- a/pytorch3d/renderer/cameras.py +++ b/pytorch3d/renderer/cameras.py @@ -6,7 +6,7 @@ import math import warnings -from typing import Optional, Sequence, Tuple, Union, List +from typing import List, Optional, Sequence, Tuple, Union import numpy as np import torch @@ -259,8 +259,9 @@ class CamerasBase(TensorProperties): # users might might have to implement the screen to NDC transform based # on the definition of the camera parameters. # See PerspectiveCameras/OrthographicCameras for an example. - # We don't flip xy because we assume that world points are in PyTorch3D coodrinates - # and thus conversion from screen to ndc is a mere scaling from image to [-1, 1] scale. + # We don't flip xy because we assume that world points are in + # PyTorch3D coordinates, and thus conversion from screen to ndc + # is a mere scaling from image to [-1, 1] scale. return get_screen_to_ndc_transform(self, with_xyflip=False, **kwargs) def transform_points_ndc( diff --git a/pytorch3d/renderer/points/pulsar/unified.py b/pytorch3d/renderer/points/pulsar/unified.py index 8ed5980b..5c1fb51d 100644 --- a/pytorch3d/renderer/points/pulsar/unified.py +++ b/pytorch3d/renderer/points/pulsar/unified.py @@ -551,17 +551,15 @@ class PulsarPointsRenderer(nn.Module): otherargs["bg_col"] = bg_col # Go! images.append( - torch.flipud( - self.renderer( - vert_pos=vert_pos, - vert_col=vert_col, - vert_rad=vert_rad, - cam_params=cam_params, - gamma=gamma, - max_depth=zfar, - min_depth=znear, - **otherargs, - ) - ) + self.renderer( + vert_pos=vert_pos, + vert_col=vert_col, + vert_rad=vert_rad, + cam_params=cam_params, + gamma=gamma, + max_depth=zfar, + min_depth=znear, + **otherargs, + ).flip(dims=[0]) ) return torch.stack(images, dim=0) diff --git a/pytorch3d/transforms/rotation_conversions.py b/pytorch3d/transforms/rotation_conversions.py index 396eaa18..c3d01488 100644 --- a/pytorch3d/transforms/rotation_conversions.py +++ b/pytorch3d/transforms/rotation_conversions.py @@ -140,8 +140,10 @@ def matrix_to_quaternion(matrix: torch.Tensor) -> torch.Tensor: dim=-2, ) - # clipping is not important here; if q_abs is small, the candidate won't be picked - quat_candidates = quat_by_rijk / (2.0 * q_abs[..., None].clip(0.1)) + # We floor here at 0.1 but the exact level is not important; if q_abs is small, + # the candidate won't be picked. + # pyre-ignore [16]: `torch.Tensor` has no attribute `new_tensor`. + quat_candidates = quat_by_rijk / (2.0 * q_abs[..., None].max(q_abs.new_tensor(0.1))) # if not for numerical problems, quat_candidates[i] should be same (up to a sign), # forall i; we pick the best-conditioned one (with the largest denominator)