Skip to content

Commit 5284de6

Browse files
patricklabatutfacebook-github-bot
authored andcommitted
Deprecate so3_exponential_map
Summary: Deprecate the `so3_exponential_map()` function in favor of its alias `so3_exp_map()`: this aligns with the naming of `so3_log_map()` and the recently introduced `se3_exp_map()` / `se3_log_map()` pair. Reviewed By: bottler Differential Revision: D29329966 fbshipit-source-id: b6f60b9e86b2995f70b1fbeb16f9feea05c55de9
1 parent f593bfd commit 5284de6

11 files changed

+35
-28
lines changed

docs/tutorials/bundle_adjustment.ipynb

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"Our optimization seeks to align the estimated (orange) cameras with the ground truth (purple) cameras, by minimizing the discrepancies between pairs of relative cameras. Thus, the solution to the problem should look as follows:\n",
4242
"![Solution](https://github.com/facebookresearch/pytorch3d/blob/master/docs/tutorials/data/bundle_adjustment_final.png?raw=1)\n",
4343
"\n",
44-
"In practice, the camera extrinsics $g_{ij}$ and $g_i$ are represented using objects from the `SfMPerspectiveCameras` class initialized with the corresponding rotation and translation matrices `R_absolute` and `T_absolute` that define the extrinsic parameters $g = (R, T); R \\in SO(3); T \\in \\mathbb{R}^3$. In order to ensure that `R_absolute` is a valid rotation matrix, we represent it using an exponential map (implemented with `so3_exponential_map`) of the axis-angle representation of the rotation `log_R_absolute`.\n",
44+
"In practice, the camera extrinsics $g_{ij}$ and $g_i$ are represented using objects from the `SfMPerspectiveCameras` class initialized with the corresponding rotation and translation matrices `R_absolute` and `T_absolute` that define the extrinsic parameters $g = (R, T); R \\in SO(3); T \\in \\mathbb{R}^3$. In order to ensure that `R_absolute` is a valid rotation matrix, we represent it using an exponential map (implemented with `so3_exp_map`) of the axis-angle representation of the rotation `log_R_absolute`.\n",
4545
"\n",
4646
"Note that the solution to this problem could only be recovered up to an unknown global rigid transformation $g_{glob} \\in SE(3)$. Thus, for simplicity, we assume knowledge of the absolute extrinsics of the first camera $g_0$. We set $g_0$ as a trivial camera $g_0 = (I, \\vec{0})$.\n"
4747
]
@@ -122,7 +122,7 @@
122122
"# imports\n",
123123
"import torch\n",
124124
"from pytorch3d.transforms.so3 import (\n",
125-
" so3_exponential_map,\n",
125+
" so3_exp_map,\n",
126126
" so3_relative_angle,\n",
127127
")\n",
128128
"from pytorch3d.renderer.cameras import (\n",
@@ -328,7 +328,7 @@
328328
"\n",
329329
"As mentioned earlier, `log_R_absolute` is the axis angle representation of the rotation part of our absolute cameras. We can obtain the 3x3 rotation matrix `R_absolute` that corresponds to `log_R_absolute` with:\n",
330330
"\n",
331-
"`R_absolute = so3_exponential_map(log_R_absolute)`\n"
331+
"`R_absolute = so3_exp_map(log_R_absolute)`\n"
332332
]
333333
},
334334
{
@@ -378,7 +378,7 @@
378378
" # compute the absolute camera rotations as \n",
379379
" # an exponential map of the logarithms (=axis-angles)\n",
380380
" # of the absolute rotations\n",
381-
" R_absolute = so3_exponential_map(log_R_absolute * camera_mask)\n",
381+
" R_absolute = so3_exp_map(log_R_absolute * camera_mask)\n",
382382
"\n",
383383
" # get the current absolute cameras\n",
384384
" cameras_absolute = SfMPerspectiveCameras(\n",

docs/tutorials/fit_simple_neural_radiance_field.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
"\n",
9696
"# Data structures and functions for rendering\n",
9797
"from pytorch3d.structures import Volumes\n",
98-
"from pytorch3d.transforms import so3_exponential_map\n",
98+
"from pytorch3d.transforms import so3_exp_map\n",
9999
"from pytorch3d.renderer import (\n",
100100
" FoVPerspectiveCameras, \n",
101101
" NDCGridRaysampler,\n",
@@ -803,7 +803,7 @@
803803
"def generate_rotating_nerf(neural_radiance_field, n_frames = 50):\n",
804804
" logRs = torch.zeros(n_frames, 3, device=device)\n",
805805
" logRs[:, 1] = torch.linspace(-3.14, 3.14, n_frames, device=device)\n",
806-
" Rs = so3_exponential_map(logRs)\n",
806+
" Rs = so3_exp_map(logRs)\n",
807807
" Ts = torch.zeros(n_frames, 3, device=device)\n",
808808
" Ts[:, 2] = 2.7\n",
809809
" frames = []\n",

docs/tutorials/fit_textured_volume.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
" NDCGridRaysampler,\n",
9191
" EmissionAbsorptionRaymarcher\n",
9292
")\n",
93-
"from pytorch3d.transforms import so3_exponential_map\n",
93+
"from pytorch3d.transforms import so3_exp_map\n",
9494
"\n",
9595
"# add path for demo utils functions \n",
9696
"sys.path.append(os.path.abspath(''))\n",
@@ -405,7 +405,7 @@
405405
"def generate_rotating_volume(volume_model, n_frames = 50):\n",
406406
" logRs = torch.zeros(n_frames, 3, device=device)\n",
407407
" logRs[:, 1] = torch.linspace(0.0, 2.0 * 3.14, n_frames, device=device)\n",
408-
" Rs = so3_exponential_map(logRs)\n",
408+
" Rs = so3_exp_map(logRs)\n",
409409
" Ts = torch.zeros(n_frames, 3, device=device)\n",
410410
" Ts[:, 2] = 2.7\n",
411411
" frames = []\n",

pytorch3d/transforms/so3.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7+
import warnings
78
from typing import Tuple
89

910
import torch
@@ -134,7 +135,15 @@ def so3_exp_map(log_rot: torch.Tensor, eps: float = 0.0001) -> torch.Tensor:
134135
return _so3_exp_map(log_rot, eps=eps)[0]
135136

136137

137-
so3_exponential_map = so3_exp_map
138+
def so3_exponential_map(log_rot: torch.Tensor, eps: float = 0.0001) -> torch.Tensor:
139+
warnings.warn(
140+
"""so3_exponential_map is deprecated,
141+
Use so3_exp_map instead.
142+
so3_exponential_map will be removed in future releases.""",
143+
PendingDeprecationWarning,
144+
)
145+
146+
return so3_exp_map(log_rot, eps)
138147

139148

140149
def _so3_exp_map(

pytorch3d/utils/camera_conversions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import torch
1010

1111
from ..renderer import PerspectiveCameras
12-
from ..transforms import so3_exponential_map, so3_log_map
12+
from ..transforms import so3_exp_map, so3_log_map
1313

1414

1515
def cameras_from_opencv_projection(
@@ -51,7 +51,7 @@ def cameras_from_opencv_projection(
5151
cameras_pytorch3d: A batch of `N` cameras in the PyTorch3D convention.
5252
"""
5353

54-
R = so3_exponential_map(rvec)
54+
R = so3_exp_map(rvec)
5555
focal_length = torch.stack([camera_matrix[:, 0, 0], camera_matrix[:, 1, 1]], dim=-1)
5656
principal_point = camera_matrix[:, :2, 2]
5757

tests/test_camera_conversions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import torch
1313
from common_testing import TestCaseMixin, get_tests_dir
1414
from pytorch3d.ops import eyes
15-
from pytorch3d.transforms import so3_exponential_map, so3_log_map
15+
from pytorch3d.transforms import so3_exp_map, so3_log_map
1616
from pytorch3d.utils import (
1717
cameras_from_opencv_projection,
1818
opencv_from_cameras_projection,
@@ -33,7 +33,7 @@ def cv2_project_points(pts, rvec, tvec, camera_matrix):
3333
"""
3434
Reproduces the `cv2.projectPoints` function from OpenCV using PyTorch.
3535
"""
36-
R = so3_exponential_map(rvec)
36+
R = so3_exp_map(rvec)
3737
pts_proj_3d = (
3838
camera_matrix.bmm(R.bmm(pts.permute(0, 2, 1)) + tvec[:, :, None])
3939
).permute(0, 2, 1)

tests/test_cameras.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
)
5454
from pytorch3d.transforms import Transform3d
5555
from pytorch3d.transforms.rotation_conversions import random_rotations
56-
from pytorch3d.transforms.so3 import so3_exponential_map
56+
from pytorch3d.transforms.so3 import so3_exp_map
5757

5858

5959
# Naive function adapted from SoftRasterizer for test purposes.
@@ -145,7 +145,7 @@ def init_random_cameras(
145145
T = torch.randn(batch_size, 3) * 0.03
146146
if not random_z:
147147
T[:, 2] = 4
148-
R = so3_exponential_map(torch.randn(batch_size, 3) * 3.0)
148+
R = so3_exp_map(torch.randn(batch_size, 3) * 3.0)
149149
cam_params = {"R": R, "T": T}
150150
if cam_type in (OpenGLPerspectiveCameras, OpenGLOrthographicCameras):
151151
cam_params["znear"] = torch.rand(batch_size) * 10 + 0.1
@@ -509,7 +509,7 @@ def test_get_camera_center(self, batch_size=10):
509509
def init_equiv_cameras_ndc_screen(cam_type: CamerasBase, batch_size: int):
510510
T = torch.randn(batch_size, 3) * 0.03
511511
T[:, 2] = 4
512-
R = so3_exponential_map(torch.randn(batch_size, 3) * 3.0)
512+
R = so3_exp_map(torch.randn(batch_size, 3) * 3.0)
513513
screen_cam_params = {"R": R, "T": T}
514514
ndc_cam_params = {"R": R, "T": T}
515515
if cam_type in (OrthographicCameras, PerspectiveCameras):

tests/test_cameras_alignment.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
SfMPerspectiveCameras,
1818
)
1919
from pytorch3d.transforms.rotation_conversions import random_rotations
20-
from pytorch3d.transforms.so3 import so3_exponential_map, so3_relative_angle
20+
from pytorch3d.transforms.so3 import so3_exp_map, so3_relative_angle
2121
from test_cameras import init_random_cameras
2222

2323

@@ -95,9 +95,7 @@ def _corresponding_cameras_alignment_test_case(
9595
) * s_align_gt
9696

9797
if add_noise != 0.0:
98-
R_new = torch.bmm(
99-
R_new, so3_exponential_map(torch.randn_like(T_new) * add_noise)
100-
)
98+
R_new = torch.bmm(R_new, so3_exp_map(torch.randn_like(T_new) * add_noise))
10199
T_new += torch.randn_like(T_new) * add_noise
102100

103101
# create new cameras from R_new and T_new

tests/test_points_to_volumes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from pytorch3d.structures.meshes import Meshes
1616
from pytorch3d.structures.pointclouds import Pointclouds
1717
from pytorch3d.structures.volumes import Volumes
18-
from pytorch3d.transforms.so3 import so3_exponential_map
18+
from pytorch3d.transforms.so3 import so3_exp_map
1919

2020

2121
DEBUG = False
@@ -138,7 +138,7 @@ def init_uniform_y_rotations(batch_size: int = 10):
138138
angles = torch.linspace(0, 2.0 * np.pi, batch_size + 1, device=device)
139139
angles = angles[:batch_size]
140140
log_rots = axis[None, :] * angles[:, None]
141-
R = so3_exponential_map(log_rots)
141+
R = so3_exp_map(log_rots)
142142
return R
143143

144144

tests/test_r2n2.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
)
3030
from pytorch3d.renderer.cameras import get_world_to_view_transform
3131
from pytorch3d.transforms import Transform3d
32-
from pytorch3d.transforms.so3 import so3_exponential_map
32+
from pytorch3d.transforms.so3 import so3_exp_map
3333
from torch.utils.data import DataLoader
3434

3535

@@ -316,7 +316,7 @@ def test_blender_camera(self):
316316
"""
317317
# Test get_world_to_view_transform.
318318
T = torch.randn(10, 3)
319-
R = so3_exponential_map(torch.randn(10, 3) * 3.0)
319+
R = so3_exp_map(torch.randn(10, 3) * 3.0)
320320
RT = get_world_to_view_transform(R=R, T=T)
321321
cam = BlenderCamera(R=R, T=T)
322322
RT_class = cam.get_world_to_view_transform()

tests/test_transforms.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import torch
1212
from common_testing import TestCaseMixin
13-
from pytorch3d.transforms.so3 import so3_exponential_map
13+
from pytorch3d.transforms.so3 import so3_exp_map
1414
from pytorch3d.transforms.transform3d import (
1515
Rotate,
1616
RotateAxisAngle,
@@ -146,7 +146,7 @@ def test_translate(self):
146146
self.assertTrue(torch.allclose(normals_out, normals_out_expected))
147147

148148
def test_rotate(self):
149-
R = so3_exponential_map(torch.randn((1, 3)))
149+
R = so3_exp_map(torch.randn((1, 3)))
150150
t = Transform3d().rotate(R)
151151
points = torch.tensor([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.5, 0.5, 0.0]]).view(
152152
1, 3, 3
@@ -273,7 +273,7 @@ def test_inverse(self, batch_size=5):
273273
)
274274
elif choice <= 2.0 / 3.0:
275275
t_ = Rotate(
276-
so3_exponential_map(
276+
so3_exp_map(
277277
torch.randn(
278278
(batch_size, 3), dtype=torch.float32, device=device
279279
)
@@ -894,7 +894,7 @@ def test_invalid_dimensions(self):
894894
def test_inverse(self, batch_size=5):
895895
device = torch.device("cuda:0")
896896
log_rot = torch.randn((batch_size, 3), dtype=torch.float32, device=device)
897-
R = so3_exponential_map(log_rot)
897+
R = so3_exp_map(log_rot)
898898
t = Rotate(R)
899899
im = t.inverse()._matrix
900900
im_2 = t._matrix.inverse()

0 commit comments

Comments
 (0)