From 7978ffd1e4819d24803b01a1147a2c33ad97c142 Mon Sep 17 00:00:00 2001 From: Pyre Bot Jr <> Date: Wed, 15 Jun 2022 06:27:35 -0700 Subject: [PATCH] suppress errors in `vision/fair/pytorch3d` Differential Revision: D37172764 fbshipit-source-id: a2ec367e56de2781a17f5e708eb5832ec9d7e6b4 --- pytorch3d/common/compat.py | 6 ++++ pytorch3d/common/datatypes.py | 2 +- pytorch3d/common/workaround/symeig3x3.py | 13 ++++---- pytorch3d/datasets/r2n2/utils.py | 2 +- pytorch3d/datasets/shapenet_base.py | 3 ++ .../implicitron/dataset/json_index_dataset.py | 4 ++- pytorch3d/implicitron/dataset/utils.py | 2 ++ .../evaluation/evaluate_new_view_synthesis.py | 7 +--- pytorch3d/implicitron/models/autodecoder.py | 2 ++ .../resnet_feature_extractor.py | 2 -- .../implicit_function/idr_feature_field.py | 8 ++++- .../neural_radiance_field.py | 2 ++ pytorch3d/implicitron/models/model_dbir.py | 4 +++ .../models/renderer/lstm_renderer.py | 6 ---- .../models/renderer/ray_sampler.py | 2 -- .../models/renderer/ray_tracing.py | 32 +++++++++++++++---- .../models/renderer/sdf_renderer.py | 10 ++++-- .../models/view_pooler/feature_aggregator.py | 3 +- .../models/view_pooler/view_sampler.py | 6 ++++ .../implicitron/third_party/hyperlayers.py | 1 - pytorch3d/implicitron/tools/circle_fitting.py | 1 + pytorch3d/implicitron/tools/depth_cleanup.py | 2 +- pytorch3d/implicitron/tools/metric_utils.py | 4 +++ .../implicitron/tools/point_cloud_utils.py | 5 +-- pytorch3d/implicitron/tools/vis_utils.py | 2 -- pytorch3d/io/mtl_io.py | 1 - pytorch3d/io/obj_io.py | 1 - pytorch3d/io/utils.py | 1 - pytorch3d/loss/mesh_laplacian_smoothing.py | 2 ++ pytorch3d/loss/point_mesh_distance.py | 4 +-- pytorch3d/ops/cameras_alignment.py | 11 ++++++- pytorch3d/ops/cubify.py | 1 - pytorch3d/ops/graph_conv.py | 1 - pytorch3d/ops/interp_face_attrs.py | 1 - pytorch3d/ops/iou_box3d.py | 2 -- pytorch3d/ops/knn.py | 1 - pytorch3d/ops/laplacian_matrices.py | 8 +++++ pytorch3d/ops/marching_cubes.py | 1 + pytorch3d/ops/mesh_filtering.py | 1 - pytorch3d/ops/points_alignment.py | 1 + pytorch3d/ops/points_to_volumes.py | 6 ++-- pytorch3d/ops/sample_farthest_points.py | 20 ++++++++++-- pytorch3d/ops/sample_points_from_meshes.py | 2 -- pytorch3d/ops/subdivide_meshes.py | 2 ++ pytorch3d/ops/utils.py | 4 +++ pytorch3d/ops/vert_align.py | 2 -- pytorch3d/renderer/camera_conversions.py | 1 - pytorch3d/renderer/cameras.py | 5 +++ pytorch3d/renderer/implicit/raymarching.py | 1 - pytorch3d/renderer/implicit/raysampling.py | 5 +-- pytorch3d/renderer/mesh/clip.py | 10 ++++-- pytorch3d/renderer/mesh/textures.py | 8 +++-- pytorch3d/renderer/splatter_blend.py | 7 +++- pytorch3d/renderer/utils.py | 1 + pytorch3d/structures/meshes.py | 1 - pytorch3d/structures/utils.py | 1 - pytorch3d/transforms/rotation_conversions.py | 12 ++++++- pytorch3d/transforms/se3.py | 4 +++ pytorch3d/transforms/so3.py | 4 ++- pytorch3d/transforms/transform3d.py | 2 ++ pytorch3d/vis/plotly_vis.py | 2 +- 61 files changed, 188 insertions(+), 80 deletions(-) diff --git a/pytorch3d/common/compat.py b/pytorch3d/common/compat.py index 74a8dd69e..86a2c5366 100644 --- a/pytorch3d/common/compat.py +++ b/pytorch3d/common/compat.py @@ -23,6 +23,7 @@ def solve(A: torch.Tensor, B: torch.Tensor) -> torch.Tensor: # pragma: no cover # PyTorch version >= 1.8.0 return torch.linalg.solve(A, B) + # pyre-fixme[16]: `Tuple` has no attribute `solution`. return torch.solve(B, A).solution @@ -67,9 +68,14 @@ def meshgrid_ij( Like torch.meshgrid was before PyTorch 1.10.0, i.e. with indexing set to ij """ if ( + # pyre-fixme[16]: Callable `meshgrid` has no attribute `__kwdefaults__`. torch.meshgrid.__kwdefaults__ is not None and "indexing" in torch.meshgrid.__kwdefaults__ ): # PyTorch >= 1.10.0 + # pyre-fixme[6]: For 1st param expected `Union[List[Tensor], Tensor]` but + # got `Union[Sequence[Tensor], Tensor]`. return torch.meshgrid(*A, indexing="ij") + # pyre-fixme[6]: For 1st param expected `Union[List[Tensor], Tensor]` but got + # `Union[Sequence[Tensor], Tensor]`. return torch.meshgrid(*A) diff --git a/pytorch3d/common/datatypes.py b/pytorch3d/common/datatypes.py index 63e698b33..8810d816f 100644 --- a/pytorch3d/common/datatypes.py +++ b/pytorch3d/common/datatypes.py @@ -26,7 +26,7 @@ def make_device(device: Device) -> torch.device: A matching torch.device object """ device = torch.device(device) if isinstance(device, str) else device - if device.type == "cuda" and device.index is None: # pyre-ignore[16] + if device.type == "cuda" and device.index is None: # If cuda but with no index, then the current cuda device is indicated. # In that case, we fix to that device device = torch.device(f"cuda:{torch.cuda.current_device()}") diff --git a/pytorch3d/common/workaround/symeig3x3.py b/pytorch3d/common/workaround/symeig3x3.py index 692bc9f4a..479f8b000 100644 --- a/pytorch3d/common/workaround/symeig3x3.py +++ b/pytorch3d/common/workaround/symeig3x3.py @@ -75,12 +75,14 @@ def forward( if inputs.shape[-2:] != (3, 3): raise ValueError("Only inputs of shape (..., 3, 3) are supported.") - inputs_diag = inputs.diagonal(dim1=-2, dim2=-1) # pyre-ignore[16] + inputs_diag = inputs.diagonal(dim1=-2, dim2=-1) inputs_trace = inputs_diag.sum(-1) q = inputs_trace / 3.0 # Calculate squared sum of elements outside the main diagonal / 2 + # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`. p1 = ((inputs**2).sum(dim=(-1, -2)) - (inputs_diag**2).sum(-1)) / 2 + # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`. p2 = ((inputs_diag - q[..., None]) ** 2).sum(dim=-1) + 2.0 * p1.clamp(self._eps) p = torch.sqrt(p2 / 6.0) @@ -195,8 +197,9 @@ def _get_ev0(self, char_poly: torch.Tensor) -> torch.Tensor: cross_products[..., :1, :] ) + # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`. norms_sq = (cross_products**2).sum(dim=-1) - max_norms_index = norms_sq.argmax(dim=-1) # pyre-ignore[16] + max_norms_index = norms_sq.argmax(dim=-1) # Pick only the cross-product with highest squared norm for each input max_cross_products = self._gather_by_index( @@ -227,9 +230,7 @@ def _gather_by_index( index_shape = list(source.shape) index_shape[dim] = 1 - return source.gather(dim, index.expand(index_shape)).squeeze( # pyre-ignore[16] - dim - ) + return source.gather(dim, index.expand(index_shape)).squeeze(dim) def _get_uv(self, w: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]: """ @@ -243,7 +244,7 @@ def _get_uv(self, w: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]: Tuple of U and V unit-length vector tensors of shape (..., 3) """ - min_idx = w.abs().argmin(dim=-1) # pyre-ignore[16] + min_idx = w.abs().argmin(dim=-1) rotation_2d = self._rotations_3d[min_idx].to(w) u = F.normalize((rotation_2d @ w[..., None])[..., 0], dim=-1) diff --git a/pytorch3d/datasets/r2n2/utils.py b/pytorch3d/datasets/r2n2/utils.py index c5b5f394f..6e9611eed 100644 --- a/pytorch3d/datasets/r2n2/utils.py +++ b/pytorch3d/datasets/r2n2/utils.py @@ -140,7 +140,6 @@ def compute_extrinsic_matrix( # rotates the model 90 degrees about the x axis. To compensate for this quirk we # roll that rotation into the extrinsic matrix here rot = torch.tensor([[1, 0, 0, 0], [0, 0, -1, 0], [0, 1, 0, 0], [0, 0, 0, 1]]) - # pyre-fixme[16]: `Tensor` has no attribute `mm`. RT = RT.mm(rot.to(RT)) return RT @@ -180,6 +179,7 @@ def read_binvox_coords( size, translation, scale = _read_binvox_header(f) storage = torch.ByteStorage.from_buffer(f.read()) data = torch.tensor([], dtype=torch.uint8) + # pyre-fixme[28]: Unexpected keyword argument `source`. data.set_(source=storage) vals, counts = data[::2], data[1::2] idxs = _compute_idxs(vals, counts) diff --git a/pytorch3d/datasets/shapenet_base.py b/pytorch3d/datasets/shapenet_base.py index eca26e900..7160ca6cb 100644 --- a/pytorch3d/datasets/shapenet_base.py +++ b/pytorch3d/datasets/shapenet_base.py @@ -227,6 +227,8 @@ def _handle_render_inputs( sampled_idxs = self._sample_idxs_from_category( sample_num=sample_num, category=category ) + # pyre-fixme[6]: For 1st param expected `Union[List[Tensor], + # typing.Tuple[Tensor, ...]]` but got `Tuple[Tensor, List[int]]`. idxs_tensor = torch.cat((idxs_tensor, sampled_idxs)) idxs = idxs_tensor.tolist() # Check if the indices are valid if idxs are supplied. @@ -283,4 +285,5 @@ def _sample_idxs_from_category( "category " + category if category is not None else "all categories", ) warnings.warn(msg) + # pyre-fixme[7]: Expected `List[int]` but got `Tensor`. return sampled_idxs diff --git a/pytorch3d/implicitron/dataset/json_index_dataset.py b/pytorch3d/implicitron/dataset/json_index_dataset.py index b5b083171..8fefe64ae 100644 --- a/pytorch3d/implicitron/dataset/json_index_dataset.py +++ b/pytorch3d/implicitron/dataset/json_index_dataset.py @@ -640,14 +640,16 @@ def _resize_image( ) imre = torch.nn.functional.interpolate( torch.from_numpy(image)[None], - # pyre-ignore[6] scale_factor=minscale, mode=mode, align_corners=False if mode == "bilinear" else None, recompute_scale_factor=True, )[0] + # pyre-fixme[19]: Expected 1 positional argument. imre_ = torch.zeros(image.shape[0], self.image_height, self.image_width) imre_[:, 0 : imre.shape[1], 0 : imre.shape[2]] = imre + # pyre-fixme[6]: For 2nd param expected `int` but got `Optional[int]`. + # pyre-fixme[6]: For 3rd param expected `int` but got `Optional[int]`. mask = torch.zeros(1, self.image_height, self.image_width) mask[:, 0 : imre.shape[1] - 1, 0 : imre.shape[2] - 1] = 1.0 return imre_, minscale, mask diff --git a/pytorch3d/implicitron/dataset/utils.py b/pytorch3d/implicitron/dataset/utils.py index 2bd065002..e20570801 100644 --- a/pytorch3d/implicitron/dataset/utils.py +++ b/pytorch3d/implicitron/dataset/utils.py @@ -23,6 +23,7 @@ def is_known_frame( Given a list `frame_type` of frame types in a batch, return a tensor of boolean flags expressing whether the corresponding frame is a known frame. """ + # pyre-fixme[7]: Expected `BoolTensor` but got `Tensor`. return torch.tensor( [ft.endswith(DATASET_TYPE_KNOWN) for ft in frame_type], dtype=torch.bool, @@ -37,6 +38,7 @@ def is_train_frame( Given a list `frame_type` of frame types in a batch, return a tensor of boolean flags expressing whether the corresponding frame is a training frame. """ + # pyre-fixme[7]: Expected `BoolTensor` but got `Tensor`. return torch.tensor( [ft.startswith(DATASET_TYPE_TRAIN) for ft in frame_type], dtype=torch.bool, diff --git a/pytorch3d/implicitron/evaluation/evaluate_new_view_synthesis.py b/pytorch3d/implicitron/evaluation/evaluate_new_view_synthesis.py index a894c6c47..3d4b4ad12 100644 --- a/pytorch3d/implicitron/evaluation/evaluate_new_view_synthesis.py +++ b/pytorch3d/implicitron/evaluation/evaluate_new_view_synthesis.py @@ -205,11 +205,7 @@ def eval_batch( imode = "bilinear" if k == "image_render" else "nearest" cloned_render[k] = ( - # pyre-fixme[6]: For 2nd param expected `Optional[int]` but got - # `Tuple[Any, ...]`. - F.interpolate(field[:1], size=image_resol, mode=imode) - .detach() - .clone() + F.interpolate(field[:1], size=image_resol, mode=imode).detach().clone() ) frame_data = copy.deepcopy(frame_data) @@ -408,7 +404,6 @@ def _reduce_camera_iou_overlap(ious: torch.Tensor, topk: int = 2) -> torch.Tenso Returns: single-element Tensor """ - # pyre-ignore[16] topk not recognized return ious.topk(k=min(topk, len(ious) - 1)).values.mean() diff --git a/pytorch3d/implicitron/models/autodecoder.py b/pytorch3d/implicitron/models/autodecoder.py index bac6a4161..f79102626 100644 --- a/pytorch3d/implicitron/models/autodecoder.py +++ b/pytorch3d/implicitron/models/autodecoder.py @@ -99,6 +99,8 @@ def forward(self, x: Union[torch.LongTensor, List[str]]) -> Optional[torch.Tenso if isinstance(x[0], str): try: + # pyre-fixme[9]: x has type `Union[List[str], LongTensor]`; used as + # `Tensor`. x = torch.tensor( # pyre-ignore[29] [self._sequence_map[elem] for elem in x], diff --git a/pytorch3d/implicitron/models/feature_extractor/resnet_feature_extractor.py b/pytorch3d/implicitron/models/feature_extractor/resnet_feature_extractor.py index 8167f2cdc..baa20c208 100644 --- a/pytorch3d/implicitron/models/feature_extractor/resnet_feature_extractor.py +++ b/pytorch3d/implicitron/models/feature_extractor/resnet_feature_extractor.py @@ -169,8 +169,6 @@ def forward( if self.image_rescale != 1.0 and imgs_input is not None: imgs_resized = Fu.interpolate( imgs_input, - # pyre-fixme[6]: For 2nd param expected `Optional[List[float]]` but - # got `float`. scale_factor=self.image_rescale, mode="bilinear", ) diff --git a/pytorch3d/implicitron/models/implicit_function/idr_feature_field.py b/pytorch3d/implicitron/models/implicit_function/idr_feature_field.py index 17faf9c38..d54ef78ca 100644 --- a/pytorch3d/implicitron/models/implicit_function/idr_feature_field.py +++ b/pytorch3d/implicitron/models/implicit_function/idr_feature_field.py @@ -103,7 +103,11 @@ def forward( self.embed_fn is None and fun_viewpool is None and global_code is None ): return torch.tensor( - [], device=rays_points_world.device, dtype=rays_points_world.dtype + [], + device=rays_points_world.device, + dtype=rays_points_world.dtype + # pyre-fixme[6]: For 2nd param expected `int` but got `Union[Module, + # Tensor]`. ).view(0, self.out_dim) embedding = None @@ -128,6 +132,7 @@ def forward( ) x = embedding + # pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C._TensorBase.__s... for layer_idx in range(self.num_layers - 1): if layer_idx in self.skip_in: x = torch.cat([x, embedding], dim=-1) / 2**0.5 @@ -135,6 +140,7 @@ def forward( # pyre-fixme[29]: `Union[torch.Tensor, torch.nn.Module]` is not a function. x = self.linear_layers[layer_idx](x) + # pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C._TensorBase... if layer_idx < self.num_layers - 2: # pyre-fixme[29]: `Union[torch.Tensor, torch.nn.Module]` is not a function. x = self.softplus(x) diff --git a/pytorch3d/implicitron/models/implicit_function/neural_radiance_field.py b/pytorch3d/implicitron/models/implicit_function/neural_radiance_field.py index 8592f6dee..7710e9e8f 100644 --- a/pytorch3d/implicitron/models/implicit_function/neural_radiance_field.py +++ b/pytorch3d/implicitron/models/implicit_function/neural_radiance_field.py @@ -406,6 +406,8 @@ def __init__( self.last = torch.nn.Linear(dimout, output_dim) _xavier_init(self.last) + # pyre-fixme[8]: Attribute has type `Tuple[ModuleList, ModuleList]`; used as + # `ModuleList`. self.layers_pool, self.layers_ray = ( torch.nn.ModuleList(layers_pool), torch.nn.ModuleList(layers_ray), diff --git a/pytorch3d/implicitron/models/model_dbir.py b/pytorch3d/implicitron/models/model_dbir.py index 47eab20e0..62dd0a7f5 100644 --- a/pytorch3d/implicitron/models/model_dbir.py +++ b/pytorch3d/implicitron/models/model_dbir.py @@ -93,6 +93,8 @@ def forward( mask_fg = (fg_probability > 0.5).type_as(image_rgb) point_cloud = get_rgbd_point_cloud( + # pyre-fixme[6]: For 1st param expected `Union[List[int], int, + # LongTensor]` but got `Tensor`. camera[is_known_idx], image_rgb[is_known_idx], depth_map[is_known_idx], @@ -101,6 +103,8 @@ def forward( pcl_size = point_cloud.num_points_per_cloud().item() if (self.max_points > 0) and (pcl_size > self.max_points): + # pyre-fixme[6]: For 1st param expected `int` but got `Union[bool, + # float, int]`. prm = torch.randperm(pcl_size)[: self.max_points] point_cloud = Pointclouds( point_cloud.points_padded()[:, prm, :], diff --git a/pytorch3d/implicitron/models/renderer/lstm_renderer.py b/pytorch3d/implicitron/models/renderer/lstm_renderer.py index 2a644263d..5121ea163 100644 --- a/pytorch3d/implicitron/models/renderer/lstm_renderer.py +++ b/pytorch3d/implicitron/models/renderer/lstm_renderer.py @@ -117,13 +117,7 @@ def forward( msg = ( f"{t}: mu={float(signed_distance.mean()):1.2e};" + f" std={float(signed_distance.std()):1.2e};" - # pyre-fixme[6]: Expected `Union[bytearray, bytes, str, - # typing.SupportsFloat, typing_extensions.SupportsIndex]` for 1st - # param but got `Tensor`. + f" mu_d={float(ray_bundle_t.lengths.mean()):1.2e};" - # pyre-fixme[6]: Expected `Union[bytearray, bytes, str, - # typing.SupportsFloat, typing_extensions.SupportsIndex]` for 1st - # param but got `Tensor`. + f" std_d={float(ray_bundle_t.lengths.std()):1.2e};" ) logger.info(msg) diff --git a/pytorch3d/implicitron/models/renderer/ray_sampler.py b/pytorch3d/implicitron/models/renderer/ray_sampler.py index 89dc6d549..eb5309686 100644 --- a/pytorch3d/implicitron/models/renderer/ray_sampler.py +++ b/pytorch3d/implicitron/models/renderer/ray_sampler.py @@ -164,8 +164,6 @@ def forward( ): sample_mask = torch.nn.functional.interpolate( mask, - # pyre-fixme[6]: Expected `Optional[int]` for 2nd param but got - # `List[int]`. size=[self.image_height, self.image_width], mode="nearest", )[:, 0] diff --git a/pytorch3d/implicitron/models/renderer/ray_tracing.py b/pytorch3d/implicitron/models/renderer/ray_tracing.py index 85e2248d0..890b055e9 100644 --- a/pytorch3d/implicitron/models/renderer/ray_tracing.py +++ b/pytorch3d/implicitron/models/renderer/ray_tracing.py @@ -123,12 +123,12 @@ def forward( ray_directions = ray_directions.reshape(-1, 3) mask_intersect = mask_intersect.reshape(-1) + # pyre-fixme[9]: object_mask has type `BoolTensor`; used as `Tensor`. object_mask = object_mask.reshape(-1) in_mask = ~network_object_mask & object_mask & ~sampler_mask out_mask = ~object_mask & ~sampler_mask - # pyre-fixme[16]: `Tensor` has no attribute `__invert__`. mask_left_out = (in_mask | out_mask) & ~mask_intersect if ( mask_left_out.sum() > 0 @@ -410,10 +410,17 @@ def ray_sampler( if n_p_out > 0: out_pts_idx = torch.argmin(sdf_val[p_out_mask, :], -1) sampler_pts[mask_intersect_idx[p_out_mask]] = points[p_out_mask, :, :][ - torch.arange(n_p_out), out_pts_idx, : + # pyre-fixme[6]: For 1st param expected `Union[bool, float, int]` + # but got `Tensor`. + torch.arange(n_p_out), + out_pts_idx, + :, ] sampler_dists[mask_intersect_idx[p_out_mask]] = pts_intervals[ - p_out_mask, : + p_out_mask, + : + # pyre-fixme[6]: For 1st param expected `Union[bool, float, int]` but + # got `Tensor`. ][torch.arange(n_p_out), out_pts_idx] # Get Network object mask @@ -434,10 +441,16 @@ def ray_sampler( secant_pts ] z_low = pts_intervals[secant_pts][ - torch.arange(n_secant_pts), sampler_pts_ind[secant_pts] - 1 + # pyre-fixme[6]: For 1st param expected `Union[bool, float, int]` + # but got `Tensor`. + torch.arange(n_secant_pts), + sampler_pts_ind[secant_pts] - 1, ] sdf_low = sdf_val[secant_pts][ - torch.arange(n_secant_pts), sampler_pts_ind[secant_pts] - 1 + # pyre-fixme[6]: For 1st param expected `Union[bool, float, int]` + # but got `Tensor`. + torch.arange(n_secant_pts), + sampler_pts_ind[secant_pts] - 1, ] cam_loc_secant = cam_loc.reshape(-1, 3)[mask_intersect_idx[secant_pts]] ray_directions_secant = ray_directions.reshape((-1, 3))[ @@ -514,6 +527,7 @@ def minimal_sdf_points( mask_max_dis = max_dis[mask].unsqueeze(-1) mask_min_dis = min_dis[mask].unsqueeze(-1) steps = ( + # pyre-fixme[6]: For 1st param expected `int` but got `Tensor`. steps.unsqueeze(0).repeat(n_mask_points, 1) * (mask_max_dis - mask_min_dis) + mask_min_dis ) @@ -533,8 +547,13 @@ def minimal_sdf_points( mask_sdf_all = torch.cat(mask_sdf_all).reshape(-1, n) min_vals, min_idx = mask_sdf_all.min(-1) min_mask_points = mask_points_all.reshape(-1, n, 3)[ - torch.arange(0, n_mask_points), min_idx + # pyre-fixme[6]: For 2nd param expected `Union[bool, float, int]` but + # got `Tensor`. + torch.arange(0, n_mask_points), + min_idx, ] + # pyre-fixme[6]: For 2nd param expected `Union[bool, float, int]` but got + # `Tensor`. min_mask_dist = steps.reshape(-1, n)[torch.arange(0, n_mask_points), min_idx] return min_mask_points, min_mask_dist @@ -553,6 +572,7 @@ def _get_sphere_intersection( # cam_loc = cam_loc.unsqueeze(-1) # ray_cam_dot = torch.bmm(ray_directions, cam_loc).squeeze() ray_cam_dot = (ray_directions * cam_loc).sum(-1) # n_images x n_rays + # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`. under_sqrt = ray_cam_dot**2 - (cam_loc.norm(2, dim=-1) ** 2 - r**2) under_sqrt = under_sqrt.reshape(-1) diff --git a/pytorch3d/implicitron/models/renderer/sdf_renderer.py b/pytorch3d/implicitron/models/renderer/sdf_renderer.py index 549f4cc80..edda575fb 100644 --- a/pytorch3d/implicitron/models/renderer/sdf_renderer.py +++ b/pytorch3d/implicitron/models/renderer/sdf_renderer.py @@ -132,7 +132,11 @@ def forward( eik_bounding_box: float = self.object_bounding_sphere n_eik_points = batch_size * num_pixels // 2 eikonal_points = torch.empty( - n_eik_points, 3, device=self._bg_color.device + n_eik_points, + 3, + # pyre-fixme[6]: For 3rd param expected `Union[None, str, device]` + # but got `Union[device, Tensor, Module]`. + device=self._bg_color.device, ).uniform_(-eik_bounding_box, eik_bounding_box) eikonal_pixel_points = points.clone() eikonal_pixel_points = eikonal_pixel_points.detach() @@ -196,7 +200,9 @@ def forward( pooling_fn=None, # TODO ) mask_full.view(-1, 1)[~surface_mask] = torch.sigmoid( - -self.soft_mask_alpha * sdf_output[~surface_mask] + # pyre-fixme[6]: For 1st param expected `Tensor` but got `float`. + -self.soft_mask_alpha + * sdf_output[~surface_mask] ) # scatter points with surface_mask diff --git a/pytorch3d/implicitron/models/view_pooler/feature_aggregator.py b/pytorch3d/implicitron/models/view_pooler/feature_aggregator.py index 26b8b7db9..37365d0cd 100644 --- a/pytorch3d/implicitron/models/view_pooler/feature_aggregator.py +++ b/pytorch3d/implicitron/models/view_pooler/feature_aggregator.py @@ -550,7 +550,6 @@ def _get_ray_dir_dot_prods(camera: CamerasBase, pts: torch.Tensor): # torch.Tensor, torch.nn.modules.module.Module]` is not a function. # pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch.Tensor.permute)[[N... camera_rep.T[:, None], - # pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch.Tensor.permute)[[N... camera_rep.R.permute(0, 2, 1), ).reshape(-1, *([1] * (pts.ndim - 2)), 3) # cam_centers_rep = camera_rep.get_camera_center().reshape( @@ -649,6 +648,7 @@ def _avgmaxstd_reduction_function( x_aggr = torch.cat(pooled_features, dim=-1) # zero out features that were all masked out + # pyre-fixme[16]: `bool` has no attribute `type_as`. any_active = (w.max(dim=dim, keepdim=True).values > 1e-4).type_as(x_aggr) x_aggr = x_aggr * any_active[..., None] @@ -676,6 +676,7 @@ def _std_reduction_function( ): if mu is None: mu = _avg_reduction_function(x, w, dim=dim) + # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`. std = wmean((x - mu) ** 2, w, dim=dim, eps=1e-2).clamp(1e-4).sqrt() # FIXME: somehow this is extremely heavy in mem? return std diff --git a/pytorch3d/implicitron/models/view_pooler/view_sampler.py b/pytorch3d/implicitron/models/view_pooler/view_sampler.py index eb8413b5f..5cc3156c5 100644 --- a/pytorch3d/implicitron/models/view_pooler/view_sampler.py +++ b/pytorch3d/implicitron/models/view_pooler/view_sampler.py @@ -205,7 +205,11 @@ def handle_seq_id( if not torch.is_tensor(seq_id): if isinstance(seq_id[0], str): seq_id = [hash(s) for s in seq_id] + # pyre-fixme[9]: seq_id has type `Union[List[int], List[str], LongTensor]`; + # used as `Tensor`. seq_id = torch.tensor(seq_id, dtype=torch.long, device=device) + # pyre-fixme[16]: Item `List` of `Union[List[int], List[str], LongTensor]` has + # no attribute `to`. return seq_id.to(device) @@ -287,5 +291,7 @@ def cameras_points_cartesian_product( ) .reshape(batch_pts * n_cameras) ) + # pyre-fixme[6]: For 1st param expected `Union[List[int], int, LongTensor]` but + # got `Tensor`. camera_rep = camera[idx_cams] return camera_rep, pts_rep diff --git a/pytorch3d/implicitron/third_party/hyperlayers.py b/pytorch3d/implicitron/third_party/hyperlayers.py index 1fb32171d..e56235130 100644 --- a/pytorch3d/implicitron/third_party/hyperlayers.py +++ b/pytorch3d/implicitron/third_party/hyperlayers.py @@ -215,7 +215,6 @@ def forward(self, input): def last_hyper_layer_init(m) -> None: if type(m) == nn.Linear: nn.init.kaiming_normal_(m.weight, a=0.0, nonlinearity="relu", mode="fan_in") - # pyre-fixme[41]: `data` cannot be reassigned. It is a read-only property. m.weight.data *= 1e-1 diff --git a/pytorch3d/implicitron/tools/circle_fitting.py b/pytorch3d/implicitron/tools/circle_fitting.py index 05f16e742..97165ed1c 100644 --- a/pytorch3d/implicitron/tools/circle_fitting.py +++ b/pytorch3d/implicitron/tools/circle_fitting.py @@ -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: diff --git a/pytorch3d/implicitron/tools/depth_cleanup.py b/pytorch3d/implicitron/tools/depth_cleanup.py index a4a8bab4c..76a3c7032 100644 --- a/pytorch3d/implicitron/tools/depth_cleanup.py +++ b/pytorch3d/implicitron/tools/depth_cleanup.py @@ -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() diff --git a/pytorch3d/implicitron/tools/metric_utils.py b/pytorch3d/implicitron/tools/metric_utils.py index 9c565d6e8..3494e922c 100644 --- a/pytorch3d/implicitron/tools/metric_utils.py +++ b/pytorch3d/implicitron/tools/metric_utils.py @@ -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 diff --git a/pytorch3d/implicitron/tools/point_cloud_utils.py b/pytorch3d/implicitron/tools/point_cloud_utils.py index 9af23e304..edcb16f3f 100644 --- a/pytorch3d/implicitron/tools/point_cloud_utils.py +++ b/pytorch3d/implicitron/tools/point_cloud_utils.py @@ -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", ) diff --git a/pytorch3d/implicitron/tools/vis_utils.py b/pytorch3d/implicitron/tools/vis_utils.py index cd7223a41..2c352d29e 100644 --- a/pytorch3d/implicitron/tools/vis_utils.py +++ b/pytorch3d/implicitron/tools/vis_utils.py @@ -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 ( diff --git a/pytorch3d/io/mtl_io.py b/pytorch3d/io/mtl_io.py index 40de82598..166f98a8e 100644 --- a/pytorch3d/io/mtl_io.py +++ b/pytorch3d/io/mtl_io.py @@ -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) diff --git a/pytorch3d/io/obj_io.py b/pytorch3d/io/obj_io.py index 09bb53464..6d3e7eca9 100644 --- a/pytorch3d/io/obj_io.py +++ b/pytorch3d/io/obj_io.py @@ -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. diff --git a/pytorch3d/io/utils.py b/pytorch3d/io/utils.py index e0bd796bb..fd60ee9be 100644 --- a/pytorch3d/io/utils.py +++ b/pytorch3d/io/utils.py @@ -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 diff --git a/pytorch3d/loss/mesh_laplacian_smoothing.py b/pytorch3d/loss/mesh_laplacian_smoothing.py index 36a8bd605..5f4bea230 100644 --- a/pytorch3d/loss/mesh_laplacian_smoothing.py +++ b/pytorch3d/loss/mesh_laplacian_smoothing.py @@ -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) diff --git a/pytorch3d/loss/point_mesh_distance.py b/pytorch3d/loss/point_mesh_distance.py index 40497c940..fb8169c20 100644 --- a/pytorch3d/loss/point_mesh_distance.py +++ b/pytorch3d/loss/point_mesh_distance.py @@ -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 diff --git a/pytorch3d/ops/cameras_alignment.py b/pytorch3d/ops/cameras_alignment.py index 4534341a8..babbd733a 100644 --- a/pytorch3d/ops/cameras_alignment.py +++ b/pytorch3d/ops/cameras_alignment.py @@ -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 diff --git a/pytorch3d/ops/cubify.py b/pytorch3d/ops/cubify.py index b47d44b05..77bc924ad 100644 --- a/pytorch3d/ops/cubify.py +++ b/pytorch3d/ops/cubify.py @@ -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) ] diff --git a/pytorch3d/ops/graph_conv.py b/pytorch3d/ops/graph_conv.py index 035a0dc6a..600ae7aee 100644 --- a/pytorch3d/ops/graph_conv.py +++ b/pytorch3d/ops/graph_conv.py @@ -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)) diff --git a/pytorch3d/ops/interp_face_attrs.py b/pytorch3d/ops/interp_face_attrs.py index cbf79590e..704982bb4 100644 --- a/pytorch3d/ops/interp_face_attrs.py +++ b/pytorch3d/ops/interp_face_attrs.py @@ -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. diff --git a/pytorch3d/ops/iou_box3d.py b/pytorch3d/ops/iou_box3d.py index 91aec4af6..e2338c268 100644 --- a/pytorch3d/ops/iou_box3d.py +++ b/pytorch3d/ops/iou_box3d.py @@ -47,7 +47,6 @@ 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 diff --git a/pytorch3d/ops/knn.py b/pytorch3d/ops/knn.py index 72e3c2895..747bc5a33 100644 --- a/pytorch3d/ops/knn.py +++ b/pytorch3d/ops/knn.py @@ -84,7 +84,6 @@ def forward( 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) diff --git a/pytorch3d/ops/laplacian_matrices.py b/pytorch3d/ops/laplacian_matrices.py index 13f2285d1..542fbebf5 100644 --- a/pytorch3d/ops/laplacian_matrices.py +++ b/pytorch3d/ops/laplacian_matrices.py @@ -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() diff --git a/pytorch3d/ops/marching_cubes.py b/pytorch3d/ops/marching_cubes.py index 8a5d93ae1..1747667a0 100644 --- a/pytorch3d/ops/marching_cubes.py +++ b/pytorch3d/ops/marching_cubes.py @@ -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] diff --git a/pytorch3d/ops/mesh_filtering.py b/pytorch3d/ops/mesh_filtering.py index 867f45dde..90cf1211c 100644 --- a/pytorch3d/ops/mesh_filtering.py +++ b/pytorch3d/ops/mesh_filtering.py @@ -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 diff --git a/pytorch3d/ops/points_alignment.py b/pytorch3d/ops/points_alignment.py index aa4552db0..61e2bbb87 100644 --- a/pytorch3d/ops/points_alignment.py +++ b/pytorch3d/ops/points_alignment.py @@ -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] diff --git a/pytorch3d/ops/points_to_volumes.py b/pytorch3d/ops/points_to_volumes.py index 5cba9fe10..3fab749c6 100644 --- a/pytorch3d/ops/points_to_volumes.py +++ b/pytorch3d/ops/points_to_volumes.py @@ -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) diff --git a/pytorch3d/ops/sample_farthest_points.py b/pytorch3d/ops/sample_farthest_points.py index 47b5a96e7..92f3efcde 100644 --- a/pytorch3d/ops/sample_farthest_points.py +++ b/pytorch3d/ops/sample_farthest_points.py @@ -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 diff --git a/pytorch3d/ops/sample_points_from_meshes.py b/pytorch3d/ops/sample_points_from_meshes.py index 3f44359fb..2e2d34890 100644 --- a/pytorch3d/ops/sample_points_from_meshes.py +++ b/pytorch3d/ops/sample_points_from_meshes.py @@ -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 diff --git a/pytorch3d/ops/subdivide_meshes.py b/pytorch3d/ops/subdivide_meshes.py index 2426fee6c..9a633ae2c 100644 --- a/pytorch3d/ops/subdivide_meshes.py +++ b/pytorch3d/ops/subdivide_meshes.py @@ -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 diff --git a/pytorch3d/ops/utils.py b/pytorch3d/ops/utils.py index 134e49b64..cb576d5b7 100644 --- a/pytorch3d/ops/utils.py +++ b/pytorch3d/ops/utils.py @@ -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 ) diff --git a/pytorch3d/ops/vert_align.py b/pytorch3d/ops/vert_align.py index 82aa2a314..f8181aebd 100644 --- a/pytorch3d/ops/vert_align.py +++ b/pytorch3d/ops/vert_align.py @@ -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 diff --git a/pytorch3d/renderer/camera_conversions.py b/pytorch3d/renderer/camera_conversions.py index 9fb73e5fc..0b90ccec0 100644 --- a/pytorch3d/renderer/camera_conversions.py +++ b/pytorch3d/renderer/camera_conversions.py @@ -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 diff --git a/pytorch3d/renderer/cameras.py b/pytorch3d/renderer/cameras.py index d2d2d3cf3..f7f6c9e9a 100644 --- a/pytorch3d/renderer/cameras.py +++ b/pytorch3d/renderer/cameras.py @@ -401,6 +401,7 @@ def __getitem__( 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 @@ def compute_projection_matrix( # 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) diff --git a/pytorch3d/renderer/implicit/raymarching.py b/pytorch3d/renderer/implicit/raymarching.py index 5802b23c9..1f3ca9ba9 100644 --- a/pytorch3d/renderer/implicit/raymarching.py +++ b/pytorch3d/renderer/implicit/raymarching.py @@ -158,7 +158,6 @@ def forward( _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 diff --git a/pytorch3d/renderer/implicit/raysampling.py b/pytorch3d/renderer/implicit/raysampling.py index b73a94cd7..03b096c60 100644 --- a/pytorch3d/renderer/implicit/raysampling.py +++ b/pytorch3d/renderer/implicit/raysampling.py @@ -180,6 +180,8 @@ def forward( # 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,)) diff --git a/pytorch3d/renderer/mesh/clip.py b/pytorch3d/renderer/mesh/clip.py index e468aec45..6261f9c5e 100644 --- a/pytorch3d/renderer/mesh/clip.py +++ b/pytorch3d/renderer/mesh/clip.py @@ -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 diff --git a/pytorch3d/renderer/mesh/textures.py b/pytorch3d/renderer/mesh/textures.py index f4960c870..5b96fd0ee 100644 --- a/pytorch3d/renderer/mesh/textures.py +++ b/pytorch3d/renderer/mesh/textures.py @@ -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, diff --git a/pytorch3d/renderer/splatter_blend.py b/pytorch3d/renderer/splatter_blend.py index 92f5220a9..261076639 100644 --- a/pytorch3d/renderer/splatter_blend.py +++ b/pytorch3d/renderer/splatter_blend.py @@ -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), diff --git a/pytorch3d/renderer/utils.py b/pytorch3d/renderer/utils.py index 414c7f790..ab11b4bee 100644 --- a/pytorch3d/renderer/utils.py +++ b/pytorch3d/renderer/utils.py @@ -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( diff --git a/pytorch3d/structures/meshes.py b/pytorch3d/structures/meshes.py index 1761e7bf8..40ff1c3cf 100644 --- a/pytorch3d/structures/meshes.py +++ b/pytorch3d/structures/meshes.py @@ -890,7 +890,6 @@ def _compute_vertex_normals(self, refresh: bool = False): # 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], diff --git a/pytorch3d/structures/utils.py b/pytorch3d/structures/utils.py index 7b16ec55a..aab4fc3da 100644 --- a/pytorch3d/structures/utils.py +++ b/pytorch3d/structures/utils.py @@ -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 diff --git a/pytorch3d/transforms/rotation_conversions.py b/pytorch3d/transforms/rotation_conversions.py index bc369206c..6873d69db 100644 --- a/pytorch3d/transforms/rotation_conversions.py +++ b/pytorch3d/transforms/rotation_conversions.py @@ -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] diff --git a/pytorch3d/transforms/se3.py b/pytorch3d/transforms/se3.py index f334a1943..81a17c755 100644 --- a/pytorch3d/transforms/se3.py +++ b/pytorch3d/transforms/se3.py @@ -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) diff --git a/pytorch3d/transforms/so3.py b/pytorch3d/transforms/so3.py index 59c499e32..f8dde4088 100644 --- a/pytorch3d/transforms/so3.py +++ b/pytorch3d/transforms/so3.py @@ -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]) diff --git a/pytorch3d/transforms/transform3d.py b/pytorch3d/transforms/transform3d.py index 580c02b63..f330eb2c4 100644 --- a/pytorch3d/transforms/transform3d.py +++ b/pytorch3d/transforms/transform3d.py @@ -556,7 +556,9 @@ def _get_matrix_inverse(self) -> torch.Tensor: 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 diff --git a/pytorch3d/vis/plotly_vis.py b/pytorch3d/vis/plotly_vis.py index b6e33e0c6..776f47688 100644 --- a/pytorch3d/vis/plotly_vis.py +++ b/pytorch3d/vis/plotly_vis.py @@ -780,7 +780,7 @@ def _add_ray_bundle_trace( """ n_pts_per_ray = ray_bundle.lengths.shape[-1] - n_rays = ray_bundle.lengths.shape[:-1].numel() # pyre-ignore[16] + n_rays = ray_bundle.lengths.shape[:-1].numel() # flatten all batches of rays into a single big bundle ray_bundle_flat = RayBundle(