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

suppress errors in `vision/fair/pytorch3d`

Differential Revision: D37172764

fbshipit-source-id: a2ec367e56de2781a17f5e708eb5832ec9d7e6b4
parent ea4f3260
...@@ -23,6 +23,7 @@ def solve(A: torch.Tensor, B: torch.Tensor) -> torch.Tensor: # pragma: no cover ...@@ -23,6 +23,7 @@ def solve(A: torch.Tensor, B: torch.Tensor) -> torch.Tensor: # pragma: no cover
# PyTorch version >= 1.8.0 # PyTorch version >= 1.8.0
return torch.linalg.solve(A, B) return torch.linalg.solve(A, B)
# pyre-fixme[16]: `Tuple` has no attribute `solution`.
return torch.solve(B, A).solution return torch.solve(B, A).solution
...@@ -67,9 +68,14 @@ def meshgrid_ij( ...@@ -67,9 +68,14 @@ def meshgrid_ij(
Like torch.meshgrid was before PyTorch 1.10.0, i.e. with indexing set to ij Like torch.meshgrid was before PyTorch 1.10.0, i.e. with indexing set to ij
""" """
if ( if (
# pyre-fixme[16]: Callable `meshgrid` has no attribute `__kwdefaults__`.
torch.meshgrid.__kwdefaults__ is not None torch.meshgrid.__kwdefaults__ is not None
and "indexing" in torch.meshgrid.__kwdefaults__ and "indexing" in torch.meshgrid.__kwdefaults__
): ):
# PyTorch >= 1.10.0 # 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") 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) return torch.meshgrid(*A)
...@@ -26,7 +26,7 @@ def make_device(device: Device) -> torch.device: ...@@ -26,7 +26,7 @@ def make_device(device: Device) -> torch.device:
A matching torch.device object A matching torch.device object
""" """
device = torch.device(device) if isinstance(device, str) else device 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. # If cuda but with no index, then the current cuda device is indicated.
# In that case, we fix to that device # In that case, we fix to that device
device = torch.device(f"cuda:{torch.cuda.current_device()}") device = torch.device(f"cuda:{torch.cuda.current_device()}")
......
...@@ -75,12 +75,14 @@ class _SymEig3x3(nn.Module): ...@@ -75,12 +75,14 @@ class _SymEig3x3(nn.Module):
if inputs.shape[-2:] != (3, 3): if inputs.shape[-2:] != (3, 3):
raise ValueError("Only inputs of shape (..., 3, 3) are supported.") 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) inputs_trace = inputs_diag.sum(-1)
q = inputs_trace / 3.0 q = inputs_trace / 3.0
# Calculate squared sum of elements outside the main diagonal / 2 # 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 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) p2 = ((inputs_diag - q[..., None]) ** 2).sum(dim=-1) + 2.0 * p1.clamp(self._eps)
p = torch.sqrt(p2 / 6.0) p = torch.sqrt(p2 / 6.0)
...@@ -195,8 +197,9 @@ class _SymEig3x3(nn.Module): ...@@ -195,8 +197,9 @@ class _SymEig3x3(nn.Module):
cross_products[..., :1, :] cross_products[..., :1, :]
) )
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
norms_sq = (cross_products**2).sum(dim=-1) 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 # Pick only the cross-product with highest squared norm for each input
max_cross_products = self._gather_by_index( max_cross_products = self._gather_by_index(
...@@ -227,9 +230,7 @@ class _SymEig3x3(nn.Module): ...@@ -227,9 +230,7 @@ class _SymEig3x3(nn.Module):
index_shape = list(source.shape) index_shape = list(source.shape)
index_shape[dim] = 1 index_shape[dim] = 1
return source.gather(dim, index.expand(index_shape)).squeeze( # pyre-ignore[16] return source.gather(dim, index.expand(index_shape)).squeeze(dim)
dim
)
def _get_uv(self, w: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]: def _get_uv(self, w: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
""" """
...@@ -243,7 +244,7 @@ class _SymEig3x3(nn.Module): ...@@ -243,7 +244,7 @@ class _SymEig3x3(nn.Module):
Tuple of U and V unit-length vector tensors of shape (..., 3) 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) rotation_2d = self._rotations_3d[min_idx].to(w)
u = F.normalize((rotation_2d @ w[..., None])[..., 0], dim=-1) u = F.normalize((rotation_2d @ w[..., None])[..., 0], dim=-1)
......
...@@ -140,7 +140,6 @@ def compute_extrinsic_matrix( ...@@ -140,7 +140,6 @@ def compute_extrinsic_matrix(
# rotates the model 90 degrees about the x axis. To compensate for this quirk we # rotates the model 90 degrees about the x axis. To compensate for this quirk we
# roll that rotation into the extrinsic matrix here # 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]]) 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)) RT = RT.mm(rot.to(RT))
return RT return RT
...@@ -180,6 +179,7 @@ def read_binvox_coords( ...@@ -180,6 +179,7 @@ def read_binvox_coords(
size, translation, scale = _read_binvox_header(f) size, translation, scale = _read_binvox_header(f)
storage = torch.ByteStorage.from_buffer(f.read()) storage = torch.ByteStorage.from_buffer(f.read())
data = torch.tensor([], dtype=torch.uint8) data = torch.tensor([], dtype=torch.uint8)
# pyre-fixme[28]: Unexpected keyword argument `source`.
data.set_(source=storage) data.set_(source=storage)
vals, counts = data[::2], data[1::2] vals, counts = data[::2], data[1::2]
idxs = _compute_idxs(vals, counts) idxs = _compute_idxs(vals, counts)
......
...@@ -227,6 +227,8 @@ class ShapeNetBase(torch.utils.data.Dataset): # pragma: no cover ...@@ -227,6 +227,8 @@ class ShapeNetBase(torch.utils.data.Dataset): # pragma: no cover
sampled_idxs = self._sample_idxs_from_category( sampled_idxs = self._sample_idxs_from_category(
sample_num=sample_num, category=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_tensor = torch.cat((idxs_tensor, sampled_idxs))
idxs = idxs_tensor.tolist() idxs = idxs_tensor.tolist()
# Check if the indices are valid if idxs are supplied. # Check if the indices are valid if idxs are supplied.
...@@ -283,4 +285,5 @@ class ShapeNetBase(torch.utils.data.Dataset): # pragma: no cover ...@@ -283,4 +285,5 @@ class ShapeNetBase(torch.utils.data.Dataset): # pragma: no cover
"category " + category if category is not None else "all categories", "category " + category if category is not None else "all categories",
) )
warnings.warn(msg) warnings.warn(msg)
# pyre-fixme[7]: Expected `List[int]` but got `Tensor`.
return sampled_idxs return sampled_idxs
...@@ -640,14 +640,16 @@ class JsonIndexDataset(DatasetBase, ReplaceableBase): ...@@ -640,14 +640,16 @@ class JsonIndexDataset(DatasetBase, ReplaceableBase):
) )
imre = torch.nn.functional.interpolate( imre = torch.nn.functional.interpolate(
torch.from_numpy(image)[None], torch.from_numpy(image)[None],
# pyre-ignore[6]
scale_factor=minscale, scale_factor=minscale,
mode=mode, mode=mode,
align_corners=False if mode == "bilinear" else None, align_corners=False if mode == "bilinear" else None,
recompute_scale_factor=True, recompute_scale_factor=True,
)[0] )[0]
# pyre-fixme[19]: Expected 1 positional argument.
imre_ = torch.zeros(image.shape[0], self.image_height, self.image_width) imre_ = torch.zeros(image.shape[0], self.image_height, self.image_width)
imre_[:, 0 : imre.shape[1], 0 : imre.shape[2]] = imre 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 = torch.zeros(1, self.image_height, self.image_width)
mask[:, 0 : imre.shape[1] - 1, 0 : imre.shape[2] - 1] = 1.0 mask[:, 0 : imre.shape[1] - 1, 0 : imre.shape[2] - 1] = 1.0
return imre_, minscale, mask return imre_, minscale, mask
......
...@@ -23,6 +23,7 @@ def is_known_frame( ...@@ -23,6 +23,7 @@ def is_known_frame(
Given a list `frame_type` of frame types in a batch, return a tensor 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. of boolean flags expressing whether the corresponding frame is a known frame.
""" """
# pyre-fixme[7]: Expected `BoolTensor` but got `Tensor`.
return torch.tensor( return torch.tensor(
[ft.endswith(DATASET_TYPE_KNOWN) for ft in frame_type], [ft.endswith(DATASET_TYPE_KNOWN) for ft in frame_type],
dtype=torch.bool, dtype=torch.bool,
...@@ -37,6 +38,7 @@ def is_train_frame( ...@@ -37,6 +38,7 @@ def is_train_frame(
Given a list `frame_type` of frame types in a batch, return a tensor 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. of boolean flags expressing whether the corresponding frame is a training frame.
""" """
# pyre-fixme[7]: Expected `BoolTensor` but got `Tensor`.
return torch.tensor( return torch.tensor(
[ft.startswith(DATASET_TYPE_TRAIN) for ft in frame_type], [ft.startswith(DATASET_TYPE_TRAIN) for ft in frame_type],
dtype=torch.bool, dtype=torch.bool,
......
...@@ -205,11 +205,7 @@ def eval_batch( ...@@ -205,11 +205,7 @@ def eval_batch(
imode = "bilinear" if k == "image_render" else "nearest" imode = "bilinear" if k == "image_render" else "nearest"
cloned_render[k] = ( cloned_render[k] = (
# pyre-fixme[6]: For 2nd param expected `Optional[int]` but got F.interpolate(field[:1], size=image_resol, mode=imode).detach().clone()
# `Tuple[Any, ...]`.
F.interpolate(field[:1], size=image_resol, mode=imode)
.detach()
.clone()
) )
frame_data = copy.deepcopy(frame_data) frame_data = copy.deepcopy(frame_data)
...@@ -408,7 +404,6 @@ def _reduce_camera_iou_overlap(ious: torch.Tensor, topk: int = 2) -> torch.Tenso ...@@ -408,7 +404,6 @@ def _reduce_camera_iou_overlap(ious: torch.Tensor, topk: int = 2) -> torch.Tenso
Returns: Returns:
single-element Tensor single-element Tensor
""" """
# pyre-ignore[16] topk not recognized
return ious.topk(k=min(topk, len(ious) - 1)).values.mean() return ious.topk(k=min(topk, len(ious) - 1)).values.mean()
......
...@@ -99,6 +99,8 @@ class Autodecoder(Configurable, torch.nn.Module): ...@@ -99,6 +99,8 @@ class Autodecoder(Configurable, torch.nn.Module):
if isinstance(x[0], str): if isinstance(x[0], str):
try: try:
# pyre-fixme[9]: x has type `Union[List[str], LongTensor]`; used as
# `Tensor`.
x = torch.tensor( x = torch.tensor(
# pyre-ignore[29] # pyre-ignore[29]
[self._sequence_map[elem] for elem in x], [self._sequence_map[elem] for elem in x],
......
...@@ -169,8 +169,6 @@ class ResNetFeatureExtractor(FeatureExtractorBase): ...@@ -169,8 +169,6 @@ class ResNetFeatureExtractor(FeatureExtractorBase):
if self.image_rescale != 1.0 and imgs_input is not None: if self.image_rescale != 1.0 and imgs_input is not None:
imgs_resized = Fu.interpolate( imgs_resized = Fu.interpolate(
imgs_input, imgs_input,
# pyre-fixme[6]: For 2nd param expected `Optional[List[float]]` but
# got `float`.
scale_factor=self.image_rescale, scale_factor=self.image_rescale,
mode="bilinear", mode="bilinear",
) )
......
...@@ -103,7 +103,11 @@ class IdrFeatureField(ImplicitFunctionBase, torch.nn.Module): ...@@ -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 self.embed_fn is None and fun_viewpool is None and global_code is None
): ):
return torch.tensor( 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) ).view(0, self.out_dim)
embedding = None embedding = None
...@@ -128,6 +132,7 @@ class IdrFeatureField(ImplicitFunctionBase, torch.nn.Module): ...@@ -128,6 +132,7 @@ class IdrFeatureField(ImplicitFunctionBase, torch.nn.Module):
) )
x = embedding x = embedding
# pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C._TensorBase.__s...
for layer_idx in range(self.num_layers - 1): for layer_idx in range(self.num_layers - 1):
if layer_idx in self.skip_in: if layer_idx in self.skip_in:
x = torch.cat([x, embedding], dim=-1) / 2**0.5 x = torch.cat([x, embedding], dim=-1) / 2**0.5
...@@ -135,6 +140,7 @@ class IdrFeatureField(ImplicitFunctionBase, torch.nn.Module): ...@@ -135,6 +140,7 @@ class IdrFeatureField(ImplicitFunctionBase, torch.nn.Module):
# pyre-fixme[29]: `Union[torch.Tensor, torch.nn.Module]` is not a function. # pyre-fixme[29]: `Union[torch.Tensor, torch.nn.Module]` is not a function.
x = self.linear_layers[layer_idx](x) x = self.linear_layers[layer_idx](x)
# pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C._TensorBase...
if layer_idx < self.num_layers - 2: if layer_idx < self.num_layers - 2:
# pyre-fixme[29]: `Union[torch.Tensor, torch.nn.Module]` is not a function. # pyre-fixme[29]: `Union[torch.Tensor, torch.nn.Module]` is not a function.
x = self.softplus(x) x = self.softplus(x)
......
...@@ -406,6 +406,8 @@ class TransformerWithInputSkips(torch.nn.Module): ...@@ -406,6 +406,8 @@ class TransformerWithInputSkips(torch.nn.Module):
self.last = torch.nn.Linear(dimout, output_dim) self.last = torch.nn.Linear(dimout, output_dim)
_xavier_init(self.last) _xavier_init(self.last)
# pyre-fixme[8]: Attribute has type `Tuple[ModuleList, ModuleList]`; used as
# `ModuleList`.
self.layers_pool, self.layers_ray = ( self.layers_pool, self.layers_ray = (
torch.nn.ModuleList(layers_pool), torch.nn.ModuleList(layers_pool),
torch.nn.ModuleList(layers_ray), torch.nn.ModuleList(layers_ray),
......
...@@ -93,6 +93,8 @@ class ModelDBIR(ImplicitronModelBase, torch.nn.Module): ...@@ -93,6 +93,8 @@ class ModelDBIR(ImplicitronModelBase, torch.nn.Module):
mask_fg = (fg_probability > 0.5).type_as(image_rgb) mask_fg = (fg_probability > 0.5).type_as(image_rgb)
point_cloud = get_rgbd_point_cloud( 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], camera[is_known_idx],
image_rgb[is_known_idx], image_rgb[is_known_idx],
depth_map[is_known_idx], depth_map[is_known_idx],
...@@ -101,6 +103,8 @@ class ModelDBIR(ImplicitronModelBase, torch.nn.Module): ...@@ -101,6 +103,8 @@ class ModelDBIR(ImplicitronModelBase, torch.nn.Module):
pcl_size = point_cloud.num_points_per_cloud().item() pcl_size = point_cloud.num_points_per_cloud().item()
if (self.max_points > 0) and (pcl_size > self.max_points): 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] prm = torch.randperm(pcl_size)[: self.max_points]
point_cloud = Pointclouds( point_cloud = Pointclouds(
point_cloud.points_padded()[:, prm, :], point_cloud.points_padded()[:, prm, :],
......
...@@ -117,13 +117,7 @@ class LSTMRenderer(BaseRenderer, torch.nn.Module): ...@@ -117,13 +117,7 @@ class LSTMRenderer(BaseRenderer, torch.nn.Module):
msg = ( msg = (
f"{t}: mu={float(signed_distance.mean()):1.2e};" f"{t}: mu={float(signed_distance.mean()):1.2e};"
+ f" std={float(signed_distance.std()):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};" + 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};" + f" std_d={float(ray_bundle_t.lengths.std()):1.2e};"
) )
logger.info(msg) logger.info(msg)
......
...@@ -164,8 +164,6 @@ class AbstractMaskRaySampler(RaySamplerBase, torch.nn.Module): ...@@ -164,8 +164,6 @@ class AbstractMaskRaySampler(RaySamplerBase, torch.nn.Module):
): ):
sample_mask = torch.nn.functional.interpolate( sample_mask = torch.nn.functional.interpolate(
mask, mask,
# pyre-fixme[6]: Expected `Optional[int]` for 2nd param but got
# `List[int]`.
size=[self.image_height, self.image_width], size=[self.image_height, self.image_width],
mode="nearest", mode="nearest",
)[:, 0] )[:, 0]
......
...@@ -123,12 +123,12 @@ class RayTracing(Configurable, nn.Module): ...@@ -123,12 +123,12 @@ class RayTracing(Configurable, nn.Module):
ray_directions = ray_directions.reshape(-1, 3) ray_directions = ray_directions.reshape(-1, 3)
mask_intersect = mask_intersect.reshape(-1) mask_intersect = mask_intersect.reshape(-1)
# pyre-fixme[9]: object_mask has type `BoolTensor`; used as `Tensor`.
object_mask = object_mask.reshape(-1) object_mask = object_mask.reshape(-1)
in_mask = ~network_object_mask & object_mask & ~sampler_mask in_mask = ~network_object_mask & object_mask & ~sampler_mask
out_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 mask_left_out = (in_mask | out_mask) & ~mask_intersect
if ( if (
mask_left_out.sum() > 0 mask_left_out.sum() > 0
...@@ -410,10 +410,17 @@ class RayTracing(Configurable, nn.Module): ...@@ -410,10 +410,17 @@ class RayTracing(Configurable, nn.Module):
if n_p_out > 0: if n_p_out > 0:
out_pts_idx = torch.argmin(sdf_val[p_out_mask, :], -1) out_pts_idx = torch.argmin(sdf_val[p_out_mask, :], -1)
sampler_pts[mask_intersect_idx[p_out_mask]] = points[p_out_mask, :, :][ 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[ 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] ][torch.arange(n_p_out), out_pts_idx]
# Get Network object mask # Get Network object mask
...@@ -434,10 +441,16 @@ class RayTracing(Configurable, nn.Module): ...@@ -434,10 +441,16 @@ class RayTracing(Configurable, nn.Module):
secant_pts secant_pts
] ]
z_low = pts_intervals[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][ 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]] cam_loc_secant = cam_loc.reshape(-1, 3)[mask_intersect_idx[secant_pts]]
ray_directions_secant = ray_directions.reshape((-1, 3))[ ray_directions_secant = ray_directions.reshape((-1, 3))[
...@@ -514,6 +527,7 @@ class RayTracing(Configurable, nn.Module): ...@@ -514,6 +527,7 @@ class RayTracing(Configurable, nn.Module):
mask_max_dis = max_dis[mask].unsqueeze(-1) mask_max_dis = max_dis[mask].unsqueeze(-1)
mask_min_dis = min_dis[mask].unsqueeze(-1) mask_min_dis = min_dis[mask].unsqueeze(-1)
steps = ( 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) steps.unsqueeze(0).repeat(n_mask_points, 1) * (mask_max_dis - mask_min_dis)
+ mask_min_dis + mask_min_dis
) )
...@@ -533,8 +547,13 @@ class RayTracing(Configurable, nn.Module): ...@@ -533,8 +547,13 @@ class RayTracing(Configurable, nn.Module):
mask_sdf_all = torch.cat(mask_sdf_all).reshape(-1, n) mask_sdf_all = torch.cat(mask_sdf_all).reshape(-1, n)
min_vals, min_idx = mask_sdf_all.min(-1) min_vals, min_idx = mask_sdf_all.min(-1)
min_mask_points = mask_points_all.reshape(-1, n, 3)[ 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] min_mask_dist = steps.reshape(-1, n)[torch.arange(0, n_mask_points), min_idx]
return min_mask_points, min_mask_dist return min_mask_points, min_mask_dist
...@@ -553,6 +572,7 @@ def _get_sphere_intersection( ...@@ -553,6 +572,7 @@ def _get_sphere_intersection(
# cam_loc = cam_loc.unsqueeze(-1) # cam_loc = cam_loc.unsqueeze(-1)
# ray_cam_dot = torch.bmm(ray_directions, cam_loc).squeeze() # ray_cam_dot = torch.bmm(ray_directions, cam_loc).squeeze()
ray_cam_dot = (ray_directions * cam_loc).sum(-1) # n_images x n_rays 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 = ray_cam_dot**2 - (cam_loc.norm(2, dim=-1) ** 2 - r**2)
under_sqrt = under_sqrt.reshape(-1) under_sqrt = under_sqrt.reshape(-1)
......
...@@ -132,7 +132,11 @@ class SignedDistanceFunctionRenderer(BaseRenderer, torch.nn.Module): ...@@ -132,7 +132,11 @@ class SignedDistanceFunctionRenderer(BaseRenderer, torch.nn.Module):
eik_bounding_box: float = self.object_bounding_sphere eik_bounding_box: float = self.object_bounding_sphere
n_eik_points = batch_size * num_pixels // 2 n_eik_points = batch_size * num_pixels // 2
eikonal_points = torch.empty( 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) ).uniform_(-eik_bounding_box, eik_bounding_box)
eikonal_pixel_points = points.clone() eikonal_pixel_points = points.clone()
eikonal_pixel_points = eikonal_pixel_points.detach() eikonal_pixel_points = eikonal_pixel_points.detach()
...@@ -196,7 +200,9 @@ class SignedDistanceFunctionRenderer(BaseRenderer, torch.nn.Module): ...@@ -196,7 +200,9 @@ class SignedDistanceFunctionRenderer(BaseRenderer, torch.nn.Module):
pooling_fn=None, # TODO pooling_fn=None, # TODO
) )
mask_full.view(-1, 1)[~surface_mask] = torch.sigmoid( 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 # scatter points with surface_mask
......
...@@ -550,7 +550,6 @@ def _get_ray_dir_dot_prods(camera: CamerasBase, pts: torch.Tensor): ...@@ -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. # torch.Tensor, torch.nn.modules.module.Module]` is not a function.
# pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch.Tensor.permute)[[N... # pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch.Tensor.permute)[[N...
camera_rep.T[:, None], camera_rep.T[:, None],
# pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch.Tensor.permute)[[N...
camera_rep.R.permute(0, 2, 1), camera_rep.R.permute(0, 2, 1),
).reshape(-1, *([1] * (pts.ndim - 2)), 3) ).reshape(-1, *([1] * (pts.ndim - 2)), 3)
# cam_centers_rep = camera_rep.get_camera_center().reshape( # cam_centers_rep = camera_rep.get_camera_center().reshape(
...@@ -649,6 +648,7 @@ def _avgmaxstd_reduction_function( ...@@ -649,6 +648,7 @@ def _avgmaxstd_reduction_function(
x_aggr = torch.cat(pooled_features, dim=-1) x_aggr = torch.cat(pooled_features, dim=-1)
# zero out features that were all masked out # 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) any_active = (w.max(dim=dim, keepdim=True).values > 1e-4).type_as(x_aggr)
x_aggr = x_aggr * any_active[..., None] x_aggr = x_aggr * any_active[..., None]
...@@ -676,6 +676,7 @@ def _std_reduction_function( ...@@ -676,6 +676,7 @@ def _std_reduction_function(
): ):
if mu is None: if mu is None:
mu = _avg_reduction_function(x, w, dim=dim) 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() std = wmean((x - mu) ** 2, w, dim=dim, eps=1e-2).clamp(1e-4).sqrt()
# FIXME: somehow this is extremely heavy in mem? # FIXME: somehow this is extremely heavy in mem?
return std return std
......
...@@ -205,7 +205,11 @@ def handle_seq_id( ...@@ -205,7 +205,11 @@ def handle_seq_id(
if not torch.is_tensor(seq_id): if not torch.is_tensor(seq_id):
if isinstance(seq_id[0], str): if isinstance(seq_id[0], str):
seq_id = [hash(s) for s in seq_id] 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) 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) return seq_id.to(device)
...@@ -287,5 +291,7 @@ def cameras_points_cartesian_product( ...@@ -287,5 +291,7 @@ def cameras_points_cartesian_product(
) )
.reshape(batch_pts * n_cameras) .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] camera_rep = camera[idx_cams]
return camera_rep, pts_rep return camera_rep, pts_rep
...@@ -215,7 +215,6 @@ class BatchLinear(nn.Module): ...@@ -215,7 +215,6 @@ class BatchLinear(nn.Module):
def last_hyper_layer_init(m) -> None: def last_hyper_layer_init(m) -> None:
if type(m) == nn.Linear: if type(m) == nn.Linear:
nn.init.kaiming_normal_(m.weight, a=0.0, nonlinearity="relu", mode="fan_in") 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 m.weight.data *= 1e-1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment