Skip to content

Commit

Permalink
Convert directory fbcode/vision to use the Ruff Formatter
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Thomas Polasek authored and facebook-github-bot committed Nov 26, 2024
1 parent f6c2ca6 commit 055ab3a
Show file tree
Hide file tree
Showing 92 changed files with 121 additions and 191 deletions.
2 changes: 0 additions & 2 deletions .circleci/regenerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def workflow_pair(
upload=False,
filter_branch,
):

w = []
py = python_version.replace(".", "")
pyt = pytorch_version.replace(".", "")
Expand Down Expand Up @@ -127,7 +126,6 @@ def generate_base_workflow(
btype,
filter_branch=None,
):

d = {
"name": base_workflow_name,
"python_version": python_version,
Expand Down
1 change: 1 addition & 0 deletions docs/examples/pulsar_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
sphere renderer. It renders and saves an image with 10 random spheres.
Output: basic.png.
"""

import logging
import math
from os import path
Expand Down
1 change: 1 addition & 0 deletions docs/examples/pulsar_basic_unified.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
10 random spheres.
Output: basic-pt3d.png.
"""

import logging
from os import path

Expand Down
1 change: 1 addition & 0 deletions docs/examples/pulsar_cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
original camera parameters.
Output: cam.gif.
"""

import logging
import math
from os import path
Expand Down
1 change: 1 addition & 0 deletions docs/examples/pulsar_cam_unified.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
original camera parameters.
Output: cam-pt3d.gif
"""

import logging
from os import path

Expand Down
1 change: 1 addition & 0 deletions docs/examples/pulsar_multiview.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
because opacity support has not landed in PyTorch3D for general data
structures yet.
"""

import logging
import math
from os import path
Expand Down
1 change: 1 addition & 0 deletions docs/examples/pulsar_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
optimization is used to converge towards a faithful
scene representation.
"""

import logging
import math

Expand Down
1 change: 1 addition & 0 deletions docs/examples/pulsar_optimization_unified.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
optimization is used to converge towards a faithful
scene representation.
"""

import logging
import math

Expand Down
3 changes: 2 additions & 1 deletion projects/implicitron_trainer/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# pyre-unsafe

""""
""" "
This file is the entry point for launching experiments with Implicitron.
Launch Training
Expand Down Expand Up @@ -44,6 +44,7 @@
config file.
"""

import logging
import os
import warnings
Expand Down
1 change: 0 additions & 1 deletion projects/implicitron_trainer/impl/model_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@


class ModelFactoryBase(ReplaceableBase):

resume: bool = True # resume from the last checkpoint

def __call__(self, **kwargs) -> ImplicitronModelBase:
Expand Down
1 change: 0 additions & 1 deletion projects/implicitron_trainer/impl/training_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ def run(
for epoch in range(start_epoch, self.max_epochs):
# automatic new_epoch and plotting of stats at every epoch start
with stats:

# Make sure to re-seed random generators to ensure reproducibility
# even after restart.
seed_all_random_engines(seed + epoch)
Expand Down
20 changes: 5 additions & 15 deletions projects/implicitron_trainer/tests/test_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ def test_from_defaults(self):
cfg.data_source_ImplicitronDataSource_args.dataset_map_provider_class_type = (
"JsonIndexDatasetMapProvider"
)
dataset_args = (
cfg.data_source_ImplicitronDataSource_args.dataset_map_provider_JsonIndexDatasetMapProvider_args
)
dataloader_args = (
cfg.data_source_ImplicitronDataSource_args.data_loader_map_provider_SequenceDataLoaderMapProvider_args
)
dataset_args = cfg.data_source_ImplicitronDataSource_args.dataset_map_provider_JsonIndexDatasetMapProvider_args
dataloader_args = cfg.data_source_ImplicitronDataSource_args.data_loader_map_provider_SequenceDataLoaderMapProvider_args
dataset_args.category = "skateboard"
dataset_args.test_restrict_sequence_id = 0
dataset_args.dataset_root = "manifold://co3d/tree/extracted"
Expand Down Expand Up @@ -94,12 +90,8 @@ def test_exponential_lr(self):
cfg.data_source_ImplicitronDataSource_args.dataset_map_provider_class_type = (
"JsonIndexDatasetMapProvider"
)
dataset_args = (
cfg.data_source_ImplicitronDataSource_args.dataset_map_provider_JsonIndexDatasetMapProvider_args
)
dataloader_args = (
cfg.data_source_ImplicitronDataSource_args.data_loader_map_provider_SequenceDataLoaderMapProvider_args
)
dataset_args = cfg.data_source_ImplicitronDataSource_args.dataset_map_provider_JsonIndexDatasetMapProvider_args
dataloader_args = cfg.data_source_ImplicitronDataSource_args.data_loader_map_provider_SequenceDataLoaderMapProvider_args
dataset_args.category = "skateboard"
dataset_args.test_restrict_sequence_id = 0
dataset_args.dataset_root = "manifold://co3d/tree/extracted"
Expand All @@ -111,9 +103,7 @@ def test_exponential_lr(self):
cfg.training_loop_ImplicitronTrainingLoop_args.max_epochs = 2
cfg.training_loop_ImplicitronTrainingLoop_args.store_checkpoints = False
cfg.optimizer_factory_ImplicitronOptimizerFactory_args.lr_policy = "Exponential"
cfg.optimizer_factory_ImplicitronOptimizerFactory_args.exponential_lr_step_size = (
2
)
cfg.optimizer_factory_ImplicitronOptimizerFactory_args.exponential_lr_step_size = 2

if DEBUG:
experiment.dump_cfg(cfg)
Expand Down
5 changes: 3 additions & 2 deletions projects/implicitron_trainer/tests/test_optimizer_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ def test_self_overrides_member_param_group_assignment(self):

def test_param_overrides_self_param_group_assignment(self):
pa, pb, pc = [torch.nn.Parameter(data=torch.tensor(i * 1.0)) for i in range(3)]
na, nb = Node(params=[pa]), Node(
params=[pb], param_groups={"self": "pb_self", "p1": "pb_param"}
na, nb = (
Node(params=[pa]),
Node(params=[pb], param_groups={"self": "pb_self", "p1": "pb_param"}),
)
root = Node(children=[na, nb], params=[pc], param_groups={"m1": "pb_member"})
param_groups = self._get_param_groups(root)
Expand Down
1 change: 0 additions & 1 deletion projects/nerf/nerf/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ def update(self, preds: dict, stat_set: str = "train") -> None:
it = self.it[stat_set]

for stat in self.log_vars:

if stat not in self.stats[stat_set]:
self.stats[stat_set][stat] = AverageMeter()

Expand Down
1 change: 0 additions & 1 deletion projects/nerf/test_nerf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

@hydra.main(config_path=CONFIG_DIR, config_name="lego")
def main(cfg: DictConfig):

# Device on which to run.
if torch.cuda.is_available():
device = "cuda"
Expand Down
1 change: 0 additions & 1 deletion projects/nerf/tests/test_raysampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def test_raysampler_caching(self, batch_size=10):
cameras, rays = [], []

for _ in range(batch_size):

R = random_rotations(1)
T = torch.randn(1, 3)
focal_length = torch.rand(1, 2) + 0.5
Expand Down
2 changes: 0 additions & 2 deletions projects/nerf/train_nerf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

@hydra.main(config_path=CONFIG_DIR, config_name="lego")
def main(cfg: DictConfig):

# Set the relevant seeds for reproducibility.
np.random.seed(cfg.seed)
torch.manual_seed(cfg.seed)
Expand Down Expand Up @@ -219,7 +218,6 @@ def lr_lambda(epoch):

# Validation
if epoch % cfg.validation_epoch_interval == 0 and epoch > 0:

# Sample a validation camera/image.
val_batch = next(val_dataloader.__iter__())
val_image, val_camera, camera_idx = val_batch[0].values()
Expand Down
2 changes: 1 addition & 1 deletion pytorch3d/common/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


def meshgrid_ij(
*A: Union[torch.Tensor, Sequence[torch.Tensor]]
*A: Union[torch.Tensor, Sequence[torch.Tensor]],
) -> Tuple[torch.Tensor, ...]: # pragma: no cover
"""
Like torch.meshgrid was before PyTorch 1.10.0, i.e. with indexing set to ij
Expand Down
2 changes: 1 addition & 1 deletion pytorch3d/datasets/shapenet/shapenet_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(
):
synset_set.add(synset)
elif (synset in self.synset_inv.keys()) and (
(path.isdir(path.join(data_dir, self.synset_inv[synset])))
path.isdir(path.join(data_dir, self.synset_inv[synset]))
):
synset_set.add(self.synset_inv[synset])
else:
Expand Down
1 change: 0 additions & 1 deletion pytorch3d/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def collate_batched_meshes(batch: List[Dict]): # pragma: no cover

collated_dict["mesh"] = None
if {"verts", "faces"}.issubset(collated_dict.keys()):

textures = None
if "textures" in collated_dict:
textures = TexturesAtlas(atlas=collated_dict["textures"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ def __post_init__(self):
self.dataset_map = dataset_map

def _load_category(self, category: str) -> DatasetMap:

frame_file = os.path.join(self.dataset_root, category, "frame_annotations.jgz")
sequence_file = os.path.join(
self.dataset_root, category, "sequence_annotations.jgz"
Expand Down
5 changes: 0 additions & 5 deletions pytorch3d/implicitron/dataset/load_llff.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def _minify(basedir, path_manager, factors=(), resolutions=()):
def _load_data(
basedir, factor=None, width=None, height=None, load_imgs=True, path_manager=None
):

poses_arr = np.load(
_local_path(path_manager, os.path.join(basedir, "poses_bounds.npy"))
)
Expand Down Expand Up @@ -164,7 +163,6 @@ def ptstocam(pts, c2w):


def poses_avg(poses):

hwf = poses[0, :3, -1:]

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


def recenter_poses(poses):

poses_ = poses + 0
bottom = np.reshape([0, 0, 0, 1.0], [1, 4])
c2w = poses_avg(poses)
Expand Down Expand Up @@ -256,7 +253,6 @@ def min_line_dist(rays_o, rays_d):
new_poses = []

for th in np.linspace(0.0, 2.0 * np.pi, 120):

camorigin = np.array([radcircle * np.cos(th), radcircle * np.sin(th), zh])
up = np.array([0, 0, -1.0])

Expand Down Expand Up @@ -311,7 +307,6 @@ def load_llff_data(
path_zflat=False,
path_manager=None,
):

poses, bds, imgs = _load_data(
basedir, factor=factor, path_manager=path_manager
) # factor=8 downsamples original imgs by 8x
Expand Down
1 change: 0 additions & 1 deletion pytorch3d/implicitron/dataset/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ def resize_image(
image_width: Optional[int],
mode: str = "bilinear",
) -> Tuple[torch.Tensor, float, torch.Tensor]:

if isinstance(image, np.ndarray):
image = torch.from_numpy(image)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ def eval_batch(
)

for loss_fg_mask, name_postfix in zip((mask_crop, mask_fg), ("_masked", "_fg")):

loss_mask_now = mask_crop * loss_fg_mask

for rgb_metric_name, rgb_metric_fun in zip(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ def forward(
global_code=None,
**kwargs,
):

if global_code is None:
raise ValueError("SRN Hypernetwork requires a non-trivial global code.")

Expand Down
2 changes: 0 additions & 2 deletions pytorch3d/implicitron/models/implicit_function/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def create_embeddings_for_implicit_function(
xyz_embedding_function: Optional[Callable],
diag_cov: Optional[torch.Tensor] = None,
) -> torch.Tensor:

bs, *spatial_size, pts_per_ray, _ = xyz_world.shape

if xyz_in_camera_coords:
Expand All @@ -64,7 +63,6 @@ def create_embeddings_for_implicit_function(
0,
)
else:

embeds = xyz_embedding_function(ray_points_for_embed, diag_cov=diag_cov)
embeds = embeds.reshape(
bs,
Expand Down
3 changes: 1 addition & 2 deletions pytorch3d/implicitron/models/renderer/sdf_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ def forward(
)
mask_full.view(-1, 1)[~surface_mask] = torch.sigmoid(
# pyre-fixme[6]: For 1st param expected `Tensor` but got `float`.
-self.soft_mask_alpha
* sdf_output[~surface_mask]
-self.soft_mask_alpha * sdf_output[~surface_mask]
)

# scatter points with surface_mask
Expand Down
1 change: 0 additions & 1 deletion pytorch3d/implicitron/tools/depth_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def cleanup_eval_depth(
sigma: float = 0.01,
image=None,
):

ba, _, H, W = depth.shape

pcl = point_cloud.points_padded()
Expand Down
1 change: 0 additions & 1 deletion pytorch3d/implicitron/tools/point_cloud_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def render_point_cloud_pytorch3d(
bin_size: Optional[int] = None,
**kwargs,
):

# feature dimension
featdim = point_cloud.features_packed().shape[-1]

Expand Down
Loading

0 comments on commit 055ab3a

Please sign in to comment.