Skip to content

Commit 7978ffd

Browse files
Pyre Bot Jrfacebook-github-bot
Pyre Bot Jr
authored andcommitted
suppress errors in vision/fair/pytorch3d
Differential Revision: D37172764 fbshipit-source-id: a2ec367e56de2781a17f5e708eb5832ec9d7e6b4
1 parent ea4f326 commit 7978ffd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+188
-80
lines changed

Diff for: pytorch3d/common/compat.py

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def solve(A: torch.Tensor, B: torch.Tensor) -> torch.Tensor: # pragma: no cover
2323
# PyTorch version >= 1.8.0
2424
return torch.linalg.solve(A, B)
2525

26+
# pyre-fixme[16]: `Tuple` has no attribute `solution`.
2627
return torch.solve(B, A).solution
2728

2829

@@ -67,9 +68,14 @@ def meshgrid_ij(
6768
Like torch.meshgrid was before PyTorch 1.10.0, i.e. with indexing set to ij
6869
"""
6970
if (
71+
# pyre-fixme[16]: Callable `meshgrid` has no attribute `__kwdefaults__`.
7072
torch.meshgrid.__kwdefaults__ is not None
7173
and "indexing" in torch.meshgrid.__kwdefaults__
7274
):
7375
# PyTorch >= 1.10.0
76+
# pyre-fixme[6]: For 1st param expected `Union[List[Tensor], Tensor]` but
77+
# got `Union[Sequence[Tensor], Tensor]`.
7478
return torch.meshgrid(*A, indexing="ij")
79+
# pyre-fixme[6]: For 1st param expected `Union[List[Tensor], Tensor]` but got
80+
# `Union[Sequence[Tensor], Tensor]`.
7581
return torch.meshgrid(*A)

Diff for: pytorch3d/common/datatypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def make_device(device: Device) -> torch.device:
2626
A matching torch.device object
2727
"""
2828
device = torch.device(device) if isinstance(device, str) else device
29-
if device.type == "cuda" and device.index is None: # pyre-ignore[16]
29+
if device.type == "cuda" and device.index is None:
3030
# If cuda but with no index, then the current cuda device is indicated.
3131
# In that case, we fix to that device
3232
device = torch.device(f"cuda:{torch.cuda.current_device()}")

Diff for: pytorch3d/common/workaround/symeig3x3.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ def forward(
7575
if inputs.shape[-2:] != (3, 3):
7676
raise ValueError("Only inputs of shape (..., 3, 3) are supported.")
7777

78-
inputs_diag = inputs.diagonal(dim1=-2, dim2=-1) # pyre-ignore[16]
78+
inputs_diag = inputs.diagonal(dim1=-2, dim2=-1)
7979
inputs_trace = inputs_diag.sum(-1)
8080
q = inputs_trace / 3.0
8181

8282
# Calculate squared sum of elements outside the main diagonal / 2
83+
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
8384
p1 = ((inputs**2).sum(dim=(-1, -2)) - (inputs_diag**2).sum(-1)) / 2
85+
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
8486
p2 = ((inputs_diag - q[..., None]) ** 2).sum(dim=-1) + 2.0 * p1.clamp(self._eps)
8587

8688
p = torch.sqrt(p2 / 6.0)
@@ -195,8 +197,9 @@ def _get_ev0(self, char_poly: torch.Tensor) -> torch.Tensor:
195197
cross_products[..., :1, :]
196198
)
197199

200+
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
198201
norms_sq = (cross_products**2).sum(dim=-1)
199-
max_norms_index = norms_sq.argmax(dim=-1) # pyre-ignore[16]
202+
max_norms_index = norms_sq.argmax(dim=-1)
200203

201204
# Pick only the cross-product with highest squared norm for each input
202205
max_cross_products = self._gather_by_index(
@@ -227,9 +230,7 @@ def _gather_by_index(
227230
index_shape = list(source.shape)
228231
index_shape[dim] = 1
229232

230-
return source.gather(dim, index.expand(index_shape)).squeeze( # pyre-ignore[16]
231-
dim
232-
)
233+
return source.gather(dim, index.expand(index_shape)).squeeze(dim)
233234

234235
def _get_uv(self, w: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
235236
"""
@@ -243,7 +244,7 @@ def _get_uv(self, w: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
243244
Tuple of U and V unit-length vector tensors of shape (..., 3)
244245
"""
245246

246-
min_idx = w.abs().argmin(dim=-1) # pyre-ignore[16]
247+
min_idx = w.abs().argmin(dim=-1)
247248
rotation_2d = self._rotations_3d[min_idx].to(w)
248249

249250
u = F.normalize((rotation_2d @ w[..., None])[..., 0], dim=-1)

Diff for: pytorch3d/datasets/r2n2/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ def compute_extrinsic_matrix(
140140
# rotates the model 90 degrees about the x axis. To compensate for this quirk we
141141
# roll that rotation into the extrinsic matrix here
142142
rot = torch.tensor([[1, 0, 0, 0], [0, 0, -1, 0], [0, 1, 0, 0], [0, 0, 0, 1]])
143-
# pyre-fixme[16]: `Tensor` has no attribute `mm`.
144143
RT = RT.mm(rot.to(RT))
145144

146145
return RT
@@ -180,6 +179,7 @@ def read_binvox_coords(
180179
size, translation, scale = _read_binvox_header(f)
181180
storage = torch.ByteStorage.from_buffer(f.read())
182181
data = torch.tensor([], dtype=torch.uint8)
182+
# pyre-fixme[28]: Unexpected keyword argument `source`.
183183
data.set_(source=storage)
184184
vals, counts = data[::2], data[1::2]
185185
idxs = _compute_idxs(vals, counts)

Diff for: pytorch3d/datasets/shapenet_base.py

+3
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ def _handle_render_inputs(
227227
sampled_idxs = self._sample_idxs_from_category(
228228
sample_num=sample_num, category=category
229229
)
230+
# pyre-fixme[6]: For 1st param expected `Union[List[Tensor],
231+
# typing.Tuple[Tensor, ...]]` but got `Tuple[Tensor, List[int]]`.
230232
idxs_tensor = torch.cat((idxs_tensor, sampled_idxs))
231233
idxs = idxs_tensor.tolist()
232234
# Check if the indices are valid if idxs are supplied.
@@ -283,4 +285,5 @@ def _sample_idxs_from_category(
283285
"category " + category if category is not None else "all categories",
284286
)
285287
warnings.warn(msg)
288+
# pyre-fixme[7]: Expected `List[int]` but got `Tensor`.
286289
return sampled_idxs

Diff for: pytorch3d/implicitron/dataset/json_index_dataset.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -640,14 +640,16 @@ def _resize_image(
640640
)
641641
imre = torch.nn.functional.interpolate(
642642
torch.from_numpy(image)[None],
643-
# pyre-ignore[6]
644643
scale_factor=minscale,
645644
mode=mode,
646645
align_corners=False if mode == "bilinear" else None,
647646
recompute_scale_factor=True,
648647
)[0]
648+
# pyre-fixme[19]: Expected 1 positional argument.
649649
imre_ = torch.zeros(image.shape[0], self.image_height, self.image_width)
650650
imre_[:, 0 : imre.shape[1], 0 : imre.shape[2]] = imre
651+
# pyre-fixme[6]: For 2nd param expected `int` but got `Optional[int]`.
652+
# pyre-fixme[6]: For 3rd param expected `int` but got `Optional[int]`.
651653
mask = torch.zeros(1, self.image_height, self.image_width)
652654
mask[:, 0 : imre.shape[1] - 1, 0 : imre.shape[2] - 1] = 1.0
653655
return imre_, minscale, mask

Diff for: pytorch3d/implicitron/dataset/utils.py

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def is_known_frame(
2323
Given a list `frame_type` of frame types in a batch, return a tensor
2424
of boolean flags expressing whether the corresponding frame is a known frame.
2525
"""
26+
# pyre-fixme[7]: Expected `BoolTensor` but got `Tensor`.
2627
return torch.tensor(
2728
[ft.endswith(DATASET_TYPE_KNOWN) for ft in frame_type],
2829
dtype=torch.bool,
@@ -37,6 +38,7 @@ def is_train_frame(
3738
Given a list `frame_type` of frame types in a batch, return a tensor
3839
of boolean flags expressing whether the corresponding frame is a training frame.
3940
"""
41+
# pyre-fixme[7]: Expected `BoolTensor` but got `Tensor`.
4042
return torch.tensor(
4143
[ft.startswith(DATASET_TYPE_TRAIN) for ft in frame_type],
4244
dtype=torch.bool,

Diff for: pytorch3d/implicitron/evaluation/evaluate_new_view_synthesis.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,7 @@ def eval_batch(
205205

206206
imode = "bilinear" if k == "image_render" else "nearest"
207207
cloned_render[k] = (
208-
# pyre-fixme[6]: For 2nd param expected `Optional[int]` but got
209-
# `Tuple[Any, ...]`.
210-
F.interpolate(field[:1], size=image_resol, mode=imode)
211-
.detach()
212-
.clone()
208+
F.interpolate(field[:1], size=image_resol, mode=imode).detach().clone()
213209
)
214210

215211
frame_data = copy.deepcopy(frame_data)
@@ -408,7 +404,6 @@ def _reduce_camera_iou_overlap(ious: torch.Tensor, topk: int = 2) -> torch.Tenso
408404
Returns:
409405
single-element Tensor
410406
"""
411-
# pyre-ignore[16] topk not recognized
412407
return ious.topk(k=min(topk, len(ious) - 1)).values.mean()
413408

414409

Diff for: pytorch3d/implicitron/models/autodecoder.py

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ def forward(self, x: Union[torch.LongTensor, List[str]]) -> Optional[torch.Tenso
9999

100100
if isinstance(x[0], str):
101101
try:
102+
# pyre-fixme[9]: x has type `Union[List[str], LongTensor]`; used as
103+
# `Tensor`.
102104
x = torch.tensor(
103105
# pyre-ignore[29]
104106
[self._sequence_map[elem] for elem in x],

Diff for: pytorch3d/implicitron/models/feature_extractor/resnet_feature_extractor.py

-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ def forward(
169169
if self.image_rescale != 1.0 and imgs_input is not None:
170170
imgs_resized = Fu.interpolate(
171171
imgs_input,
172-
# pyre-fixme[6]: For 2nd param expected `Optional[List[float]]` but
173-
# got `float`.
174172
scale_factor=self.image_rescale,
175173
mode="bilinear",
176174
)

Diff for: pytorch3d/implicitron/models/implicit_function/idr_feature_field.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ def forward(
103103
self.embed_fn is None and fun_viewpool is None and global_code is None
104104
):
105105
return torch.tensor(
106-
[], device=rays_points_world.device, dtype=rays_points_world.dtype
106+
[],
107+
device=rays_points_world.device,
108+
dtype=rays_points_world.dtype
109+
# pyre-fixme[6]: For 2nd param expected `int` but got `Union[Module,
110+
# Tensor]`.
107111
).view(0, self.out_dim)
108112

109113
embedding = None
@@ -128,13 +132,15 @@ def forward(
128132
)
129133

130134
x = embedding
135+
# pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C._TensorBase.__s...
131136
for layer_idx in range(self.num_layers - 1):
132137
if layer_idx in self.skip_in:
133138
x = torch.cat([x, embedding], dim=-1) / 2**0.5
134139

135140
# pyre-fixme[29]: `Union[torch.Tensor, torch.nn.Module]` is not a function.
136141
x = self.linear_layers[layer_idx](x)
137142

143+
# pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C._TensorBase...
138144
if layer_idx < self.num_layers - 2:
139145
# pyre-fixme[29]: `Union[torch.Tensor, torch.nn.Module]` is not a function.
140146
x = self.softplus(x)

Diff for: pytorch3d/implicitron/models/implicit_function/neural_radiance_field.py

+2
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ def __init__(
406406
self.last = torch.nn.Linear(dimout, output_dim)
407407
_xavier_init(self.last)
408408

409+
# pyre-fixme[8]: Attribute has type `Tuple[ModuleList, ModuleList]`; used as
410+
# `ModuleList`.
409411
self.layers_pool, self.layers_ray = (
410412
torch.nn.ModuleList(layers_pool),
411413
torch.nn.ModuleList(layers_ray),

Diff for: pytorch3d/implicitron/models/model_dbir.py

+4
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ def forward(
9393
mask_fg = (fg_probability > 0.5).type_as(image_rgb)
9494

9595
point_cloud = get_rgbd_point_cloud(
96+
# pyre-fixme[6]: For 1st param expected `Union[List[int], int,
97+
# LongTensor]` but got `Tensor`.
9698
camera[is_known_idx],
9799
image_rgb[is_known_idx],
98100
depth_map[is_known_idx],
@@ -101,6 +103,8 @@ def forward(
101103

102104
pcl_size = point_cloud.num_points_per_cloud().item()
103105
if (self.max_points > 0) and (pcl_size > self.max_points):
106+
# pyre-fixme[6]: For 1st param expected `int` but got `Union[bool,
107+
# float, int]`.
104108
prm = torch.randperm(pcl_size)[: self.max_points]
105109
point_cloud = Pointclouds(
106110
point_cloud.points_padded()[:, prm, :],

Diff for: pytorch3d/implicitron/models/renderer/lstm_renderer.py

-6
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,7 @@ def forward(
117117
msg = (
118118
f"{t}: mu={float(signed_distance.mean()):1.2e};"
119119
+ f" std={float(signed_distance.std()):1.2e};"
120-
# pyre-fixme[6]: Expected `Union[bytearray, bytes, str,
121-
# typing.SupportsFloat, typing_extensions.SupportsIndex]` for 1st
122-
# param but got `Tensor`.
123120
+ f" mu_d={float(ray_bundle_t.lengths.mean()):1.2e};"
124-
# pyre-fixme[6]: Expected `Union[bytearray, bytes, str,
125-
# typing.SupportsFloat, typing_extensions.SupportsIndex]` for 1st
126-
# param but got `Tensor`.
127121
+ f" std_d={float(ray_bundle_t.lengths.std()):1.2e};"
128122
)
129123
logger.info(msg)

Diff for: pytorch3d/implicitron/models/renderer/ray_sampler.py

-2
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ def forward(
164164
):
165165
sample_mask = torch.nn.functional.interpolate(
166166
mask,
167-
# pyre-fixme[6]: Expected `Optional[int]` for 2nd param but got
168-
# `List[int]`.
169167
size=[self.image_height, self.image_width],
170168
mode="nearest",
171169
)[:, 0]

Diff for: pytorch3d/implicitron/models/renderer/ray_tracing.py

+26-6
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ def forward(
123123

124124
ray_directions = ray_directions.reshape(-1, 3)
125125
mask_intersect = mask_intersect.reshape(-1)
126+
# pyre-fixme[9]: object_mask has type `BoolTensor`; used as `Tensor`.
126127
object_mask = object_mask.reshape(-1)
127128

128129
in_mask = ~network_object_mask & object_mask & ~sampler_mask
129130
out_mask = ~object_mask & ~sampler_mask
130131

131-
# pyre-fixme[16]: `Tensor` has no attribute `__invert__`.
132132
mask_left_out = (in_mask | out_mask) & ~mask_intersect
133133
if (
134134
mask_left_out.sum() > 0
@@ -410,10 +410,17 @@ def ray_sampler(
410410
if n_p_out > 0:
411411
out_pts_idx = torch.argmin(sdf_val[p_out_mask, :], -1)
412412
sampler_pts[mask_intersect_idx[p_out_mask]] = points[p_out_mask, :, :][
413-
torch.arange(n_p_out), out_pts_idx, :
413+
# pyre-fixme[6]: For 1st param expected `Union[bool, float, int]`
414+
# but got `Tensor`.
415+
torch.arange(n_p_out),
416+
out_pts_idx,
417+
:,
414418
]
415419
sampler_dists[mask_intersect_idx[p_out_mask]] = pts_intervals[
416-
p_out_mask, :
420+
p_out_mask,
421+
:
422+
# pyre-fixme[6]: For 1st param expected `Union[bool, float, int]` but
423+
# got `Tensor`.
417424
][torch.arange(n_p_out), out_pts_idx]
418425

419426
# Get Network object mask
@@ -434,10 +441,16 @@ def ray_sampler(
434441
secant_pts
435442
]
436443
z_low = pts_intervals[secant_pts][
437-
torch.arange(n_secant_pts), sampler_pts_ind[secant_pts] - 1
444+
# pyre-fixme[6]: For 1st param expected `Union[bool, float, int]`
445+
# but got `Tensor`.
446+
torch.arange(n_secant_pts),
447+
sampler_pts_ind[secant_pts] - 1,
438448
]
439449
sdf_low = sdf_val[secant_pts][
440-
torch.arange(n_secant_pts), sampler_pts_ind[secant_pts] - 1
450+
# pyre-fixme[6]: For 1st param expected `Union[bool, float, int]`
451+
# but got `Tensor`.
452+
torch.arange(n_secant_pts),
453+
sampler_pts_ind[secant_pts] - 1,
441454
]
442455
cam_loc_secant = cam_loc.reshape(-1, 3)[mask_intersect_idx[secant_pts]]
443456
ray_directions_secant = ray_directions.reshape((-1, 3))[
@@ -514,6 +527,7 @@ def minimal_sdf_points(
514527
mask_max_dis = max_dis[mask].unsqueeze(-1)
515528
mask_min_dis = min_dis[mask].unsqueeze(-1)
516529
steps = (
530+
# pyre-fixme[6]: For 1st param expected `int` but got `Tensor`.
517531
steps.unsqueeze(0).repeat(n_mask_points, 1) * (mask_max_dis - mask_min_dis)
518532
+ mask_min_dis
519533
)
@@ -533,8 +547,13 @@ def minimal_sdf_points(
533547
mask_sdf_all = torch.cat(mask_sdf_all).reshape(-1, n)
534548
min_vals, min_idx = mask_sdf_all.min(-1)
535549
min_mask_points = mask_points_all.reshape(-1, n, 3)[
536-
torch.arange(0, n_mask_points), min_idx
550+
# pyre-fixme[6]: For 2nd param expected `Union[bool, float, int]` but
551+
# got `Tensor`.
552+
torch.arange(0, n_mask_points),
553+
min_idx,
537554
]
555+
# pyre-fixme[6]: For 2nd param expected `Union[bool, float, int]` but got
556+
# `Tensor`.
538557
min_mask_dist = steps.reshape(-1, n)[torch.arange(0, n_mask_points), min_idx]
539558

540559
return min_mask_points, min_mask_dist
@@ -553,6 +572,7 @@ def _get_sphere_intersection(
553572
# cam_loc = cam_loc.unsqueeze(-1)
554573
# ray_cam_dot = torch.bmm(ray_directions, cam_loc).squeeze()
555574
ray_cam_dot = (ray_directions * cam_loc).sum(-1) # n_images x n_rays
575+
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
556576
under_sqrt = ray_cam_dot**2 - (cam_loc.norm(2, dim=-1) ** 2 - r**2)
557577

558578
under_sqrt = under_sqrt.reshape(-1)

Diff for: pytorch3d/implicitron/models/renderer/sdf_renderer.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ def forward(
132132
eik_bounding_box: float = self.object_bounding_sphere
133133
n_eik_points = batch_size * num_pixels // 2
134134
eikonal_points = torch.empty(
135-
n_eik_points, 3, device=self._bg_color.device
135+
n_eik_points,
136+
3,
137+
# pyre-fixme[6]: For 3rd param expected `Union[None, str, device]`
138+
# but got `Union[device, Tensor, Module]`.
139+
device=self._bg_color.device,
136140
).uniform_(-eik_bounding_box, eik_bounding_box)
137141
eikonal_pixel_points = points.clone()
138142
eikonal_pixel_points = eikonal_pixel_points.detach()
@@ -196,7 +200,9 @@ def forward(
196200
pooling_fn=None, # TODO
197201
)
198202
mask_full.view(-1, 1)[~surface_mask] = torch.sigmoid(
199-
-self.soft_mask_alpha * sdf_output[~surface_mask]
203+
# pyre-fixme[6]: For 1st param expected `Tensor` but got `float`.
204+
-self.soft_mask_alpha
205+
* sdf_output[~surface_mask]
200206
)
201207

202208
# scatter points with surface_mask

Diff for: pytorch3d/implicitron/models/view_pooler/feature_aggregator.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,6 @@ def _get_ray_dir_dot_prods(camera: CamerasBase, pts: torch.Tensor):
550550
# torch.Tensor, torch.nn.modules.module.Module]` is not a function.
551551
# pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch.Tensor.permute)[[N...
552552
camera_rep.T[:, None],
553-
# pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch.Tensor.permute)[[N...
554553
camera_rep.R.permute(0, 2, 1),
555554
).reshape(-1, *([1] * (pts.ndim - 2)), 3)
556555
# cam_centers_rep = camera_rep.get_camera_center().reshape(
@@ -649,6 +648,7 @@ def _avgmaxstd_reduction_function(
649648
x_aggr = torch.cat(pooled_features, dim=-1)
650649

651650
# zero out features that were all masked out
651+
# pyre-fixme[16]: `bool` has no attribute `type_as`.
652652
any_active = (w.max(dim=dim, keepdim=True).values > 1e-4).type_as(x_aggr)
653653
x_aggr = x_aggr * any_active[..., None]
654654

@@ -676,6 +676,7 @@ def _std_reduction_function(
676676
):
677677
if mu is None:
678678
mu = _avg_reduction_function(x, w, dim=dim)
679+
# pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
679680
std = wmean((x - mu) ** 2, w, dim=dim, eps=1e-2).clamp(1e-4).sqrt()
680681
# FIXME: somehow this is extremely heavy in mem?
681682
return std

0 commit comments

Comments
 (0)