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( ...@@ -108,6 +108,7 @@ def fit_circle_in_2d(
raise ValueError(f"{n_provided} points are not enough to determine a circle") raise ValueError(f"{n_provided} points are not enough to determine a circle")
solution = lstsq(design, rhs[:, None]) solution = lstsq(design, rhs[:, None])
center = solution[:2, 0] / 2 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()) radius = torch.sqrt(solution[2, 0] + (center**2).sum())
if n_points > 0: if n_points > 0:
if angles is not None: if angles is not None:
......
...@@ -50,6 +50,7 @@ def cleanup_eval_depth( ...@@ -50,6 +50,7 @@ def cleanup_eval_depth(
# the threshold is a sigma-multiple of the standard deviation of the 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) mu = wmean(depth.view(ba, -1, 1), mask.view(ba, -1)).view(ba, 1)
std = ( 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)) wmean((depth.view(ba, -1) - mu).view(ba, -1, 1) ** 2, mask.view(ba, -1))
.clamp(1e-4) .clamp(1e-4)
.sqrt() .sqrt()
...@@ -62,7 +63,6 @@ def cleanup_eval_depth( ...@@ -62,7 +63,6 @@ def cleanup_eval_depth(
# print(f'Kept {100.0 * perc_kept.mean():1.3f} % points') # print(f'Kept {100.0 * perc_kept.mean():1.3f} % points')
good_depth_raster = torch.zeros_like(depth).view(ba, -1) 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_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() good_depth_mask = (good_depth_raster.view(ba, 1, H, W) > 0).float()
......
...@@ -65,6 +65,7 @@ def eval_depth( ...@@ -65,6 +65,7 @@ def eval_depth(
df = gt - pred 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 mse_depth = (dmask * (df**2)).sum((1, 2, 3)) / dmask_mass
abs_depth = (dmask * df.abs()).sum((1, 2, 3)) / dmask_mass abs_depth = (dmask * df.abs()).sum((1, 2, 3)) / dmask_mass
...@@ -100,8 +101,10 @@ def calc_mse( ...@@ -100,8 +101,10 @@ def calc_mse(
Calculates the mean square error between tensors `x` and `y`. Calculates the mean square error between tensors `x` and `y`.
""" """
if mask is None: if mask is None:
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
return torch.mean((x - y) ** 2) return torch.mean((x - y) ** 2)
else: 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) return (((x - y) ** 2) * mask).sum() / mask.expand_as(x).sum().clamp(1e-5)
...@@ -128,6 +131,7 @@ def calc_bce( ...@@ -128,6 +131,7 @@ def calc_bce(
mask_bg = (1 - mask_fg) * mask mask_bg = (1 - mask_fg) * mask
weight = mask_fg / mask_fg.sum().clamp(1.0) + mask_bg / mask_bg.sum().clamp(1.0) 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 # 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)) weight = weight * (weight.numel() / weight.sum().clamp(1.0))
else: else:
weight = torch.ones_like(gt) * mask weight = torch.ones_like(gt) * mask
......
...@@ -55,8 +55,6 @@ def get_rgbd_point_cloud( ...@@ -55,8 +55,6 @@ def get_rgbd_point_cloud(
pts_colors = torch.nn.functional.interpolate( pts_colors = torch.nn.functional.interpolate(
image_rgb, image_rgb,
# pyre-fixme[6]: Expected `Optional[int]` for 2nd param but got
# `List[typing.Any]`.
size=[imh, imw], size=[imh, imw],
mode="bilinear", mode="bilinear",
align_corners=False, align_corners=False,
...@@ -133,6 +131,7 @@ def render_point_cloud_pytorch3d( ...@@ -133,6 +131,7 @@ def render_point_cloud_pytorch3d(
cumprod = torch.cat((torch.ones_like(cumprod[..., :1]), cumprod[..., :-1]), dim=-1) cumprod = torch.cat((torch.ones_like(cumprod[..., :1]), cumprod[..., :-1]), dim=-1)
depths = (weights * cumprod * fragments.zbuf).sum(dim=-1) depths = (weights * cumprod * fragments.zbuf).sum(dim=-1)
# add the rendering mask # 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 render_mask = -torch.prod(1.0 - weights, dim=-1) + 1.0
# cat depths and render mask # cat depths and render mask
...@@ -141,8 +140,6 @@ def render_point_cloud_pytorch3d( ...@@ -141,8 +140,6 @@ def render_point_cloud_pytorch3d(
# reshape back # reshape back
rendered_blob = Fu.interpolate( rendered_blob = Fu.interpolate(
rendered_blob, rendered_blob,
# pyre-fixme[6]: Expected `Optional[int]` for 2nd param but got `Tuple[int,
# ...]`.
size=tuple(render_size), size=tuple(render_size),
mode="bilinear", mode="bilinear",
) )
......
...@@ -99,8 +99,6 @@ def visualize_basics( ...@@ -99,8 +99,6 @@ def visualize_basics(
v = v.repeat(1, 3, 1, 1) v = v.repeat(1, 3, 1, 1)
v = torch.nn.functional.interpolate( v = torch.nn.functional.interpolate(
v, v,
# pyre-fixme[6]: Expected `Optional[typing.List[float]]` for 2nd param
# but got `float`.
scale_factor=( scale_factor=(
600.0 600.0
if ( if (
......
...@@ -288,7 +288,6 @@ def make_material_atlas( ...@@ -288,7 +288,6 @@ def make_material_atlas(
# w0, w1 # w0, w1
bary[below_diag, slc] = ((grid[below_diag] + 1.0 / 3.0) / R).T bary[below_diag, slc] = ((grid[below_diag] + 1.0 / 3.0) / R).T
# w0, w1 for above diagonal grid cells. # 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 bary[~below_diag, slc] = (((R - 1.0 - grid[~below_diag]) + 2.0 / 3.0) / R).T
# w2 = 1. - w0 - w1 # w2 = 1. - w0 - w1
bary[..., -1] = 1 - bary[..., :2].sum(dim=-1) 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) ...@@ -57,7 +57,6 @@ def _format_faces_indices(faces_indices, max_index: int, device, pad_value=None)
) )
if pad_value is not None: if pad_value is not None:
# pyre-fixme[28]: Unexpected keyword argument `dim`.
mask = faces_indices.eq(pad_value).all(dim=-1) mask = faces_indices.eq(pad_value).all(dim=-1)
# Change to 0 based indexing. # Change to 0 based indexing.
......
...@@ -58,7 +58,6 @@ def _check_faces_indices( ...@@ -58,7 +58,6 @@ def _check_faces_indices(
if pad_value is None: if pad_value is None:
mask = torch.ones(faces_indices.shape[:-1]).bool() # Keep all faces mask = torch.ones(faces_indices.shape[:-1]).bool() # Keep all faces
else: else:
# pyre-fixme[16]: `torch.ByteTensor` has no attribute `any`
mask = faces_indices.ne(pad_value).any(dim=-1) mask = faces_indices.ne(pad_value).any(dim=-1)
if torch.any(faces_indices[mask] >= max_index) or torch.any( if torch.any(faces_indices[mask] >= max_index) or torch.any(
faces_indices[mask] < 0 faces_indices[mask] < 0
......
...@@ -112,6 +112,8 @@ def mesh_laplacian_smoothing(meshes, method: str = "uniform"): ...@@ -112,6 +112,8 @@ def mesh_laplacian_smoothing(meshes, method: str = "uniform"):
if method == "cot": if method == "cot":
norm_w = torch.sparse.sum(L, dim=1).to_dense().view(-1, 1) norm_w = torch.sparse.sum(L, dim=1).to_dense().view(-1, 1)
idx = norm_w > 0 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] = 1.0 / norm_w[idx]
else: else:
L_sum = torch.sparse.sum(L, dim=1).to_dense().view(-1, 1) 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): ...@@ -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 # 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), ) point_to_cloud_idx = pcls.packed_to_cloud_idx() # (sum(P_i), )
num_points_per_cloud = pcls.num_points_per_cloud() # (N,) 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) 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 = 1.0 / weights_p.float()
point_to_edge = point_to_edge * weights_p point_to_edge = point_to_edge * weights_p
point_dist = point_to_edge.sum() / N point_dist = point_to_edge.sum() / N
...@@ -378,8 +378,8 @@ def point_mesh_face_distance( ...@@ -378,8 +378,8 @@ def point_mesh_face_distance(
# weight each example by the inverse of number of points in the example # 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),) point_to_cloud_idx = pcls.packed_to_cloud_idx() # (sum(P_i),)
num_points_per_cloud = pcls.num_points_per_cloud() # (N,) 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) 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 = 1.0 / weights_p.float()
point_to_face = point_to_face * weights_p point_to_face = point_to_face * weights_p
point_dist = point_to_face.sum() / N point_dist = point_to_face.sum() / N
......
...@@ -119,11 +119,16 @@ def corresponding_cameras_alignment( ...@@ -119,11 +119,16 @@ def corresponding_cameras_alignment(
# create a new cameras object and set the R and T accordingly # create a new cameras object and set the R and T accordingly
cameras_src_aligned = cameras_src.clone() 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.R = torch.bmm(align_t_R.expand_as(cameras_src.R), cameras_src.R)
cameras_src_aligned.T = ( cameras_src_aligned.T = (
torch.bmm( 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] )[:, 0]
# pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C._TensorBase.__m...
+ cameras_src.T * align_t_s + cameras_src.T * align_t_s
) )
...@@ -171,6 +176,7 @@ def _align_camera_extrinsics( ...@@ -171,6 +176,7 @@ def _align_camera_extrinsics(
R_A = (U V^T)^T 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) RRcov = torch.bmm(cameras_src.R, cameras_tgt.R.transpose(2, 1)).mean(0)
U, _, V = torch.svd(RRcov) U, _, V = torch.svd(RRcov)
align_t_R = V @ U.t() align_t_R = V @ U.t()
...@@ -204,11 +210,13 @@ def _align_camera_extrinsics( ...@@ -204,11 +210,13 @@ def _align_camera_extrinsics(
# `Union[BoundMethod[typing.Callable(torch.Tensor.__getitem__)[[Named(self, # `Union[BoundMethod[typing.Callable(torch.Tensor.__getitem__)[[Named(self,
# torch.Tensor), Named(item, typing.Any)], typing.Any], torch.Tensor], # torch.Tensor), Named(item, typing.Any)], typing.Any], torch.Tensor],
# torch.Tensor, torch.nn.Module]` is not a function. # 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] A = torch.bmm(cameras_src.R, cameras_src.T[:, :, None])[:, :, 0]
# pyre-fixme[29]: # pyre-fixme[29]:
# `Union[BoundMethod[typing.Callable(torch.Tensor.__getitem__)[[Named(self, # `Union[BoundMethod[typing.Callable(torch.Tensor.__getitem__)[[Named(self,
# torch.Tensor), Named(item, typing.Any)], typing.Any], torch.Tensor], # torch.Tensor), Named(item, typing.Any)], typing.Any], torch.Tensor],
# torch.Tensor, torch.nn.Module]` is not a function. # 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] B = torch.bmm(cameras_src.R, cameras_tgt.T[:, :, None])[:, :, 0]
Amu = A.mean(0, keepdim=True) Amu = A.mean(0, keepdim=True)
Bmu = B.mean(0, keepdim=True) Bmu = B.mean(0, keepdim=True)
...@@ -217,6 +225,7 @@ def _align_camera_extrinsics( ...@@ -217,6 +225,7 @@ def _align_camera_extrinsics(
# of centered A and centered B # of centered A and centered B
Ac = A - Amu Ac = A - Amu
Bc = B - Bmu 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) align_t_s = (Ac * Bc).mean() / (Ac**2).mean().clamp(eps)
else: else:
# set the scale to identity # set the scale to identity
......
...@@ -235,7 +235,6 @@ def cubify(voxels, thresh, device=None, align: str = "topleft") -> Meshes: ...@@ -235,7 +235,6 @@ def cubify(voxels, thresh, device=None, align: str = "topleft") -> Meshes:
idlenum = idleverts.cumsum(1) idlenum = idleverts.cumsum(1)
verts_list = [ verts_list = [
# pyre-fixme[16]: `Tensor` has no attribute `index_select`.
grid_verts.index_select(0, (idleverts[n] == 0).nonzero(as_tuple=False)[:, 0]) grid_verts.index_select(0, (idleverts[n] == 0).nonzero(as_tuple=False)[:, 0])
for n in range(N) for n in range(N)
] ]
......
...@@ -119,7 +119,6 @@ def gather_scatter_python(input, edges, directed: bool = False): ...@@ -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) 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) 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)) output = output.scatter_add(0, idx0, input.gather(0, idx1))
if not directed: if not directed:
output = output.scatter_add(0, idx1, input.gather(0, idx0)) output = output.scatter_add(0, idx1, input.gather(0, idx0))
......
...@@ -94,7 +94,6 @@ def interpolate_face_attributes_python( ...@@ -94,7 +94,6 @@ def interpolate_face_attributes_python(
pix_to_face = pix_to_face.clone() pix_to_face = pix_to_face.clone()
pix_to_face[mask] = 0 pix_to_face[mask] = 0
idx = pix_to_face.view(N * H * W * K, 1, 1).expand(N * H * W * K, 3, D) 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_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 = (barycentric_coords[..., None] * pixel_face_vals).sum(dim=-2)
pixel_vals[mask] = 0 # Replace masked values in output. pixel_vals[mask] = 0 # Replace masked values in output.
......
...@@ -47,7 +47,6 @@ _box_triangles = [ ...@@ -47,7 +47,6 @@ _box_triangles = [
def _check_coplanar(boxes: torch.Tensor, eps: float = 1e-4) -> None: def _check_coplanar(boxes: torch.Tensor, eps: float = 1e-4) -> None:
faces = torch.tensor(_box_planes, dtype=torch.int64, device=boxes.device) 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) verts = boxes.index_select(index=faces.view(-1), dim=1)
B = boxes.shape[0] B = boxes.shape[0]
P, V = faces.shape P, V = faces.shape
...@@ -74,7 +73,6 @@ def _check_nonzero(boxes: torch.Tensor, eps: float = 1e-4) -> None: ...@@ -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 Checks that the sides of the box have a non zero area
""" """
faces = torch.tensor(_box_triangles, dtype=torch.int64, device=boxes.device) 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) verts = boxes.index_select(index=faces.view(-1), dim=1)
B = boxes.shape[0] B = boxes.shape[0]
T, V = faces.shape T, V = faces.shape
......
...@@ -84,7 +84,6 @@ class _knn_points(Function): ...@@ -84,7 +84,6 @@ class _knn_points(Function):
dists[mask] = 0 dists[mask] = 0
else: else:
dists, sort_idx = dists.sort(dim=2) dists, sort_idx = dists.sort(dim=2)
# pyre-fixme[16]: `Tensor` has no attribute `gather`.
idx = idx.gather(2, sort_idx) idx = idx.gather(2, sort_idx)
ctx.save_for_backward(p1, p2, lengths1, lengths2, idx) ctx.save_for_backward(p1, p2, lengths1, lengths2, idx)
......
...@@ -45,6 +45,7 @@ def laplacian(verts: torch.Tensor, edges: torch.Tensor) -> torch.Tensor: ...@@ -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 # i.e. A[i, j] = 1 if (i,j) is an edge, or
# A[e0, e1] = 1 & A[e1, e0] = 1 # A[e0, e1] = 1 & A[e1, e0] = 1
ones = torch.ones(idx.shape[1], dtype=torch.float32, device=verts.device) 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)) A = torch.sparse.FloatTensor(idx, ones, (V, V))
# the sum of i-th row of A gives the degree of the i-th vertex # 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: ...@@ -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 # 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 # i.e. L[i, j] = 1 ./ deg(i) if (i, j) is an edge
deg0 = deg[e0] 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, 1.0 / deg0, deg0)
deg1 = deg[e1] 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, 1.0 / deg1, deg1)
val = torch.cat([deg0, deg1]) val = torch.cat([deg0, deg1])
# pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
L = torch.sparse.FloatTensor(idx, val, (V, V)) L = torch.sparse.FloatTensor(idx, val, (V, V))
# Then we add the diagonal values L[i, i] = -1. # Then we add the diagonal values L[i, i] = -1.
idx = torch.arange(V, device=verts.device) idx = torch.arange(V, device=verts.device)
idx = torch.stack([idx, idx], dim=0) idx = torch.stack([idx, idx], dim=0)
ones = torch.ones(idx.shape[1], dtype=torch.float32, device=verts.device) 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)) L -= torch.sparse.FloatTensor(idx, ones, (V, V))
return L return L
...@@ -119,6 +124,7 @@ def cot_laplacian( ...@@ -119,6 +124,7 @@ def cot_laplacian(
ii = faces[:, [1, 2, 0]] ii = faces[:, [1, 2, 0]]
jj = faces[:, [2, 0, 1]] jj = faces[:, [2, 0, 1]]
idx = torch.stack([ii, jj], dim=0).view(2, F * 3) 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)) L = torch.sparse.FloatTensor(idx, cot.view(-1), (V, V))
# Make it symmetric; this means we are also setting # Make it symmetric; this means we are also setting
...@@ -133,6 +139,7 @@ def cot_laplacian( ...@@ -133,6 +139,7 @@ def cot_laplacian(
val = torch.stack([area] * 3, dim=1).view(-1) val = torch.stack([area] * 3, dim=1).view(-1)
inv_areas.scatter_add_(0, idx, val) inv_areas.scatter_add_(0, idx, val)
idx = inv_areas > 0 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] = 1.0 / inv_areas[idx]
inv_areas = inv_areas.view(-1, 1) inv_areas = inv_areas.view(-1, 1)
...@@ -166,6 +173,7 @@ def norm_laplacian( ...@@ -166,6 +173,7 @@ def norm_laplacian(
e01 = edges.t() # (2, E) e01 = edges.t() # (2, E)
V = verts.shape[0] V = verts.shape[0]
# pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
L = torch.sparse.FloatTensor(e01, w01, (V, V)) L = torch.sparse.FloatTensor(e01, w01, (V, V))
L = L + L.t() L = L + L.t()
......
...@@ -347,4 +347,5 @@ def _get_value(point: Tuple[int, int, int], volume_data: torch.Tensor) -> float: ...@@ -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 data: scalar value in the volume at the given point
""" """
x, y, z = point x, y, z = point
# pyre-fixme[7]: Expected `float` but got `Tensor`.
return volume_data[z][y][x] return volume_data[z][y][x]
...@@ -49,7 +49,6 @@ def taubin_smoothing( ...@@ -49,7 +49,6 @@ def taubin_smoothing(
total_weight = torch.sparse.sum(L, dim=1).to_dense().view(-1, 1) total_weight = torch.sparse.sum(L, dim=1).to_dense().view(-1, 1)
verts = (1 - lambd) * verts + lambd * torch.mm(L, verts) / total_weight verts = (1 - lambd) * verts + lambd * torch.mm(L, verts) / total_weight
# pyre-ignore
L = norm_laplacian(verts, edges) L = norm_laplacian(verts, edges)
total_weight = torch.sparse.sum(L, dim=1).to_dense().view(-1, 1) total_weight = torch.sparse.sum(L, dim=1).to_dense().view(-1, 1)
verts = (1 - mu) * verts + mu * torch.mm(L, verts) / total_weight verts = (1 - mu) * verts + mu * torch.mm(L, verts) / total_weight
......
...@@ -180,6 +180,7 @@ def iterative_closest_point( ...@@ -180,6 +180,7 @@ def iterative_closest_point(
t_history.append(SimilarityTransform(R, T, s)) t_history.append(SimilarityTransform(R, T, s))
# compute the root mean squared error # 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) Xt_sq_diff = ((Xt - Xt_nn_points) ** 2).sum(2)
rmse = oputil.wmean(Xt_sq_diff[:, :, None], mask_X).sqrt()[:, 0, 0] 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