mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-12-21 23:00:34 +08:00
suppress errors in vision/fair/pytorch3d
Differential Revision: D37172764 fbshipit-source-id: a2ec367e56de2781a17f5e708eb5832ec9d7e6b4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ea4f3260e4
commit
7978ffd1e4
@@ -119,11 +119,16 @@ def corresponding_cameras_alignment(
|
||||
|
||||
# create a new cameras object and set the R and T accordingly
|
||||
cameras_src_aligned = cameras_src.clone()
|
||||
# pyre-fixme[6]: For 2nd param expected `Tensor` but got `Union[Tensor, Module]`.
|
||||
cameras_src_aligned.R = torch.bmm(align_t_R.expand_as(cameras_src.R), cameras_src.R)
|
||||
cameras_src_aligned.T = (
|
||||
torch.bmm(
|
||||
align_t_T[:, None].repeat(cameras_src.R.shape[0], 1, 1), cameras_src.R
|
||||
align_t_T[:, None].repeat(cameras_src.R.shape[0], 1, 1),
|
||||
# pyre-fixme[6]: For 2nd param expected `Tensor` but got `Union[Tensor,
|
||||
# Module]`.
|
||||
cameras_src.R,
|
||||
)[:, 0]
|
||||
# pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C._TensorBase.__m...
|
||||
+ cameras_src.T * align_t_s
|
||||
)
|
||||
|
||||
@@ -171,6 +176,7 @@ def _align_camera_extrinsics(
|
||||
R_A = (U V^T)^T
|
||||
```
|
||||
"""
|
||||
# pyre-fixme[6]: For 1st param expected `Tensor` but got `Union[Tensor, Module]`.
|
||||
RRcov = torch.bmm(cameras_src.R, cameras_tgt.R.transpose(2, 1)).mean(0)
|
||||
U, _, V = torch.svd(RRcov)
|
||||
align_t_R = V @ U.t()
|
||||
@@ -204,11 +210,13 @@ def _align_camera_extrinsics(
|
||||
# `Union[BoundMethod[typing.Callable(torch.Tensor.__getitem__)[[Named(self,
|
||||
# torch.Tensor), Named(item, typing.Any)], typing.Any], torch.Tensor],
|
||||
# torch.Tensor, torch.nn.Module]` is not a function.
|
||||
# pyre-fixme[6]: For 1st param expected `Tensor` but got `Union[Tensor, Module]`.
|
||||
A = torch.bmm(cameras_src.R, cameras_src.T[:, :, None])[:, :, 0]
|
||||
# pyre-fixme[29]:
|
||||
# `Union[BoundMethod[typing.Callable(torch.Tensor.__getitem__)[[Named(self,
|
||||
# torch.Tensor), Named(item, typing.Any)], typing.Any], torch.Tensor],
|
||||
# torch.Tensor, torch.nn.Module]` is not a function.
|
||||
# pyre-fixme[6]: For 1st param expected `Tensor` but got `Union[Tensor, Module]`.
|
||||
B = torch.bmm(cameras_src.R, cameras_tgt.T[:, :, None])[:, :, 0]
|
||||
Amu = A.mean(0, keepdim=True)
|
||||
Bmu = B.mean(0, keepdim=True)
|
||||
@@ -217,6 +225,7 @@ def _align_camera_extrinsics(
|
||||
# of centered A and centered B
|
||||
Ac = A - Amu
|
||||
Bc = B - Bmu
|
||||
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
|
||||
align_t_s = (Ac * Bc).mean() / (Ac**2).mean().clamp(eps)
|
||||
else:
|
||||
# set the scale to identity
|
||||
|
||||
@@ -235,7 +235,6 @@ def cubify(voxels, thresh, device=None, align: str = "topleft") -> Meshes:
|
||||
idlenum = idleverts.cumsum(1)
|
||||
|
||||
verts_list = [
|
||||
# pyre-fixme[16]: `Tensor` has no attribute `index_select`.
|
||||
grid_verts.index_select(0, (idleverts[n] == 0).nonzero(as_tuple=False)[:, 0])
|
||||
for n in range(N)
|
||||
]
|
||||
|
||||
@@ -119,7 +119,6 @@ def gather_scatter_python(input, edges, directed: bool = False):
|
||||
idx0 = edges[:, 0].view(num_edges, 1).expand(num_edges, input_feature_dim)
|
||||
idx1 = edges[:, 1].view(num_edges, 1).expand(num_edges, input_feature_dim)
|
||||
|
||||
# pyre-fixme[16]: `Tensor` has no attribute `scatter_add`.
|
||||
output = output.scatter_add(0, idx0, input.gather(0, idx1))
|
||||
if not directed:
|
||||
output = output.scatter_add(0, idx1, input.gather(0, idx0))
|
||||
|
||||
@@ -94,7 +94,6 @@ def interpolate_face_attributes_python(
|
||||
pix_to_face = pix_to_face.clone()
|
||||
pix_to_face[mask] = 0
|
||||
idx = pix_to_face.view(N * H * W * K, 1, 1).expand(N * H * W * K, 3, D)
|
||||
# pyre-fixme[16]: `Tensor` has no attribute `gather`.
|
||||
pixel_face_vals = face_attributes.gather(0, idx).view(N, H, W, K, 3, D)
|
||||
pixel_vals = (barycentric_coords[..., None] * pixel_face_vals).sum(dim=-2)
|
||||
pixel_vals[mask] = 0 # Replace masked values in output.
|
||||
|
||||
@@ -47,7 +47,6 @@ _box_triangles = [
|
||||
|
||||
def _check_coplanar(boxes: torch.Tensor, eps: float = 1e-4) -> None:
|
||||
faces = torch.tensor(_box_planes, dtype=torch.int64, device=boxes.device)
|
||||
# pyre-fixme[16]: `boxes` has no attribute `index_select`.
|
||||
verts = boxes.index_select(index=faces.view(-1), dim=1)
|
||||
B = boxes.shape[0]
|
||||
P, V = faces.shape
|
||||
@@ -74,7 +73,6 @@ def _check_nonzero(boxes: torch.Tensor, eps: float = 1e-4) -> None:
|
||||
Checks that the sides of the box have a non zero area
|
||||
"""
|
||||
faces = torch.tensor(_box_triangles, dtype=torch.int64, device=boxes.device)
|
||||
# pyre-fixme[16]: `boxes` has no attribute `index_select`.
|
||||
verts = boxes.index_select(index=faces.view(-1), dim=1)
|
||||
B = boxes.shape[0]
|
||||
T, V = faces.shape
|
||||
|
||||
@@ -84,7 +84,6 @@ class _knn_points(Function):
|
||||
dists[mask] = 0
|
||||
else:
|
||||
dists, sort_idx = dists.sort(dim=2)
|
||||
# pyre-fixme[16]: `Tensor` has no attribute `gather`.
|
||||
idx = idx.gather(2, sort_idx)
|
||||
|
||||
ctx.save_for_backward(p1, p2, lengths1, lengths2, idx)
|
||||
|
||||
@@ -45,6 +45,7 @@ def laplacian(verts: torch.Tensor, edges: torch.Tensor) -> torch.Tensor:
|
||||
# i.e. A[i, j] = 1 if (i,j) is an edge, or
|
||||
# A[e0, e1] = 1 & A[e1, e0] = 1
|
||||
ones = torch.ones(idx.shape[1], dtype=torch.float32, device=verts.device)
|
||||
# pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
|
||||
A = torch.sparse.FloatTensor(idx, ones, (V, V))
|
||||
|
||||
# the sum of i-th row of A gives the degree of the i-th vertex
|
||||
@@ -53,16 +54,20 @@ 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)
|
||||
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)
|
||||
val = torch.cat([deg0, deg1])
|
||||
# pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
|
||||
L = torch.sparse.FloatTensor(idx, val, (V, V))
|
||||
|
||||
# Then we add the diagonal values L[i, i] = -1.
|
||||
idx = torch.arange(V, device=verts.device)
|
||||
idx = torch.stack([idx, idx], dim=0)
|
||||
ones = torch.ones(idx.shape[1], dtype=torch.float32, device=verts.device)
|
||||
# pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
|
||||
L -= torch.sparse.FloatTensor(idx, ones, (V, V))
|
||||
|
||||
return L
|
||||
@@ -119,6 +124,7 @@ def cot_laplacian(
|
||||
ii = faces[:, [1, 2, 0]]
|
||||
jj = faces[:, [2, 0, 1]]
|
||||
idx = torch.stack([ii, jj], dim=0).view(2, F * 3)
|
||||
# pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
|
||||
L = torch.sparse.FloatTensor(idx, cot.view(-1), (V, V))
|
||||
|
||||
# Make it symmetric; this means we are also setting
|
||||
@@ -133,6 +139,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 = inv_areas.view(-1, 1)
|
||||
|
||||
@@ -166,6 +173,7 @@ def norm_laplacian(
|
||||
e01 = edges.t() # (2, E)
|
||||
|
||||
V = verts.shape[0]
|
||||
# pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
|
||||
L = torch.sparse.FloatTensor(e01, w01, (V, V))
|
||||
L = L + L.t()
|
||||
|
||||
|
||||
@@ -347,4 +347,5 @@ def _get_value(point: Tuple[int, int, int], volume_data: torch.Tensor) -> float:
|
||||
data: scalar value in the volume at the given point
|
||||
"""
|
||||
x, y, z = point
|
||||
# pyre-fixme[7]: Expected `float` but got `Tensor`.
|
||||
return volume_data[z][y][x]
|
||||
|
||||
@@ -49,7 +49,6 @@ def taubin_smoothing(
|
||||
total_weight = torch.sparse.sum(L, dim=1).to_dense().view(-1, 1)
|
||||
verts = (1 - lambd) * verts + lambd * torch.mm(L, verts) / total_weight
|
||||
|
||||
# pyre-ignore
|
||||
L = norm_laplacian(verts, edges)
|
||||
total_weight = torch.sparse.sum(L, dim=1).to_dense().view(-1, 1)
|
||||
verts = (1 - mu) * verts + mu * torch.mm(L, verts) / total_weight
|
||||
|
||||
@@ -180,6 +180,7 @@ def iterative_closest_point(
|
||||
t_history.append(SimilarityTransform(R, T, s))
|
||||
|
||||
# compute the root mean squared error
|
||||
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
|
||||
Xt_sq_diff = ((Xt - Xt_nn_points) ** 2).sum(2)
|
||||
rmse = oputil.wmean(Xt_sq_diff[:, :, None], mask_X).sqrt()[:, 0, 0]
|
||||
|
||||
|
||||
@@ -276,6 +276,7 @@ def add_pointclouds_to_volumes(
|
||||
|
||||
# obtain the conversion mask
|
||||
n_per_pcl = pointclouds.num_points_per_cloud().type_as(pcl_feats)
|
||||
# pyre-fixme[6]: For 1st param expected `Union[bool, float, int]` but got `Tensor`.
|
||||
mask = torch.arange(n_per_pcl.max(), dtype=pcl_feats.dtype, device=pcl_feats.device)
|
||||
mask = (mask[None, :] < n_per_pcl[:, None]).type_as(mask)
|
||||
|
||||
@@ -388,6 +389,7 @@ def add_points_features_to_volume_densities_features(
|
||||
mode=mode,
|
||||
min_weight=min_weight,
|
||||
mask=mask,
|
||||
# pyre-fixme[6]: For 8th param expected `LongTensor` but got `Tensor`.
|
||||
grid_sizes=grid_sizes,
|
||||
)
|
||||
|
||||
@@ -595,7 +597,6 @@ def _splat_points_to_volumes(
|
||||
rX, rY, rZ = rXYZ.split(1, dim=2)
|
||||
|
||||
# get random indices for the purpose of adding out-of-bounds values
|
||||
# pyre-fixme[16]: `Tensor` has no attribute `new_zeros`.
|
||||
rand_idx = X.new_zeros(X.shape).random_(0, n_voxels)
|
||||
|
||||
# iterate over the x, y, z indices of the 8-neighborhood (xdiff, ydiff, zdiff)
|
||||
@@ -635,7 +636,6 @@ def _splat_points_to_volumes(
|
||||
|
||||
# scatter add casts the votes into the weight accumulator
|
||||
# and the feature accumulator
|
||||
# pyre-fixme[16]: `Tensor` has no attribute `scatter_add_`.
|
||||
volume_densities.scatter_add_(1, idx_valid, w_valid)
|
||||
|
||||
# reshape idx_valid -> (minibatch, feature_dim, n_points)
|
||||
@@ -719,6 +719,7 @@ def _round_points_to_volumes(
|
||||
X, Y, Z = XYZ.split(1, dim=2)
|
||||
|
||||
# valid - binary indicators of votes that fall into the volume
|
||||
# pyre-fixme[9]: grid_sizes has type `LongTensor`; used as `Tensor`.
|
||||
grid_sizes = grid_sizes.type_as(XYZ)
|
||||
valid = (
|
||||
(0 <= X)
|
||||
@@ -743,7 +744,6 @@ def _round_points_to_volumes(
|
||||
|
||||
# scatter add casts the votes into the weight accumulator
|
||||
# and the feature accumulator
|
||||
# pyre-fixme[16]: `Tensor` has no attribute `scatter_add_`.
|
||||
volume_densities.scatter_add_(1, idx_valid, w_valid)
|
||||
|
||||
# reshape idx_valid -> (minibatch, feature_dim, n_points)
|
||||
|
||||
@@ -81,6 +81,7 @@ def sample_farthest_points(
|
||||
start_idxs = torch.zeros_like(lengths)
|
||||
if random_start_point:
|
||||
for n in range(N):
|
||||
# pyre-fixme[6]: For 1st param expected `int` but got `Tensor`.
|
||||
start_idxs[n] = torch.randint(high=lengths[n], size=(1,)).item()
|
||||
|
||||
with torch.no_grad():
|
||||
@@ -128,14 +129,23 @@ def sample_farthest_points_naive(
|
||||
for n in range(N):
|
||||
# Initialize an array for the sampled indices, shape: (max_K,)
|
||||
sample_idx_batch = torch.full(
|
||||
(max_K,), fill_value=-1, dtype=torch.int64, device=device
|
||||
# pyre-fixme[6]: For 1st param expected `Union[List[int], Size,
|
||||
# typing.Tuple[int, ...]]` but got `Tuple[Tensor]`.
|
||||
(max_K,),
|
||||
fill_value=-1,
|
||||
dtype=torch.int64,
|
||||
device=device,
|
||||
)
|
||||
|
||||
# Initialize closest distances to inf, shape: (P,)
|
||||
# This will be updated at each iteration to track the closest distance of the
|
||||
# remaining points to any of the selected points
|
||||
closest_dists = points.new_full(
|
||||
(lengths[n],), float("inf"), dtype=torch.float32
|
||||
# pyre-fixme[6]: For 1st param expected `Union[List[int], Size,
|
||||
# typing.Tuple[int, ...]]` but got `Tuple[Tensor]`.
|
||||
(lengths[n],),
|
||||
float("inf"),
|
||||
dtype=torch.float32,
|
||||
)
|
||||
|
||||
# Select a random point index and save it as the starting point
|
||||
@@ -143,6 +153,10 @@ def sample_farthest_points_naive(
|
||||
sample_idx_batch[0] = selected_idx
|
||||
|
||||
# If the pointcloud has fewer than K points then only iterate over the min
|
||||
# pyre-fixme[6]: For 1st param expected `SupportsRichComparisonT` but got
|
||||
# `Tensor`.
|
||||
# pyre-fixme[6]: For 2nd param expected `SupportsRichComparisonT` but got
|
||||
# `Tensor`.
|
||||
k_n = min(lengths[n], K[n])
|
||||
|
||||
# Iteratively select points for a maximum of k_n
|
||||
@@ -151,6 +165,8 @@ def sample_farthest_points_naive(
|
||||
# and all the other points. If a point has already been selected
|
||||
# it's distance will be 0.0 so it will not be selected again as the max.
|
||||
dist = points[n, selected_idx, :] - points[n, : lengths[n], :]
|
||||
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and
|
||||
# `int`.
|
||||
dist_to_last_selected = (dist**2).sum(-1) # (P - i)
|
||||
|
||||
# If closer than currently saved distance to one of the selected
|
||||
|
||||
@@ -172,6 +172,4 @@ def _rand_barycentric_coords(
|
||||
w0 = 1.0 - u_sqrt
|
||||
w1 = u_sqrt * (1.0 - v)
|
||||
w2 = u_sqrt * v
|
||||
# pyre-fixme[7]: Expected `Tuple[torch.Tensor, torch.Tensor, torch.Tensor]` but
|
||||
# got `Tuple[float, typing.Any, typing.Any]`.
|
||||
return w0, w1, w2
|
||||
|
||||
@@ -441,6 +441,8 @@ def _create_faces_index(faces_per_mesh: torch.Tensor, device=None):
|
||||
|
||||
switch123_offset = F - faces_per_mesh # e.g. (8, 5, 7)
|
||||
|
||||
# pyre-fixme[6]: For 1st param expected `Union[List[int], Size,
|
||||
# typing.Tuple[int, ...]]` but got `Tensor`.
|
||||
idx_diffs = torch.ones(4 * F, device=device, dtype=torch.int64)
|
||||
idx_diffs[switch1_idx] += switch123_offset
|
||||
idx_diffs[switch2_idx] += switch123_offset
|
||||
|
||||
@@ -89,6 +89,8 @@ def wmean(
|
||||
args = {"dim": dim, "keepdim": keepdim}
|
||||
|
||||
if weight is None:
|
||||
# pyre-fixme[6]: For 1st param expected `Optional[dtype]` but got
|
||||
# `Union[Tuple[int], int]`.
|
||||
return x.mean(**args)
|
||||
|
||||
if any(
|
||||
@@ -97,6 +99,8 @@ def wmean(
|
||||
):
|
||||
raise ValueError("wmean: weights are not compatible with the tensor")
|
||||
|
||||
# pyre-fixme[6]: For 1st param expected `Optional[dtype]` but got
|
||||
# `Union[Tuple[int], int]`.
|
||||
return (x * weight[..., None]).sum(**args) / weight[..., None].sum(**args).clamp(
|
||||
eps
|
||||
)
|
||||
|
||||
@@ -87,7 +87,6 @@ def vert_align(
|
||||
padding_mode=padding_mode,
|
||||
align_corners=align_corners,
|
||||
) # (N, C, 1, V)
|
||||
# pyre-fixme[28]: Unexpected keyword argument `dim`.
|
||||
feat_sampled = feat_sampled.squeeze(dim=2).transpose(1, 2) # (N, V, C)
|
||||
feats_sampled.append(feat_sampled)
|
||||
feats_sampled = torch.cat(feats_sampled, dim=2) # (N, V, sum(C))
|
||||
@@ -101,7 +100,6 @@ def vert_align(
|
||||
.view(-1, 1)
|
||||
.expand(-1, feats_sampled.shape[-1])
|
||||
)
|
||||
# pyre-fixme[16]: `Tensor` has no attribute `gather`.
|
||||
feats_sampled = feats_sampled.gather(0, idx) # (sum(V), C)
|
||||
|
||||
return feats_sampled
|
||||
|
||||
Reference in New Issue
Block a user