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