Commit 7978ffd1 authored by Pyre Bot Jr's avatar Pyre Bot Jr Committed by Facebook GitHub Bot
Browse files

suppress errors in `vision/fair/pytorch3d`

Differential Revision: D37172764

fbshipit-source-id: a2ec367e56de2781a17f5e708eb5832ec9d7e6b4
parent ea4f3260
......@@ -108,6 +108,7 @@ def fit_circle_in_2d(
raise ValueError(f"{n_provided} points are not enough to determine a circle")
solution = lstsq(design, rhs[:, None])
center = solution[:2, 0] / 2
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
radius = torch.sqrt(solution[2, 0] + (center**2).sum())
if n_points > 0:
if angles is not None:
......
......@@ -50,6 +50,7 @@ def cleanup_eval_depth(
# the threshold is a sigma-multiple of the standard deviation of the depth
mu = wmean(depth.view(ba, -1, 1), mask.view(ba, -1)).view(ba, 1)
std = (
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
wmean((depth.view(ba, -1) - mu).view(ba, -1, 1) ** 2, mask.view(ba, -1))
.clamp(1e-4)
.sqrt()
......@@ -62,7 +63,6 @@ def cleanup_eval_depth(
# print(f'Kept {100.0 * perc_kept.mean():1.3f} % points')
good_depth_raster = torch.zeros_like(depth).view(ba, -1)
# pyre-ignore[16]: scatter_add_
good_depth_raster.scatter_add_(1, torch.round(idx_sampled[:, 0]).long(), good_depth)
good_depth_mask = (good_depth_raster.view(ba, 1, H, W) > 0).float()
......
......@@ -65,6 +65,7 @@ def eval_depth(
df = gt - pred
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
mse_depth = (dmask * (df**2)).sum((1, 2, 3)) / dmask_mass
abs_depth = (dmask * df.abs()).sum((1, 2, 3)) / dmask_mass
......@@ -100,8 +101,10 @@ def calc_mse(
Calculates the mean square error between tensors `x` and `y`.
"""
if mask is None:
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
return torch.mean((x - y) ** 2)
else:
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
return (((x - y) ** 2) * mask).sum() / mask.expand_as(x).sum().clamp(1e-5)
......@@ -128,6 +131,7 @@ def calc_bce(
mask_bg = (1 - mask_fg) * mask
weight = mask_fg / mask_fg.sum().clamp(1.0) + mask_bg / mask_bg.sum().clamp(1.0)
# weight sum should be at this point ~2
# pyre-fixme[58]: `/` is not supported for operand types `int` and `Tensor`.
weight = weight * (weight.numel() / weight.sum().clamp(1.0))
else:
weight = torch.ones_like(gt) * mask
......
......@@ -55,8 +55,6 @@ def get_rgbd_point_cloud(
pts_colors = torch.nn.functional.interpolate(
image_rgb,
# pyre-fixme[6]: Expected `Optional[int]` for 2nd param but got
# `List[typing.Any]`.
size=[imh, imw],
mode="bilinear",
align_corners=False,
......@@ -133,6 +131,7 @@ def render_point_cloud_pytorch3d(
cumprod = torch.cat((torch.ones_like(cumprod[..., :1]), cumprod[..., :-1]), dim=-1)
depths = (weights * cumprod * fragments.zbuf).sum(dim=-1)
# add the rendering mask
# pyre-fixme[6]: For 1st param expected `Tensor` but got `float`.
render_mask = -torch.prod(1.0 - weights, dim=-1) + 1.0
# cat depths and render mask
......@@ -141,8 +140,6 @@ def render_point_cloud_pytorch3d(
# reshape back
rendered_blob = Fu.interpolate(
rendered_blob,
# pyre-fixme[6]: Expected `Optional[int]` for 2nd param but got `Tuple[int,
# ...]`.
size=tuple(render_size),
mode="bilinear",
)
......
......@@ -99,8 +99,6 @@ def visualize_basics(
v = v.repeat(1, 3, 1, 1)
v = torch.nn.functional.interpolate(
v,
# pyre-fixme[6]: Expected `Optional[typing.List[float]]` for 2nd param
# but got `float`.
scale_factor=(
600.0
if (
......
......@@ -288,7 +288,6 @@ def make_material_atlas(
# w0, w1
bary[below_diag, slc] = ((grid[below_diag] + 1.0 / 3.0) / R).T
# w0, w1 for above diagonal grid cells.
# pyre-fixme[16]: `float` has no attribute `T`.
bary[~below_diag, slc] = (((R - 1.0 - grid[~below_diag]) + 2.0 / 3.0) / R).T
# w2 = 1. - w0 - w1
bary[..., -1] = 1 - bary[..., :2].sum(dim=-1)
......
......@@ -57,7 +57,6 @@ def _format_faces_indices(faces_indices, max_index: int, device, pad_value=None)
)
if pad_value is not None:
# pyre-fixme[28]: Unexpected keyword argument `dim`.
mask = faces_indices.eq(pad_value).all(dim=-1)
# Change to 0 based indexing.
......
......@@ -58,7 +58,6 @@ def _check_faces_indices(
if pad_value is None:
mask = torch.ones(faces_indices.shape[:-1]).bool() # Keep all faces
else:
# pyre-fixme[16]: `torch.ByteTensor` has no attribute `any`
mask = faces_indices.ne(pad_value).any(dim=-1)
if torch.any(faces_indices[mask] >= max_index) or torch.any(
faces_indices[mask] < 0
......
......@@ -112,6 +112,8 @@ 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]
else:
L_sum = torch.sparse.sum(L, dim=1).to_dense().view(-1, 1)
......
......@@ -303,8 +303,8 @@ def point_mesh_edge_distance(meshes: Meshes, pcls: Pointclouds):
# weight each example by the inverse of number of points in the example
point_to_cloud_idx = pcls.packed_to_cloud_idx() # (sum(P_i), )
num_points_per_cloud = pcls.num_points_per_cloud() # (N,)
# pyre-ignore[16]: `torch.Tensor` has no attribute `gather`
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()
point_to_edge = point_to_edge * weights_p
point_dist = point_to_edge.sum() / N
......@@ -378,8 +378,8 @@ def point_mesh_face_distance(
# weight each example by the inverse of number of points in the example
point_to_cloud_idx = pcls.packed_to_cloud_idx() # (sum(P_i),)
num_points_per_cloud = pcls.num_points_per_cloud() # (N,)
# pyre-ignore[16]: `torch.Tensor` has no attribute `gather`
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()
point_to_face = point_to_face * weights_p
point_dist = point_to_face.sum() / N
......
......@@ -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]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment