mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2026-02-25 23:56:00 +08:00
Compare commits
8 Commits
e9ed1cb178
...
e43ed8c76e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e43ed8c76e | ||
|
|
49f43402c6 | ||
|
|
90646d93ab | ||
|
|
eabb511410 | ||
|
|
e70188ebbc | ||
|
|
1bd911d534 | ||
|
|
3aadd19a2b | ||
|
|
42d66c1145 |
@@ -114,9 +114,7 @@ def mesh_laplacian_smoothing(meshes, method: str = "uniform"):
|
||||
if method == "cot":
|
||||
norm_w = torch.sparse.sum(L, dim=1).to_dense().view(-1, 1)
|
||||
idx = norm_w > 0
|
||||
# pyre-fixme[58]: `/` is not supported for operand types `float` and
|
||||
# `Tensor`.
|
||||
norm_w[idx] = 1.0 / norm_w[idx]
|
||||
norm_w[idx] = torch.reciprocal(norm_w[idx])
|
||||
else:
|
||||
L_sum = torch.sparse.sum(L, dim=1).to_dense().view(-1, 1)
|
||||
norm_w = 0.25 * inv_areas
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
# pyre-unsafe
|
||||
|
||||
import torch
|
||||
from pytorch3d import _C
|
||||
from pytorch3d.structures import Meshes, Pointclouds
|
||||
from torch.autograd import Function
|
||||
@@ -302,8 +303,7 @@ def point_mesh_edge_distance(meshes: Meshes, pcls: Pointclouds):
|
||||
point_to_cloud_idx = pcls.packed_to_cloud_idx() # (sum(P_i), )
|
||||
num_points_per_cloud = pcls.num_points_per_cloud() # (N,)
|
||||
weights_p = num_points_per_cloud.gather(0, point_to_cloud_idx)
|
||||
# pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`.
|
||||
weights_p = 1.0 / weights_p.float()
|
||||
weights_p = torch.reciprocal(weights_p.float())
|
||||
point_to_edge = point_to_edge * weights_p
|
||||
point_dist = point_to_edge.sum() / N
|
||||
|
||||
@@ -377,8 +377,7 @@ def point_mesh_face_distance(
|
||||
point_to_cloud_idx = pcls.packed_to_cloud_idx() # (sum(P_i),)
|
||||
num_points_per_cloud = pcls.num_points_per_cloud() # (N,)
|
||||
weights_p = num_points_per_cloud.gather(0, point_to_cloud_idx)
|
||||
# pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`.
|
||||
weights_p = 1.0 / weights_p.float()
|
||||
weights_p = torch.reciprocal(weights_p.float())
|
||||
point_to_face = point_to_face * weights_p
|
||||
point_dist = point_to_face.sum() / N
|
||||
|
||||
|
||||
@@ -55,11 +55,9 @@ def laplacian(verts: torch.Tensor, edges: torch.Tensor) -> torch.Tensor:
|
||||
# We construct the Laplacian matrix by adding the non diagonal values
|
||||
# i.e. L[i, j] = 1 ./ deg(i) if (i, j) is an edge
|
||||
deg0 = deg[e0]
|
||||
# pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`.
|
||||
deg0 = torch.where(deg0 > 0.0, 1.0 / deg0, deg0)
|
||||
deg0 = torch.where(deg0 > 0.0, torch.reciprocal(deg0), deg0)
|
||||
deg1 = deg[e1]
|
||||
# pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`.
|
||||
deg1 = torch.where(deg1 > 0.0, 1.0 / deg1, deg1)
|
||||
deg1 = torch.where(deg1 > 0.0, torch.reciprocal(deg1), deg1)
|
||||
val = torch.cat([deg0, deg1])
|
||||
L = torch.sparse_coo_tensor(idx, val, (V, V), dtype=torch.float32)
|
||||
|
||||
@@ -137,8 +135,7 @@ def cot_laplacian(
|
||||
val = torch.stack([area] * 3, dim=1).view(-1)
|
||||
inv_areas.scatter_add_(0, idx, val)
|
||||
idx = inv_areas > 0
|
||||
# pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`.
|
||||
inv_areas[idx] = 1.0 / inv_areas[idx]
|
||||
inv_areas[idx] = torch.reciprocal(inv_areas[idx])
|
||||
inv_areas = inv_areas.view(-1, 1)
|
||||
|
||||
return L, inv_areas
|
||||
|
||||
@@ -629,10 +629,8 @@ class FoVPerspectiveCameras(CamerasBase):
|
||||
# so the so the z sign is 1.0.
|
||||
z_sign = 1.0
|
||||
|
||||
# pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`.
|
||||
K[:, 0, 0] = 2.0 * znear / (max_x - min_x)
|
||||
# pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`.
|
||||
K[:, 1, 1] = 2.0 * znear / (max_y - min_y)
|
||||
K[:, 0, 0] = torch.div(2.0 * znear, max_x - min_x)
|
||||
K[:, 1, 1] = torch.div(2.0 * znear, max_y - min_y)
|
||||
K[:, 0, 2] = (max_x + min_x) / (max_x - min_x)
|
||||
K[:, 1, 2] = (max_y + min_y) / (max_y - min_y)
|
||||
K[:, 3, 2] = z_sign * ones
|
||||
@@ -1178,9 +1176,7 @@ class PerspectiveCameras(CamerasBase):
|
||||
xy_inv_depth = torch.cat(
|
||||
# pyre-fixme[6]: For 1st argument expected `Union[List[Tensor],
|
||||
# tuple[Tensor, ...]]` but got `Tuple[Tensor, float]`.
|
||||
# pyre-fixme[58]: `/` is not supported for operand types `float` and
|
||||
# `Tensor`.
|
||||
(xy_depth[..., :2], 1.0 / xy_depth[..., 2:3]),
|
||||
(xy_depth[..., :2], torch.reciprocal(xy_depth[..., 2:3])),
|
||||
dim=-1, # type: ignore
|
||||
)
|
||||
return unprojection_transform.transform_points(xy_inv_depth)
|
||||
|
||||
@@ -434,13 +434,7 @@ def clip_faces(
|
||||
# These will then be filled in for each case.
|
||||
###########################################
|
||||
F_clipped = (
|
||||
F
|
||||
# pyre-fixme[58]: `+` is not supported for operand types `int` and
|
||||
# `Union[bool, float, int]`.
|
||||
+ faces_delta_cum[-1].item()
|
||||
# pyre-fixme[58]: `+` is not supported for operand types `int` and
|
||||
# `Union[bool, float, int]`.
|
||||
+ faces_delta[-1].item()
|
||||
F + int(faces_delta_cum[-1].item()) + int(faces_delta[-1].item())
|
||||
) # Total number of faces in the new Meshes
|
||||
face_verts_clipped = torch.zeros(
|
||||
(F_clipped, 3, 3), dtype=face_verts_unclipped.dtype, device=device
|
||||
|
||||
@@ -71,9 +71,7 @@ def _list_to_padded_wrapper(
|
||||
# pyre-fixme[6]: For 2nd param expected `int` but got `Union[bool, float, int]`.
|
||||
x_reshaped.append(y.reshape(-1, D))
|
||||
x_padded = list_to_padded(x_reshaped, pad_size=pad_size, pad_value=pad_value)
|
||||
# pyre-fixme[58]: `+` is not supported for operand types `Tuple[int, int]` and
|
||||
# `Size`.
|
||||
return x_padded.reshape((N, -1) + reshape_dims)
|
||||
return x_padded.reshape((N, -1) + tuple(reshape_dims))
|
||||
|
||||
|
||||
def _padded_to_list_wrapper(
|
||||
@@ -104,9 +102,7 @@ def _padded_to_list_wrapper(
|
||||
# pyre-fixme[6]: For 3rd param expected `int` but got `Union[bool, float, int]`.
|
||||
x_reshaped = x.reshape(N, M, D)
|
||||
x_list = padded_to_list(x_reshaped, split_size=split_size)
|
||||
# pyre-fixme[58]: `+` is not supported for operand types `Tuple[typing.Any]` and
|
||||
# `Size`.
|
||||
x_list = [xl.reshape((xl.shape[0],) + reshape_dims) for xl in x_list]
|
||||
x_list = [xl.reshape((xl.shape[0],) + tuple(reshape_dims)) for xl in x_list]
|
||||
return x_list
|
||||
|
||||
|
||||
|
||||
@@ -52,8 +52,7 @@ def quaternion_to_matrix(quaternions: torch.Tensor) -> torch.Tensor:
|
||||
Rotation matrices as tensor of shape (..., 3, 3).
|
||||
"""
|
||||
r, i, j, k = torch.unbind(quaternions, -1)
|
||||
# pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`.
|
||||
two_s = 2.0 / (quaternions * quaternions).sum(-1)
|
||||
two_s = torch.div(2.0, (quaternions * quaternions).sum(-1))
|
||||
|
||||
o = torch.stack(
|
||||
(
|
||||
@@ -137,18 +136,18 @@ def matrix_to_quaternion(matrix: torch.Tensor) -> torch.Tensor:
|
||||
# we produce the desired quaternion multiplied by each of r, i, j, k
|
||||
quat_by_rijk = torch.stack(
|
||||
[
|
||||
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and
|
||||
# `int`.
|
||||
torch.stack([q_abs[..., 0] ** 2, m21 - m12, m02 - m20, m10 - m01], dim=-1),
|
||||
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and
|
||||
# `int`.
|
||||
torch.stack([m21 - m12, q_abs[..., 1] ** 2, m10 + m01, m02 + m20], dim=-1),
|
||||
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and
|
||||
# `int`.
|
||||
torch.stack([m02 - m20, m10 + m01, q_abs[..., 2] ** 2, m12 + m21], dim=-1),
|
||||
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and
|
||||
# `int`.
|
||||
torch.stack([m10 - m01, m20 + m02, m21 + m12, q_abs[..., 3] ** 2], dim=-1),
|
||||
torch.stack(
|
||||
[torch.square(q_abs[..., 0]), m21 - m12, m02 - m20, m10 - m01], dim=-1
|
||||
),
|
||||
torch.stack(
|
||||
[m21 - m12, torch.square(q_abs[..., 1]), m10 + m01, m02 + m20], dim=-1
|
||||
),
|
||||
torch.stack(
|
||||
[m02 - m20, m10 + m01, torch.square(q_abs[..., 2]), m12 + m21], dim=-1
|
||||
),
|
||||
torch.stack(
|
||||
[m10 - m01, m20 + m02, m21 + m12, torch.square(q_abs[..., 3])], dim=-1
|
||||
),
|
||||
],
|
||||
dim=-2,
|
||||
)
|
||||
|
||||
@@ -623,9 +623,7 @@ class Scale(Transform3d):
|
||||
Return the inverse of self._matrix.
|
||||
"""
|
||||
xyz = torch.stack([self._matrix[:, i, i] for i in range(4)], dim=1)
|
||||
# pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`.
|
||||
ixyz = 1.0 / xyz
|
||||
# pyre-fixme[6]: For 1st param expected `Tensor` but got `float`.
|
||||
ixyz = torch.reciprocal(xyz)
|
||||
imat = torch.diag_embed(ixyz, dim1=1, dim2=2)
|
||||
return imat
|
||||
|
||||
|
||||
Reference in New Issue
Block a user