Skip to content

Commit 055ab3a

Browse files
Thomas Polasekfacebook-github-bot
Thomas Polasek
authored andcommitted
Convert directory fbcode/vision to use the Ruff Formatter
Summary: Converts the directory specified to use the Ruff formatter in pyfmt ruff_dog If this diff causes merge conflicts when rebasing, please run `hg status -n -0 --change . -I '**/*.{py,pyi}' | xargs -0 arc pyfmt` on your diff, and amend any changes before rebasing onto latest. That should help reduce or eliminate any merge conflicts. allow-large-files Reviewed By: bottler Differential Revision: D66472063 fbshipit-source-id: 35841cb397e4f8e066e2159550d2f56b403b1bef
1 parent f6c2ca6 commit 055ab3a

File tree

92 files changed

+121
-191
lines changed

Some content is hidden

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

92 files changed

+121
-191
lines changed

.circleci/regenerate.py

-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def workflow_pair(
8888
upload=False,
8989
filter_branch,
9090
):
91-
9291
w = []
9392
py = python_version.replace(".", "")
9493
pyt = pytorch_version.replace(".", "")
@@ -127,7 +126,6 @@ def generate_base_workflow(
127126
btype,
128127
filter_branch=None,
129128
):
130-
131129
d = {
132130
"name": base_workflow_name,
133131
"python_version": python_version,

docs/examples/pulsar_basic.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
sphere renderer. It renders and saves an image with 10 random spheres.
1111
Output: basic.png.
1212
"""
13+
1314
import logging
1415
import math
1516
from os import path

docs/examples/pulsar_basic_unified.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
10 random spheres.
1212
Output: basic-pt3d.png.
1313
"""
14+
1415
import logging
1516
from os import path
1617

docs/examples/pulsar_cam.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
original camera parameters.
1515
Output: cam.gif.
1616
"""
17+
1718
import logging
1819
import math
1920
from os import path

docs/examples/pulsar_cam_unified.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
original camera parameters.
1515
Output: cam-pt3d.gif
1616
"""
17+
1718
import logging
1819
from os import path
1920

docs/examples/pulsar_multiview.py

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
because opacity support has not landed in PyTorch3D for general data
1919
structures yet.
2020
"""
21+
2122
import logging
2223
import math
2324
from os import path

docs/examples/pulsar_optimization.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
optimization is used to converge towards a faithful
1414
scene representation.
1515
"""
16+
1617
import logging
1718
import math
1819

docs/examples/pulsar_optimization_unified.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
optimization is used to converge towards a faithful
1414
scene representation.
1515
"""
16+
1617
import logging
1718
import math
1819

projects/implicitron_trainer/experiment.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# pyre-unsafe
99

10-
""""
10+
""" "
1111
This file is the entry point for launching experiments with Implicitron.
1212
1313
Launch Training
@@ -44,6 +44,7 @@
4444
config file.
4545
4646
"""
47+
4748
import logging
4849
import os
4950
import warnings

projects/implicitron_trainer/impl/model_factory.py

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727

2828
class ModelFactoryBase(ReplaceableBase):
29-
3029
resume: bool = True # resume from the last checkpoint
3130

3231
def __call__(self, **kwargs) -> ImplicitronModelBase:

projects/implicitron_trainer/impl/training_loop.py

-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ def run(
161161
for epoch in range(start_epoch, self.max_epochs):
162162
# automatic new_epoch and plotting of stats at every epoch start
163163
with stats:
164-
165164
# Make sure to re-seed random generators to ensure reproducibility
166165
# even after restart.
167166
seed_all_random_engines(seed + epoch)

projects/implicitron_trainer/tests/test_experiment.py

+5-15
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,8 @@ def test_from_defaults(self):
5353
cfg.data_source_ImplicitronDataSource_args.dataset_map_provider_class_type = (
5454
"JsonIndexDatasetMapProvider"
5555
)
56-
dataset_args = (
57-
cfg.data_source_ImplicitronDataSource_args.dataset_map_provider_JsonIndexDatasetMapProvider_args
58-
)
59-
dataloader_args = (
60-
cfg.data_source_ImplicitronDataSource_args.data_loader_map_provider_SequenceDataLoaderMapProvider_args
61-
)
56+
dataset_args = cfg.data_source_ImplicitronDataSource_args.dataset_map_provider_JsonIndexDatasetMapProvider_args
57+
dataloader_args = cfg.data_source_ImplicitronDataSource_args.data_loader_map_provider_SequenceDataLoaderMapProvider_args
6258
dataset_args.category = "skateboard"
6359
dataset_args.test_restrict_sequence_id = 0
6460
dataset_args.dataset_root = "manifold://co3d/tree/extracted"
@@ -94,12 +90,8 @@ def test_exponential_lr(self):
9490
cfg.data_source_ImplicitronDataSource_args.dataset_map_provider_class_type = (
9591
"JsonIndexDatasetMapProvider"
9692
)
97-
dataset_args = (
98-
cfg.data_source_ImplicitronDataSource_args.dataset_map_provider_JsonIndexDatasetMapProvider_args
99-
)
100-
dataloader_args = (
101-
cfg.data_source_ImplicitronDataSource_args.data_loader_map_provider_SequenceDataLoaderMapProvider_args
102-
)
93+
dataset_args = cfg.data_source_ImplicitronDataSource_args.dataset_map_provider_JsonIndexDatasetMapProvider_args
94+
dataloader_args = cfg.data_source_ImplicitronDataSource_args.data_loader_map_provider_SequenceDataLoaderMapProvider_args
10395
dataset_args.category = "skateboard"
10496
dataset_args.test_restrict_sequence_id = 0
10597
dataset_args.dataset_root = "manifold://co3d/tree/extracted"
@@ -111,9 +103,7 @@ def test_exponential_lr(self):
111103
cfg.training_loop_ImplicitronTrainingLoop_args.max_epochs = 2
112104
cfg.training_loop_ImplicitronTrainingLoop_args.store_checkpoints = False
113105
cfg.optimizer_factory_ImplicitronOptimizerFactory_args.lr_policy = "Exponential"
114-
cfg.optimizer_factory_ImplicitronOptimizerFactory_args.exponential_lr_step_size = (
115-
2
116-
)
106+
cfg.optimizer_factory_ImplicitronOptimizerFactory_args.exponential_lr_step_size = 2
117107

118108
if DEBUG:
119109
experiment.dump_cfg(cfg)

projects/implicitron_trainer/tests/test_optimizer_factory.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ def test_self_overrides_member_param_group_assignment(self):
8181

8282
def test_param_overrides_self_param_group_assignment(self):
8383
pa, pb, pc = [torch.nn.Parameter(data=torch.tensor(i * 1.0)) for i in range(3)]
84-
na, nb = Node(params=[pa]), Node(
85-
params=[pb], param_groups={"self": "pb_self", "p1": "pb_param"}
84+
na, nb = (
85+
Node(params=[pa]),
86+
Node(params=[pb], param_groups={"self": "pb_self", "p1": "pb_param"}),
8687
)
8788
root = Node(children=[na, nb], params=[pc], param_groups={"m1": "pb_member"})
8889
param_groups = self._get_param_groups(root)

projects/nerf/nerf/stats.py

-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ def update(self, preds: dict, stat_set: str = "train") -> None:
194194
it = self.it[stat_set]
195195

196196
for stat in self.log_vars:
197-
198197
if stat not in self.stats[stat_set]:
199198
self.stats[stat_set][stat] = AverageMeter()
200199

projects/nerf/test_nerf.py

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
@hydra.main(config_path=CONFIG_DIR, config_name="lego")
2626
def main(cfg: DictConfig):
27-
2827
# Device on which to run.
2928
if torch.cuda.is_available():
3029
device = "cuda"

projects/nerf/tests/test_raysampler.py

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def test_raysampler_caching(self, batch_size=10):
4242
cameras, rays = [], []
4343

4444
for _ in range(batch_size):
45-
4645
R = random_rotations(1)
4746
T = torch.randn(1, 3)
4847
focal_length = torch.rand(1, 2) + 0.5

projects/nerf/train_nerf.py

-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
@hydra.main(config_path=CONFIG_DIR, config_name="lego")
2727
def main(cfg: DictConfig):
28-
2928
# Set the relevant seeds for reproducibility.
3029
np.random.seed(cfg.seed)
3130
torch.manual_seed(cfg.seed)
@@ -219,7 +218,6 @@ def lr_lambda(epoch):
219218

220219
# Validation
221220
if epoch % cfg.validation_epoch_interval == 0 and epoch > 0:
222-
223221
# Sample a validation camera/image.
224222
val_batch = next(val_dataloader.__iter__())
225223
val_image, val_camera, camera_idx = val_batch[0].values()

pytorch3d/common/compat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
def meshgrid_ij(
20-
*A: Union[torch.Tensor, Sequence[torch.Tensor]]
20+
*A: Union[torch.Tensor, Sequence[torch.Tensor]],
2121
) -> Tuple[torch.Tensor, ...]: # pragma: no cover
2222
"""
2323
Like torch.meshgrid was before PyTorch 1.10.0, i.e. with indexing set to ij

pytorch3d/datasets/shapenet/shapenet_core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __init__(
8383
):
8484
synset_set.add(synset)
8585
elif (synset in self.synset_inv.keys()) and (
86-
(path.isdir(path.join(data_dir, self.synset_inv[synset])))
86+
path.isdir(path.join(data_dir, self.synset_inv[synset]))
8787
):
8888
synset_set.add(self.synset_inv[synset])
8989
else:

pytorch3d/datasets/utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def collate_batched_meshes(batch: List[Dict]): # pragma: no cover
3636

3737
collated_dict["mesh"] = None
3838
if {"verts", "faces"}.issubset(collated_dict.keys()):
39-
4039
textures = None
4140
if "textures" in collated_dict:
4241
textures = TexturesAtlas(atlas=collated_dict["textures"])

pytorch3d/implicitron/dataset/json_index_dataset_map_provider_v2.py

-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ def __post_init__(self):
222222
self.dataset_map = dataset_map
223223

224224
def _load_category(self, category: str) -> DatasetMap:
225-
226225
frame_file = os.path.join(self.dataset_root, category, "frame_annotations.jgz")
227226
sequence_file = os.path.join(
228227
self.dataset_root, category, "sequence_annotations.jgz"

pytorch3d/implicitron/dataset/load_llff.py

-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def _minify(basedir, path_manager, factors=(), resolutions=()):
7575
def _load_data(
7676
basedir, factor=None, width=None, height=None, load_imgs=True, path_manager=None
7777
):
78-
7978
poses_arr = np.load(
8079
_local_path(path_manager, os.path.join(basedir, "poses_bounds.npy"))
8180
)
@@ -164,7 +163,6 @@ def ptstocam(pts, c2w):
164163

165164

166165
def poses_avg(poses):
167-
168166
hwf = poses[0, :3, -1:]
169167

170168
center = poses[:, :3, 3].mean(0)
@@ -192,7 +190,6 @@ def render_path_spiral(c2w, up, rads, focal, zdelta, zrate, rots, N):
192190

193191

194192
def recenter_poses(poses):
195-
196193
poses_ = poses + 0
197194
bottom = np.reshape([0, 0, 0, 1.0], [1, 4])
198195
c2w = poses_avg(poses)
@@ -256,7 +253,6 @@ def min_line_dist(rays_o, rays_d):
256253
new_poses = []
257254

258255
for th in np.linspace(0.0, 2.0 * np.pi, 120):
259-
260256
camorigin = np.array([radcircle * np.cos(th), radcircle * np.sin(th), zh])
261257
up = np.array([0, 0, -1.0])
262258

@@ -311,7 +307,6 @@ def load_llff_data(
311307
path_zflat=False,
312308
path_manager=None,
313309
):
314-
315310
poses, bds, imgs = _load_data(
316311
basedir, factor=factor, path_manager=path_manager
317312
) # factor=8 downsamples original imgs by 8x

pytorch3d/implicitron/dataset/utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ def resize_image(
201201
image_width: Optional[int],
202202
mode: str = "bilinear",
203203
) -> Tuple[torch.Tensor, float, torch.Tensor]:
204-
205204
if isinstance(image, np.ndarray):
206205
image = torch.from_numpy(image)
207206

pytorch3d/implicitron/evaluation/evaluate_new_view_synthesis.py

-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ def eval_batch(
299299
)
300300

301301
for loss_fg_mask, name_postfix in zip((mask_crop, mask_fg), ("_masked", "_fg")):
302-
303302
loss_mask_now = mask_crop * loss_fg_mask
304303

305304
for rgb_metric_name, rgb_metric_fun in zip(

pytorch3d/implicitron/models/implicit_function/scene_representation_networks.py

-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ def forward(
306306
global_code=None,
307307
**kwargs,
308308
):
309-
310309
if global_code is None:
311310
raise ValueError("SRN Hypernetwork requires a non-trivial global code.")
312311

pytorch3d/implicitron/models/implicit_function/utils.py

-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def create_embeddings_for_implicit_function(
4040
xyz_embedding_function: Optional[Callable],
4141
diag_cov: Optional[torch.Tensor] = None,
4242
) -> torch.Tensor:
43-
4443
bs, *spatial_size, pts_per_ray, _ = xyz_world.shape
4544

4645
if xyz_in_camera_coords:
@@ -64,7 +63,6 @@ def create_embeddings_for_implicit_function(
6463
0,
6564
)
6665
else:
67-
6866
embeds = xyz_embedding_function(ray_points_for_embed, diag_cov=diag_cov)
6967
embeds = embeds.reshape(
7068
bs,

pytorch3d/implicitron/models/renderer/sdf_renderer.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ def forward(
220220
)
221221
mask_full.view(-1, 1)[~surface_mask] = torch.sigmoid(
222222
# pyre-fixme[6]: For 1st param expected `Tensor` but got `float`.
223-
-self.soft_mask_alpha
224-
* sdf_output[~surface_mask]
223+
-self.soft_mask_alpha * sdf_output[~surface_mask]
225224
)
226225

227226
# scatter points with surface_mask

pytorch3d/implicitron/tools/depth_cleanup.py

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def cleanup_eval_depth(
2121
sigma: float = 0.01,
2222
image=None,
2323
):
24-
2524
ba, _, H, W = depth.shape
2625

2726
pcl = point_cloud.points_padded()

pytorch3d/implicitron/tools/point_cloud_utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def render_point_cloud_pytorch3d(
100100
bin_size: Optional[int] = None,
101101
**kwargs,
102102
):
103-
104103
# feature dimension
105104
featdim = point_cloud.features_packed().shape[-1]
106105

0 commit comments

Comments
 (0)