Skip to content

Commit 0eca74f

Browse files
nikhilaravifacebook-github-bot
authored andcommitted
lint fixes
Summary: Ran the linter. TODO: need to update the linter as per D21353065. Reviewed By: bottler Differential Revision: D21362270 fbshipit-source-id: ad0e781de0a29f565ad25c43bc94a19b1828c020
1 parent 0c595dc commit 0eca74f

15 files changed

+73
-57
lines changed

pytorch3d/io/mtl_io.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def make_mesh_texture_atlas(
8080
faces_material_ind = torch.from_numpy(face_material_names == material_name).to(
8181
faces_verts_uvs.device
8282
)
83-
if (faces_material_ind).sum() > 0:
83+
if faces_material_ind.sum() > 0:
8484
# For these faces, update the base color to the
8585
# diffuse material color.
8686
if "diffuse_color" not in props:

pytorch3d/loss/chamfer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ def chamfer_distance(
117117
P2 = y.shape[1]
118118

119119
# Check if inputs are heterogeneous and create a lengths mask.
120-
is_x_heterogeneous = ~(x_lengths == P1).all()
121-
is_y_heterogeneous = ~(y_lengths == P2).all()
120+
is_x_heterogeneous = (x_lengths != P1).any()
121+
is_y_heterogeneous = (y_lengths != P2).any()
122122
x_mask = (
123123
torch.arange(P1, device=x.device)[None] >= x_lengths[:, None]
124124
) # shape [N, P1]

pytorch3d/renderer/mesh/rasterize_meshes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def rasterize_meshes_python(
259259
N = len(meshes)
260260
# Assume only square images.
261261
# TODO(T52813608) extend support for non-square images.
262-
H, W, = image_size, image_size
262+
H, W = image_size, image_size
263263
K = faces_per_pixel
264264
device = meshes.device
265265

@@ -479,7 +479,7 @@ def point_line_distance(p, v0, v1):
479479
if l2 <= kEpsilon:
480480
return (p - v1).dot(p - v1) # v0 == v1
481481

482-
t = (v1v0).dot(p - v0) / l2
482+
t = v1v0.dot(p - v0) / l2
483483
t = torch.clamp(t, min=0.0, max=1.0)
484484
p_proj = v0 + t * v1v0
485485
delta_p = p_proj - p

pytorch3d/renderer/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def convert_to_tensors_and_broadcast(*args, dtype=torch.float32, device: str = "
308308
args_Nd = []
309309
for c in args_1d:
310310
if c.shape[0] != 1 and c.shape[0] != N:
311-
msg = "Got non-broadcastable sizes %r" % (sizes)
311+
msg = "Got non-broadcastable sizes %r" % sizes
312312
raise ValueError(msg)
313313

314314
# Expand broadcast dim and keep non broadcast dims the same size

pytorch3d/structures/meshes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -926,8 +926,8 @@ def _compute_packed(self, refresh: bool = False):
926926
self._num_verts_per_mesh = torch.zeros(
927927
(0,), dtype=torch.int64, device=self.device
928928
)
929-
self._faces_packed = -torch.ones(
930-
(0, 3), dtype=torch.int64, device=self.device
929+
self._faces_packed = -(
930+
torch.ones((0, 3), dtype=torch.int64, device=self.device)
931931
)
932932
self._faces_packed_to_mesh_idx = torch.zeros(
933933
(0,), dtype=torch.int64, device=self.device
@@ -977,8 +977,8 @@ def _compute_edges_packed(self, refresh: bool = False):
977977
return
978978

979979
if self.isempty():
980-
self._edges_packed = -torch.ones(
981-
(0, 2), dtype=torch.int64, device=self.device
980+
self._edges_packed = torch.full(
981+
(0, 2), fill_value=-1, dtype=torch.int64, device=self.device
982982
)
983983
self._edges_packed_to_mesh_idx = torch.zeros(
984984
(0,), dtype=torch.int64, device=self.device

tests/test_blending.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ def test_softmax_rgb_blend(self):
261261
# of the image with surrounding padded values.
262262
N, S, K = 1, 8, 2
263263
device = torch.device("cuda")
264-
pix_to_face = -torch.ones((N, S, S, K), dtype=torch.int64, device=device)
264+
pix_to_face = torch.full(
265+
(N, S, S, K), fill_value=-1, dtype=torch.int64, device=device
266+
)
265267
h = int(S / 2)
266268
pix_to_face_full = torch.randint(
267269
size=(N, h, h, K), low=0, high=100, device=device

tests/test_cameras.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def test_camera_position_from_angles_torch_scalar_grads(self):
203203
+ torch.cos(elev) * torch.cos(azim)
204204
)
205205
grad_elev = (
206-
-torch.sin(elev) * torch.sin(azim)
206+
-(torch.sin(elev)) * torch.sin(azim)
207207
+ torch.cos(elev)
208208
- torch.sin(elev) * torch.cos(azim)
209209
)
@@ -260,7 +260,7 @@ def test_camera_position_from_angles_vectors_mixed_broadcast_grads(self):
260260
+ torch.cos(elev) * torch.cos(azim)
261261
)
262262
grad_elev = (
263-
-torch.sin(elev) * torch.sin(azim)
263+
-(torch.sin(elev)) * torch.sin(azim)
264264
+ torch.cos(elev)
265265
- torch.sin(elev) * torch.cos(azim)
266266
)
@@ -395,8 +395,8 @@ def init_random_cameras(cam_type: CamerasBase, batch_size: int):
395395
cam_params["aspect_ratio"] = torch.rand(batch_size) * 0.5 + 0.5
396396
else:
397397
cam_params["top"] = torch.rand(batch_size) * 0.2 + 0.9
398-
cam_params["bottom"] = -torch.rand(batch_size) * 0.2 - 0.9
399-
cam_params["left"] = -torch.rand(batch_size) * 0.2 - 0.9
398+
cam_params["bottom"] = -(torch.rand(batch_size)) * 0.2 - 0.9
399+
cam_params["left"] = -(torch.rand(batch_size)) * 0.2 - 0.9
400400
cam_params["right"] = torch.rand(batch_size) * 0.2 + 0.9
401401
elif cam_type in (SfMOrthographicCameras, SfMPerspectiveCameras):
402402
cam_params["focal_length"] = torch.rand(batch_size) * 10 + 0.1
@@ -532,7 +532,7 @@ def test_perspective_mixed_inputs_broadcast(self):
532532
P = cameras.get_projection_transform()
533533
vertices = torch.tensor([1, 2, 10], dtype=torch.float32)
534534
z1 = 1.0 # vertices at far clipping plane so z = 1.0
535-
z2 = (20.0 / (20.0 - 1.0) * 10.0 + -(20.0) / (20.0 - 1.0)) / 10.0
535+
z2 = (20.0 / (20.0 - 1.0) * 10.0 + -20.0 / (20.0 - 1.0)) / 10.0
536536
projected_verts = torch.tensor(
537537
[
538538
[np.sqrt(3) / 10.0, 2 * np.sqrt(3) / 10.0, z1],
@@ -660,7 +660,7 @@ def test_orthographic_mixed_inputs_broadcast(self):
660660
cameras = OpenGLOrthographicCameras(znear=near, zfar=far)
661661
P = cameras.get_projection_transform()
662662
vertices = torch.tensor([1.0, 2.0, 10.0], dtype=torch.float32)
663-
z2 = 1.0 / (20.0 - 1.0) * 10.0 + -(1.0) / (20.0 - 1.0)
663+
z2 = 1.0 / (20.0 - 1.0) * 10.0 + -1.0 / (20.0 - 1.0)
664664
projected_verts = torch.tensor(
665665
[[1.0, 2.0, 1.0], [1.0, 2.0, z2]], dtype=torch.float32
666666
)

tests/test_chamfer.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def init_pointclouds(
3535
low = 0 if allow_empty else 1
3636
p1_lengths = torch.randint(low, P1, size=(N,), dtype=torch.int64, device=device)
3737
p2_lengths = torch.randint(low, P2, size=(N,), dtype=torch.int64, device=device)
38+
P1 = p1_lengths.max().item()
39+
P2 = p2_lengths.max().item()
3840
weights = torch.rand((N,), dtype=torch.float32, device=device)
3941

4042
# list of points and normals tensors
@@ -109,9 +111,8 @@ def chamfer_distance_naive_pointclouds(p1, p2, device="cpu"):
109111
torch.arange(P2, device=y.device)[None] >= y_lengths[:, None]
110112
) # shape [N, P2]
111113

112-
is_x_heterogeneous = ~(x_lengths == P1).all()
113-
is_y_heterogeneous = ~(y_lengths == P2).all()
114-
114+
is_x_heterogeneous = (x_lengths != P1).any()
115+
is_y_heterogeneous = (y_lengths != P2).any()
115116
# Only calculate the distances for the points which are not masked
116117
for n in range(N):
117118
for i1 in range(x_lengths[n]):

tests/test_mesh_normal_consistency.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def test_mesh_normal_consistency_simple(self):
180180
# mesh1: normal consistency computation
181181
n0 = (verts1[1] - verts1[2]).cross(verts1[3] - verts1[2])
182182
n1 = (verts1[1] - verts1[2]).cross(verts1[0] - verts1[2])
183-
loss1 = 1.0 - torch.cosine_similarity(n0.view(1, 3), -n1.view(1, 3))
183+
loss1 = 1.0 - torch.cosine_similarity(n0.view(1, 3), -(n1.view(1, 3)))
184184

185185
# mesh2: normal consistency computation
186186
# In the cube mesh, 6 edges are shared with coplanar faces (loss=0),
@@ -193,9 +193,9 @@ def test_mesh_normal_consistency_simple(self):
193193
n2 = (verts3[1] - verts3[2]).cross(verts3[4] - verts3[2])
194194
loss3 = (
195195
3.0
196-
- torch.cosine_similarity(n0.view(1, 3), -n1.view(1, 3))
197-
- torch.cosine_similarity(n0.view(1, 3), -n2.view(1, 3))
198-
- torch.cosine_similarity(n1.view(1, 3), -n2.view(1, 3))
196+
- torch.cosine_similarity(n0.view(1, 3), -(n1.view(1, 3)))
197+
- torch.cosine_similarity(n0.view(1, 3), -(n2.view(1, 3)))
198+
- torch.cosine_similarity(n1.view(1, 3), -(n2.view(1, 3)))
199199
)
200200
loss3 /= 3.0
201201

tests/test_obj_io.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ def test_load_obj_simple(self):
5252
)
5353
self.assertTrue(torch.all(verts == expected_verts))
5454
self.assertTrue(torch.all(faces.verts_idx == expected_faces))
55-
padded_vals = -torch.ones_like(faces.verts_idx)
55+
padded_vals = -(torch.ones_like(faces.verts_idx))
5656
self.assertTrue(torch.all(faces.normals_idx == padded_vals))
5757
self.assertTrue(torch.all(faces.textures_idx == padded_vals))
5858
self.assertTrue(
59-
torch.all(faces.materials_idx == -torch.ones(len(expected_faces)))
59+
torch.all(faces.materials_idx == -(torch.ones(len(expected_faces))))
6060
)
6161
self.assertTrue(normals is None)
6262
self.assertTrue(textures is None)
@@ -124,10 +124,12 @@ def test_load_obj_complex(self):
124124
[[0.749279, 0.501284], [0.999110, 0.501077], [0.999455, 0.750380]],
125125
dtype=torch.float32,
126126
)
127-
expected_faces_normals_idx = -torch.ones_like(expected_faces, dtype=torch.int64)
127+
expected_faces_normals_idx = -(
128+
torch.ones_like(expected_faces, dtype=torch.int64)
129+
)
128130
expected_faces_normals_idx[4, :] = torch.tensor([1, 1, 1], dtype=torch.int64)
129-
expected_faces_textures_idx = -torch.ones_like(
130-
expected_faces, dtype=torch.int64
131+
expected_faces_textures_idx = -(
132+
torch.ones_like(expected_faces, dtype=torch.int64)
131133
)
132134
expected_faces_textures_idx[4, :] = torch.tensor([0, 0, 1], dtype=torch.int64)
133135

@@ -207,7 +209,7 @@ def test_load_obj_textures_only(self):
207209
self.assertClose(expected_textures, textures)
208210
self.assertClose(expected_verts, verts)
209211
self.assertTrue(
210-
torch.all(faces.normals_idx == -torch.ones_like(faces.textures_idx))
212+
torch.all(faces.normals_idx == -(torch.ones_like(faces.textures_idx)))
211213
)
212214
self.assertTrue(normals is None)
213215
self.assertTrue(materials is None)

tests/test_point_mesh_distance.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def test_point_mesh_edge_distance(self):
431431
# Naive implementation: forward & backward
432432
edges_packed = meshes.edges_packed()
433433
edges_list = packed_to_list(edges_packed, meshes.num_edges_per_mesh().tolist())
434-
loss_naive = torch.zeros((N), dtype=torch.float32, device=device)
434+
loss_naive = torch.zeros(N, dtype=torch.float32, device=device)
435435
for i in range(N):
436436
points = pcls.points_list()[i]
437437
verts = meshes.verts_list()[i]
@@ -461,7 +461,7 @@ def test_point_mesh_edge_distance(self):
461461
self.assertClose(loss_op, loss_naive)
462462

463463
# Compare backward pass
464-
rand_val = torch.rand((1)).item()
464+
rand_val = torch.rand(1).item()
465465
grad_dist = torch.tensor(rand_val, dtype=torch.float32, device=device)
466466

467467
loss_naive.backward(grad_dist)
@@ -707,7 +707,7 @@ def test_point_mesh_face_distance(self):
707707
pcls_op = Pointclouds(points_op)
708708

709709
# naive implementation
710-
loss_naive = torch.zeros((N), dtype=torch.float32, device=device)
710+
loss_naive = torch.zeros(N, dtype=torch.float32, device=device)
711711
for i in range(N):
712712
points = pcls.points_list()[i]
713713
verts = meshes.verts_list()[i]
@@ -735,7 +735,7 @@ def test_point_mesh_face_distance(self):
735735
self.assertClose(loss_op, loss_naive)
736736

737737
# Compare backward pass
738-
rand_val = torch.rand((1)).item()
738+
rand_val = torch.rand(1).item()
739739
grad_dist = torch.tensor(rand_val, dtype=torch.float32, device=device)
740740

741741
loss_naive.backward(grad_dist)

tests/test_points_alignment.py

+28-20
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,13 @@ def test_init_transformation(self, batch_size=10):
112112
]
113113

114114
# run full icp
115-
converged, _, Xt, (
116-
R,
117-
T,
118-
s,
119-
), t_hist = points_alignment.iterative_closest_point(
115+
(
116+
converged,
117+
_,
118+
Xt,
119+
(R, T, s),
120+
t_hist,
121+
) = points_alignment.iterative_closest_point(
120122
X,
121123
Y,
122124
estimate_scale=False,
@@ -130,11 +132,13 @@ def test_init_transformation(self, batch_size=10):
130132
t_init = t_hist[min(2, len(t_hist) - 1)]
131133

132134
# rerun the ICP
133-
converged_init, _, Xt_init, (
134-
R_init,
135-
T_init,
136-
s_init,
137-
), t_hist_init = points_alignment.iterative_closest_point(
135+
(
136+
converged_init,
137+
_,
138+
Xt_init,
139+
(R_init, T_init, s_init),
140+
t_hist_init,
141+
) = points_alignment.iterative_closest_point(
138142
X,
139143
Y,
140144
init_transform=t_init,
@@ -182,11 +186,13 @@ def test_heterogenous_inputs(self, batch_size=10):
182186
n_points_Y = Y_pcl.num_points_per_cloud()
183187

184188
# run icp with Pointlouds inputs
185-
_, _, Xt_pcl, (
186-
R_pcl,
187-
T_pcl,
188-
s_pcl,
189-
), _ = points_alignment.iterative_closest_point(
189+
(
190+
_,
191+
_,
192+
Xt_pcl,
193+
(R_pcl, T_pcl, s_pcl),
194+
_,
195+
) = points_alignment.iterative_closest_point(
190196
X_pcl,
191197
Y_pcl,
192198
estimate_scale=estimate_scale,
@@ -263,11 +269,13 @@ def _compare_with_trimesh(
263269
]
264270

265271
# run the icp algorithm
266-
converged, _, _, (
267-
R_ours,
268-
T_ours,
269-
s_ours,
270-
), _ = points_alignment.iterative_closest_point(
272+
(
273+
converged,
274+
_,
275+
_,
276+
(R_ours, T_ours, s_ours),
277+
_,
278+
) = points_alignment.iterative_closest_point(
271279
X,
272280
Y,
273281
estimate_scale=estimate_scale,

tests/test_points_normals.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ def test_pcl_normals(self, batch_size=3, num_points=300, neighborhood_size=50):
7474

7575
# check for both disambiguation options
7676
for disambiguate_directions in (True, False):
77-
curvatures, local_coord_frames = estimate_pointcloud_local_coord_frames(
77+
(
78+
curvatures,
79+
local_coord_frames,
80+
) = estimate_pointcloud_local_coord_frames(
7881
pcl,
7982
neighborhood_size=neighborhood_size,
8083
disambiguate_directions=disambiguate_directions,

tests/test_rasterize_meshes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ def _test_back_face_culling(self, rasterize_meshes_fn, device, bin_size):
448448
], dtype=torch.int64, device=device)
449449
# fmt: on
450450

451-
pix_to_face_padded = -torch.ones_like(pix_to_face_frontface)
451+
pix_to_face_padded = -(torch.ones_like(pix_to_face_frontface))
452452
# Run with and without culling
453453
# Without culling, for k=0, the front face (i.e. face 2) is
454454
# rasterized and for k=1, the back face (i.e. face 3) is

tests/test_sample_points_from_meshes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_sampling_output(self):
9595
x, y, z = samples[1, :].unbind(1)
9696
radius = torch.sqrt(x ** 2 + y ** 2 + z ** 2)
9797

98-
self.assertClose(radius, torch.ones((num_samples)))
98+
self.assertClose(radius, torch.ones(num_samples))
9999

100100
# Pyramid: points shoudl lie on one of the faces.
101101
pyramid_verts = samples[2, :]

0 commit comments

Comments
 (0)