Skip to content

Commit 3da7703

Browse files
amyreesefacebook-github-bot
authored andcommitted
apply Black 2024 style in fbcode (4/16)
Summary: Formats the covered files with pyfmt. paintitblack Reviewed By: aleivag Differential Revision: D54447727 fbshipit-source-id: 8844b1caa08de94d04ac4df3c768dbf8c865fd2f
1 parent f34104c commit 3da7703

31 files changed

+130
-106
lines changed

projects/nerf/nerf/nerf_renderer.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,14 @@ def forward(
343343
# For a full render pass concatenate the output chunks,
344344
# and reshape to image size.
345345
out = {
346-
k: torch.cat(
347-
[ch_o[k] for ch_o in chunk_outputs],
348-
dim=1,
349-
).view(-1, *self._image_size, 3)
350-
if chunk_outputs[0][k] is not None
351-
else None
346+
k: (
347+
torch.cat(
348+
[ch_o[k] for ch_o in chunk_outputs],
349+
dim=1,
350+
).view(-1, *self._image_size, 3)
351+
if chunk_outputs[0][k] is not None
352+
else None
353+
)
352354
for k in ("rgb_fine", "rgb_coarse", "rgb_gt")
353355
}
354356
else:

pytorch3d/implicitron/dataset/frame_data.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,11 @@ def build(
576576
camera_quality_score=safe_as_tensor(
577577
sequence_annotation.viewpoint_quality_score, torch.float
578578
),
579-
point_cloud_quality_score=safe_as_tensor(
580-
point_cloud.quality_score, torch.float
581-
)
582-
if point_cloud is not None
583-
else None,
579+
point_cloud_quality_score=(
580+
safe_as_tensor(point_cloud.quality_score, torch.float)
581+
if point_cloud is not None
582+
else None
583+
),
584584
)
585585

586586
fg_mask_np: Optional[np.ndarray] = None

pytorch3d/implicitron/dataset/json_index_dataset.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ class JsonIndexDataset(DatasetBase, ReplaceableBase):
124124
dimension of the cropping bounding box, relative to box size.
125125
"""
126126

127-
frame_annotations_type: ClassVar[
128-
Type[types.FrameAnnotation]
129-
] = types.FrameAnnotation
127+
frame_annotations_type: ClassVar[Type[types.FrameAnnotation]] = (
128+
types.FrameAnnotation
129+
)
130130

131131
path_manager: Any = None
132132
frame_annotations_file: str = ""

pytorch3d/implicitron/dataset/visualize.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ def get_implicitron_sequence_pointcloud(
8888
frame_data.camera,
8989
frame_data.image_rgb,
9090
frame_data.depth_map,
91-
(cast(torch.Tensor, frame_data.fg_probability) > 0.5).float()
92-
if mask_points and frame_data.fg_probability is not None
93-
else None,
91+
(
92+
(cast(torch.Tensor, frame_data.fg_probability) > 0.5).float()
93+
if mask_points and frame_data.fg_probability is not None
94+
else None
95+
),
9496
)
9597

9698
return point_cloud, frame_data

pytorch3d/implicitron/evaluation/evaluate_new_view_synthesis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ def eval_batch(
282282
image_rgb_masked=image_rgb_masked,
283283
depth_render=cloned_render["depth_render"],
284284
depth_map=frame_data.depth_map,
285-
depth_mask=frame_data.depth_mask[:1]
286-
if frame_data.depth_mask is not None
287-
else None,
285+
depth_mask=(
286+
frame_data.depth_mask[:1] if frame_data.depth_mask is not None else None
287+
),
288288
visdom_env=visualize_visdom_env,
289289
)
290290

pytorch3d/implicitron/models/generic_model.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,11 @@ def forward(
395395
n_targets = (
396396
1
397397
if evaluation_mode == EvaluationMode.EVALUATION
398-
else batch_size
399-
if self.n_train_target_views <= 0
400-
else min(self.n_train_target_views, batch_size)
398+
else (
399+
batch_size
400+
if self.n_train_target_views <= 0
401+
else min(self.n_train_target_views, batch_size)
402+
)
401403
)
402404

403405
# A helper function for selecting n_target first elements from the input
@@ -422,9 +424,12 @@ def safe_slice_targets(
422424
ray_bundle: ImplicitronRayBundle = self.raysampler(
423425
target_cameras,
424426
evaluation_mode,
425-
mask=mask_crop[:n_targets]
426-
if mask_crop is not None and sampling_mode == RenderSamplingMode.MASK_SAMPLE
427-
else None,
427+
mask=(
428+
mask_crop[:n_targets]
429+
if mask_crop is not None
430+
and sampling_mode == RenderSamplingMode.MASK_SAMPLE
431+
else None
432+
),
428433
)
429434

430435
# custom_args hold additional arguments to the implicit function.

pytorch3d/implicitron/models/implicit_function/idr_feature_field.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ def __post_init__(self):
102102
elif self.n_harmonic_functions_xyz >= 0 and layer_idx == 0:
103103
torch.nn.init.constant_(lin.bias, 0.0)
104104
torch.nn.init.constant_(lin.weight[:, 3:], 0.0)
105-
torch.nn.init.normal_(
106-
lin.weight[:, :3], 0.0, 2**0.5 / out_dim**0.5
107-
)
105+
torch.nn.init.normal_(lin.weight[:, :3], 0.0, 2**0.5 / out_dim**0.5)
108106
elif self.n_harmonic_functions_xyz >= 0 and layer_idx in self.skip_in:
109107
torch.nn.init.constant_(lin.bias, 0.0)
110108
torch.nn.init.normal_(lin.weight, 0.0, 2**0.5 / out_dim**0.5)

pytorch3d/implicitron/models/implicit_function/neural_radiance_field.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ def forward(
193193
embeds = create_embeddings_for_implicit_function(
194194
xyz_world=rays_points_world,
195195
# for 2nd param but got `Union[None, torch.Tensor, torch.nn.Module]`.
196-
xyz_embedding_function=self.harmonic_embedding_xyz
197-
if self.input_xyz
198-
else None,
196+
xyz_embedding_function=(
197+
self.harmonic_embedding_xyz if self.input_xyz else None
198+
),
199199
global_code=global_code,
200200
fun_viewpool=fun_viewpool,
201201
xyz_in_camera_coords=self.xyz_ray_dir_in_camera_coords,

pytorch3d/implicitron/models/overfit_model.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,12 @@ def forward(
356356
ray_bundle: ImplicitronRayBundle = self.raysampler(
357357
camera,
358358
evaluation_mode,
359-
mask=mask_crop
360-
if mask_crop is not None and sampling_mode == RenderSamplingMode.MASK_SAMPLE
361-
else None,
359+
mask=(
360+
mask_crop
361+
if mask_crop is not None
362+
and sampling_mode == RenderSamplingMode.MASK_SAMPLE
363+
else None
364+
),
362365
)
363366

364367
inputs_to_be_chunked = {}
@@ -381,10 +384,12 @@ def forward(
381384
frame_timestamp=frame_timestamp,
382385
)
383386
implicit_functions = [
384-
functools.partial(implicit_function, global_code=global_code)
385-
if isinstance(implicit_function, Callable)
386-
else functools.partial(
387-
implicit_function.forward, global_code=global_code
387+
(
388+
functools.partial(implicit_function, global_code=global_code)
389+
if isinstance(implicit_function, Callable)
390+
else functools.partial(
391+
implicit_function.forward, global_code=global_code
392+
)
388393
)
389394
for implicit_function in implicit_functions
390395
]

pytorch3d/implicitron/models/renderer/ray_sampler.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,12 @@ def __post_init__(self):
145145
n_pts_per_ray=n_pts_per_ray_training,
146146
min_depth=0.0,
147147
max_depth=0.0,
148-
n_rays_per_image=self.n_rays_per_image_sampled_from_mask
149-
if self._sampling_mode[EvaluationMode.TRAINING]
150-
== RenderSamplingMode.MASK_SAMPLE
151-
else None,
148+
n_rays_per_image=(
149+
self.n_rays_per_image_sampled_from_mask
150+
if self._sampling_mode[EvaluationMode.TRAINING]
151+
== RenderSamplingMode.MASK_SAMPLE
152+
else None
153+
),
152154
n_rays_total=self.n_rays_total_training,
153155
unit_directions=True,
154156
stratified_sampling=self.stratified_point_sampling_training,
@@ -160,10 +162,12 @@ def __post_init__(self):
160162
n_pts_per_ray=n_pts_per_ray_evaluation,
161163
min_depth=0.0,
162164
max_depth=0.0,
163-
n_rays_per_image=self.n_rays_per_image_sampled_from_mask
164-
if self._sampling_mode[EvaluationMode.EVALUATION]
165-
== RenderSamplingMode.MASK_SAMPLE
166-
else None,
165+
n_rays_per_image=(
166+
self.n_rays_per_image_sampled_from_mask
167+
if self._sampling_mode[EvaluationMode.EVALUATION]
168+
== RenderSamplingMode.MASK_SAMPLE
169+
else None
170+
),
167171
unit_directions=True,
168172
stratified_sampling=self.stratified_point_sampling_evaluation,
169173
)

pytorch3d/implicitron/models/renderer/ray_tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def ray_sampler(
415415
]
416416
sampler_dists[mask_intersect_idx[p_out_mask]] = pts_intervals[
417417
p_out_mask,
418-
:
418+
:,
419419
# pyre-fixme[6]: For 1st param expected `Union[bool, float, int]` but
420420
# got `Tensor`.
421421
][torch.arange(n_p_out), out_pts_idx]

pytorch3d/implicitron/models/renderer/sdf_renderer.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ def __post_init__(
4343

4444
run_auto_creation(self)
4545

46-
self.ray_normal_coloring_network_args[
47-
"feature_vector_size"
48-
] = render_features_dimensions
46+
self.ray_normal_coloring_network_args["feature_vector_size"] = (
47+
render_features_dimensions
48+
)
4949
self._rgb_network = RayNormalColoringNetwork(
5050
**self.ray_normal_coloring_network_args
5151
)
@@ -201,15 +201,15 @@ def forward(
201201
None, :, 0, :
202202
]
203203
normals_full.view(-1, 3)[surface_mask] = normals
204-
render_full.view(-1, self.render_features_dimensions)[
205-
surface_mask
206-
] = self._rgb_network(
207-
features,
208-
differentiable_surface_points[None],
209-
normals,
210-
ray_bundle,
211-
surface_mask[None, :, None],
212-
pooling_fn=None, # TODO
204+
render_full.view(-1, self.render_features_dimensions)[surface_mask] = (
205+
self._rgb_network(
206+
features,
207+
differentiable_surface_points[None],
208+
normals,
209+
ray_bundle,
210+
surface_mask[None, :, None],
211+
pooling_fn=None, # TODO
212+
)
213213
)
214214
mask_full.view(-1, 1)[~surface_mask] = torch.sigmoid(
215215
# pyre-fixme[6]: For 1st param expected `Tensor` but got `float`.

pytorch3d/implicitron/tools/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ class _Registry:
241241
"""
242242

243243
def __init__(self) -> None:
244-
self._mapping: Dict[
245-
Type[ReplaceableBase], Dict[str, Type[ReplaceableBase]]
246-
] = defaultdict(dict)
244+
self._mapping: Dict[Type[ReplaceableBase], Dict[str, Type[ReplaceableBase]]] = (
245+
defaultdict(dict)
246+
)
247247

248248
def register(self, some_class: Type[_X]) -> Type[_X]:
249249
"""

pytorch3d/implicitron/tools/eval_video_trajectory.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,11 @@ def generate_eval_video_cameras(
139139
fit = fit_circle_in_3d(
140140
cam_centers,
141141
angles=angle,
142-
offset=angle.new_tensor(traj_offset_canonical)
143-
if traj_offset_canonical is not None
144-
else None,
142+
offset=(
143+
angle.new_tensor(traj_offset_canonical)
144+
if traj_offset_canonical is not None
145+
else None
146+
),
145147
up=angle.new_tensor(up),
146148
)
147149
traj = fit.generated_points

pytorch3d/implicitron/tools/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ def cat_dataclass(batch, tensor_collator: Callable):
146146
)
147147
elif isinstance(elem_f, collections.abc.Mapping):
148148
collated[f.name] = {
149-
k: tensor_collator([getattr(e, f.name)[k] for e in batch])
150-
if elem_f[k] is not None
151-
else None
149+
k: (
150+
tensor_collator([getattr(e, f.name)[k] for e in batch])
151+
if elem_f[k] is not None
152+
else None
153+
)
152154
for k in elem_f
153155
}
154156
else:

pytorch3d/renderer/fisheyecameras.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def __init__(
8181
device: Device = "cpu",
8282
image_size: Optional[Union[List, Tuple, torch.Tensor]] = None,
8383
) -> None:
84-
8584
"""
8685
8786
Args:

pytorch3d/renderer/mesh/clip.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,9 @@ def convert_clipped_rasterization_to_original_faces(
712712
)
713713

714714
bary_coords_unclipped_subset = bary_coords_unclipped_subset.reshape([N * 3])
715-
bary_coords_unclipped[
716-
faces_to_convert_mask_expanded
717-
] = bary_coords_unclipped_subset
715+
bary_coords_unclipped[faces_to_convert_mask_expanded] = (
716+
bary_coords_unclipped_subset
717+
)
718718

719719
# dists for case 4 faces will be handled in the rasterizer
720720
# so no need to modify them here.

pytorch3d/renderer/mesh/rasterize_meshes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,10 @@ def rasterize_meshes_python( # noqa: C901
605605
# If faces were clipped, map the rasterization result to be in terms of the
606606
# original unclipped faces. This may involve converting barycentric
607607
# coordinates
608-
(face_idxs, bary_coords,) = convert_clipped_rasterization_to_original_faces(
608+
(
609+
face_idxs,
610+
bary_coords,
611+
) = convert_clipped_rasterization_to_original_faces(
609612
face_idxs,
610613
bary_coords,
611614
# pyre-fixme[61]: `clipped_faces` may not be initialized here.

pytorch3d/renderer/opengl/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7+
78
# If we can access EGL, import MeshRasterizerOpenGL.
89
def _can_import_egl_and_pycuda():
910
import os

pytorch3d/renderer/opengl/rasterizer_opengl.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,11 @@ def __call__(
292292
pix_to_face, bary_coord, zbuf = self._rasterize_mesh(
293293
mesh,
294294
image_size,
295-
projection_matrix=projection_matrix[mesh_id]
296-
if projection_matrix.shape[0] > 1
297-
else None,
295+
projection_matrix=(
296+
projection_matrix[mesh_id]
297+
if projection_matrix.shape[0] > 1
298+
else None
299+
),
298300
)
299301
pix_to_faces.append(pix_to_face)
300302
bary_coords.append(bary_coord)

tests/implicitron/test_extending_orm_types.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class ExtendedSqlFrameAnnotation(SqlFrameAnnotation):
6161

6262

6363
class ExtendedSqlIndexDataset(SqlIndexDataset):
64-
frame_annotations_type: ClassVar[
65-
Type[SqlFrameAnnotation]
66-
] = ExtendedSqlFrameAnnotation
64+
frame_annotations_type: ClassVar[Type[SqlFrameAnnotation]] = (
65+
ExtendedSqlFrameAnnotation
66+
)
6767

6868

6969
class CanineFrameData(FrameData):
@@ -96,9 +96,9 @@ def build(
9696

9797

9898
class CanineSqlIndexDataset(SqlIndexDataset):
99-
frame_annotations_type: ClassVar[
100-
Type[SqlFrameAnnotation]
101-
] = ExtendedSqlFrameAnnotation
99+
frame_annotations_type: ClassVar[Type[SqlFrameAnnotation]] = (
100+
ExtendedSqlFrameAnnotation
101+
)
102102

103103
frame_data_builder_class_type: str = "CanineFrameDataBuilder"
104104

tests/implicitron/test_frame_data_builder.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ def setUp(self):
8585
camera_quality_score=safe_as_tensor(
8686
self.seq_annotation.viewpoint_quality_score, torch.float
8787
),
88-
point_cloud_quality_score=safe_as_tensor(
89-
point_cloud.quality_score, torch.float
90-
)
91-
if point_cloud is not None
92-
else None,
88+
point_cloud_quality_score=(
89+
safe_as_tensor(point_cloud.quality_score, torch.float)
90+
if point_cloud is not None
91+
else None
92+
),
9393
)
9494

9595
def test_frame_data_builder_args(self):

0 commit comments

Comments
 (0)