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
......@@ -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
......@@ -80,7 +80,6 @@ def _opencv_from_cameras_projection(
scale = scale.expand(-1, 2)
c0 = image_size_wh / 2.0
# pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch.Tensor.__neg__)[[Named...
principal_point = -p0_pytorch3d * scale + c0
focal_length = focal_pytorch3d * scale
......
......@@ -401,6 +401,7 @@ class CamerasBase(TensorProperties):
kwargs = {}
# pyre-fixme[16]: Module `cuda` has no attribute `LongTensor`.
if not isinstance(index, (int, list, torch.LongTensor, torch.cuda.LongTensor)):
msg = "Invalid index type, expected int, List[int] or torch.LongTensor; got %r"
raise ValueError(msg % type(index))
......@@ -600,7 +601,9 @@ 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, 2] = (max_x + min_x) / (max_x - min_x)
K[:, 1, 2] = (max_y + min_y) / (max_y - min_y)
......@@ -1755,6 +1758,8 @@ def get_ndc_to_screen_transform(
K = torch.zeros((cameras._N, 4, 4), device=cameras.device, dtype=torch.float32)
if not torch.is_tensor(image_size):
image_size = torch.tensor(image_size, device=cameras.device)
# pyre-fixme[16]: Item `List` of `Union[List[typing.Any], Tensor, Tuple[Any,
# ...]]` has no attribute `view`.
image_size = image_size.view(-1, 2) # of shape (1 or B)x2
height, width = image_size.unbind(1)
......
......@@ -158,7 +158,6 @@ class AbsorptionOnlyRaymarcher(torch.nn.Module):
_check_density_bounds(rays_densities)
total_transmission = torch.prod(1 - rays_densities, dim=-1, keepdim=True)
opacities = 1.0 - total_transmission
# pyre-fixme[7]: Expected `Optional[torch.Tensor]` but got `float`.
return opacities
......
......@@ -180,6 +180,8 @@ class MultinomialRaysampler(torch.nn.Module):
# is not batched and does not support partial permutation
_, width, height, _ = xy_grid.shape
weights = xy_grid.new_ones(batch_size, width * height)
# pyre-fixme[6]: For 2nd param expected `int` but got `Union[bool,
# float, int]`.
rays_idx = _safe_multinomial(weights, num_rays)[..., None].expand(-1, -1, 2)
xy_grid = torch.gather(xy_grid.reshape(batch_size, -1, 2), 1, rays_idx)[
......@@ -478,7 +480,6 @@ def _safe_multinomial(input: torch.Tensor, num_samples: int) -> torch.Tensor:
# in some versions of Pytorch, zero probabilty samples can be drawn without an error
# due to this bug: https://github.com/pytorch/pytorch/issues/50034. Handle this case:
repl = (input > 0.0).sum(dim=-1) < num_samples
# pyre-fixme[16]: Undefined attribute `torch.ByteTensor` has no attribute `any`.
if repl.any():
res[repl] = torch.multinomial(input[repl], num_samples, replacement=True)
......@@ -515,7 +516,7 @@ def _xy_to_ray_bundle(
"""
batch_size = xy_grid.shape[0]
spatial_size = xy_grid.shape[1:-1]
n_rays_per_image = spatial_size.numel() # pyre-ignore
n_rays_per_image = spatial_size.numel()
# ray z-coords
rays_zs = xy_grid.new_empty((0,))
......
......@@ -254,7 +254,6 @@ def _find_verts_intersecting_clipping_plane(
# p1, p2, p3 are (T, 3) tensors storing the corresponding (x, y, z) coordinates
# of p1_face_ind, p2_face_ind, p3_face_ind
# pyre-ignore[16]
p1 = face_verts.gather(1, p1_face_ind[:, None, None].expand(-1, -1, 3)).squeeze(1)
p2 = face_verts.gather(1, p2_face_ind[:, None, None].expand(-1, -1, 3)).squeeze(1)
p3 = face_verts.gather(1, p3_face_ind[:, None, None].expand(-1, -1, 3)).squeeze(1)
......@@ -398,7 +397,6 @@ def clip_faces(
# into a smaller quadrilateral and split into two triangles)
#####################################################################################
# pyre-ignore[16]:
faces_unculled = ~faces_culled
# Case 1: no clipped verts or culled faces
cases1_unclipped = (faces_num_clipped_verts == 0) & faces_unculled
......@@ -434,7 +432,13 @@ def clip_faces(
# These will then be filled in for each case.
###########################################
F_clipped = (
F + faces_delta_cum[-1].item() + faces_delta[-1].item()
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()
) # Total number of faces in the new Meshes
face_verts_clipped = torch.zeros(
(F_clipped, 3, 3), dtype=face_verts_unclipped.dtype, device=device
......
......@@ -66,8 +66,11 @@ def _list_to_padded_wrapper(
"list_to_padded requires tensors to have the same number of dimensions"
)
raise ValueError(msg)
# 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)
......@@ -96,8 +99,11 @@ def _padded_to_list_wrapper(
N, M = x.shape[:2]
reshape_dims = x.shape[2:]
D = torch.prod(torch.tensor(reshape_dims)).item()
# 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]
return x_list
......@@ -132,8 +138,6 @@ def _pad_texture_maps(
image_BCHW = image.permute(2, 0, 1)[None]
new_image_BCHW = interpolate(
image_BCHW,
# pyre-fixme[6]: Expected `Optional[int]` for 2nd param but got
# `Tuple[int, int]`.
size=max_shape,
mode="bilinear",
align_corners=align_corners,
......
......@@ -130,12 +130,15 @@ def _get_splat_kernel_normalization(
epsilon = 0.05
normalization_constant = torch.exp(
-(offsets**2).sum(dim=1) / (2 * sigma**2)
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
-(offsets**2).sum(dim=1)
/ (2 * sigma**2)
).sum()
# We add an epsilon to the normalization constant to ensure the gradient will travel
# through non-boundary pixels' normalization factor, see Sec. 3.3.1 in "Differentia-
# ble Surface Rendering via Non-Differentiable Sampling", Cole et al.
# pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`.
return (1 + epsilon) / normalization_constant
......@@ -260,6 +263,7 @@ def _compute_splatting_colors_and_weights(
torch.floor(pixel_coords_screen[..., :2]) - pixel_coords_screen[..., :2] + 0.5
).view((N, H, W, K, 1, 2))
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
dist2_p_q = torch.sum((q_to_px_center + offsets) ** 2, dim=5) # (N, H, W, K, 9)
splat_weights = torch.exp(-dist2_p_q / (2 * sigma**2))
alpha = colors[..., 3:4]
......@@ -413,6 +417,7 @@ def _normalize_and_compose_all_layers(
# Normalize each of bg/surface/fg splat layers separately.
normalization_scales = 1.0 / (
# pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`.
torch.maximum(
splatted_weights_per_occlusion_layer,
torch.tensor([1.0], device=device),
......
......@@ -394,6 +394,7 @@ def ndc_grid_sample(
grid_ndc_flat = grid_ndc.reshape(batch, -1, 1, 2)
# pyre-fixme[6]: For 2nd param expected `Tuple[int, int]` but got `Size`.
grid_flat = ndc_to_grid_sample_coords(grid_ndc_flat, input.shape[2:])
sampled_input_flat = torch.nn.functional.grid_sample(
......
......@@ -890,7 +890,6 @@ class Meshes:
# NOTE: this is already applying the area weighting as the magnitude
# of the cross product is 2 x area of the triangle.
# pyre-fixme[16]: `Tensor` has no attribute `index_add`.
verts_normals = verts_normals.index_add(
0,
faces_packed[:, 1],
......
......@@ -210,7 +210,6 @@ def padded_to_packed(
# Convert to packed using pad value
if pad_value is not None:
# pyre-fixme[16]: `ByteTensor` has no attribute `any`.
mask = x_packed.ne(pad_value).any(-1)
x_packed = x_packed[mask]
return x_packed
......
......@@ -50,6 +50,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)
o = torch.stack(
......@@ -131,9 +132,17 @@ 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),
],
dim=-2,
......@@ -148,7 +157,7 @@ def matrix_to_quaternion(matrix: torch.Tensor) -> torch.Tensor:
# forall i; we pick the best-conditioned one (with the largest denominator)
return quat_candidates[
F.one_hot(q_abs.argmax(dim=-1), num_classes=4) > 0.5, : # pyre-ignore[16]
F.one_hot(q_abs.argmax(dim=-1), num_classes=4) > 0.5, :
].reshape(batch_dim + (4,))
......@@ -314,6 +323,7 @@ def random_quaternions(
"""
if isinstance(device, str):
device = torch.device(device)
# pyre-fixme[6]: For 2nd param expected `dtype` but got `Optional[dtype]`.
o = torch.randn((n, 4), dtype=dtype, device=device)
s = (o * o).sum(1)
o = o / _copysign(torch.sqrt(s), o[:, 0])[:, None]
......
......@@ -194,9 +194,12 @@ def _se3_V_matrix(
V = (
torch.eye(3, dtype=log_rotation.dtype, device=log_rotation.device)[None]
+ log_rotation_hat
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
* ((1 - torch.cos(rotation_angles)) / (rotation_angles**2))[:, None, None]
+ (
log_rotation_hat_square
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and
# `int`.
* ((rotation_angles - torch.sin(rotation_angles)) / (rotation_angles**3))[
:, None, None
]
......@@ -211,6 +214,7 @@ def _get_se3_V_input(log_rotation: torch.Tensor, eps: float = 1e-4):
A helper function that computes the input variables to the `_se3_V_matrix`
function.
"""
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
nrms = (log_rotation**2).sum(-1)
rotation_angles = torch.clamp(nrms, eps).sqrt()
log_rotation_hat = hat(log_rotation)
......
......@@ -160,6 +160,7 @@ def _so3_exp_map(
nrms = (log_rot * log_rot).sum(1)
# phis ... rotation angles
rot_angles = torch.clamp(nrms, eps).sqrt()
# pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`.
rot_angles_inv = 1.0 / rot_angles
fac1 = rot_angles_inv * rot_angles.sin()
fac2 = rot_angles_inv * rot_angles_inv * (1.0 - rot_angles.cos())
......@@ -167,8 +168,8 @@ def _so3_exp_map(
skews_square = torch.bmm(skews, skews)
R = (
# pyre-fixme[16]: `float` has no attribute `__getitem__`.
fac1[:, None, None] * skews
# pyre-fixme[16]: `float` has no attribute `__getitem__`.
+ fac2[:, None, None] * skews_square
+ torch.eye(3, dtype=log_rot.dtype, device=log_rot.device)[None]
)
......@@ -216,6 +217,7 @@ def so3_log_map(
# 2nd order Taylor expansion: phi_factor = 0.5 + (1.0 / 12) * phi**2
phi_factor = torch.empty_like(phi)
ok_denom = phi_sin.abs() > (0.5 * eps)
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
phi_factor[~ok_denom] = 0.5 + (phi[~ok_denom] ** 2) * (1.0 / 12)
phi_factor[ok_denom] = phi[ok_denom] / (2.0 * phi_sin[ok_denom])
......
......@@ -556,7 +556,9 @@ 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`.
imat = torch.diag_embed(ixyz, dim1=1, dim2=2)
return imat
......
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