diff --git a/.circleci/regenerate.py b/.circleci/regenerate.py index 02b6f748..f9becfe9 100755 --- a/.circleci/regenerate.py +++ b/.circleci/regenerate.py @@ -88,7 +88,6 @@ def workflow_pair( upload=False, filter_branch, ): - w = [] py = python_version.replace(".", "") pyt = pytorch_version.replace(".", "") @@ -127,7 +126,6 @@ def generate_base_workflow( btype, filter_branch=None, ): - d = { "name": base_workflow_name, "python_version": python_version, diff --git a/docs/examples/pulsar_basic.py b/docs/examples/pulsar_basic.py index be547e34..175f0c44 100755 --- a/docs/examples/pulsar_basic.py +++ b/docs/examples/pulsar_basic.py @@ -10,6 +10,7 @@ This example demonstrates the most trivial, direct interface of the pulsar sphere renderer. It renders and saves an image with 10 random spheres. Output: basic.png. """ + import logging import math from os import path diff --git a/docs/examples/pulsar_basic_unified.py b/docs/examples/pulsar_basic_unified.py index ae93f49d..bc315196 100755 --- a/docs/examples/pulsar_basic_unified.py +++ b/docs/examples/pulsar_basic_unified.py @@ -11,6 +11,7 @@ interface for sphere renderering. It renders and saves an image with 10 random spheres. Output: basic-pt3d.png. """ + import logging from os import path diff --git a/docs/examples/pulsar_cam.py b/docs/examples/pulsar_cam.py index cd1dfabc..ee7692ee 100755 --- a/docs/examples/pulsar_cam.py +++ b/docs/examples/pulsar_cam.py @@ -14,6 +14,7 @@ distorted. Gradient-based optimization is used to converge towards the original camera parameters. Output: cam.gif. """ + import logging import math from os import path diff --git a/docs/examples/pulsar_cam_unified.py b/docs/examples/pulsar_cam_unified.py index 8ef3a8df..39472e17 100755 --- a/docs/examples/pulsar_cam_unified.py +++ b/docs/examples/pulsar_cam_unified.py @@ -14,6 +14,7 @@ distorted. Gradient-based optimization is used to converge towards the original camera parameters. Output: cam-pt3d.gif """ + import logging from os import path diff --git a/docs/examples/pulsar_multiview.py b/docs/examples/pulsar_multiview.py index a6a05b4a..74bba1ff 100755 --- a/docs/examples/pulsar_multiview.py +++ b/docs/examples/pulsar_multiview.py @@ -18,6 +18,7 @@ This example is not available yet through the 'unified' interface, because opacity support has not landed in PyTorch3D for general data structures yet. """ + import logging import math from os import path diff --git a/docs/examples/pulsar_optimization.py b/docs/examples/pulsar_optimization.py index 530233f3..c79c0afe 100755 --- a/docs/examples/pulsar_optimization.py +++ b/docs/examples/pulsar_optimization.py @@ -13,6 +13,7 @@ The scene is initialized with random spheres. Gradient-based optimization is used to converge towards a faithful scene representation. """ + import logging import math diff --git a/docs/examples/pulsar_optimization_unified.py b/docs/examples/pulsar_optimization_unified.py index be4d9299..663adeb6 100755 --- a/docs/examples/pulsar_optimization_unified.py +++ b/docs/examples/pulsar_optimization_unified.py @@ -13,6 +13,7 @@ The scene is initialized with random spheres. Gradient-based optimization is used to converge towards a faithful scene representation. """ + import logging import math diff --git a/projects/implicitron_trainer/experiment.py b/projects/implicitron_trainer/experiment.py index 3ec33c50..969fb732 100755 --- a/projects/implicitron_trainer/experiment.py +++ b/projects/implicitron_trainer/experiment.py @@ -7,7 +7,7 @@ # pyre-unsafe -"""" +""" " This file is the entry point for launching experiments with Implicitron. Launch Training @@ -44,6 +44,7 @@ The outputs of the experiment are saved and logged in multiple ways: config file. """ + import logging import os import warnings diff --git a/projects/implicitron_trainer/impl/model_factory.py b/projects/implicitron_trainer/impl/model_factory.py index bbfcceb7..9692b92a 100644 --- a/projects/implicitron_trainer/impl/model_factory.py +++ b/projects/implicitron_trainer/impl/model_factory.py @@ -26,7 +26,6 @@ logger = logging.getLogger(__name__) class ModelFactoryBase(ReplaceableBase): - resume: bool = True # resume from the last checkpoint def __call__(self, **kwargs) -> ImplicitronModelBase: diff --git a/projects/implicitron_trainer/impl/training_loop.py b/projects/implicitron_trainer/impl/training_loop.py index ff15176e..b752d595 100644 --- a/projects/implicitron_trainer/impl/training_loop.py +++ b/projects/implicitron_trainer/impl/training_loop.py @@ -161,7 +161,6 @@ class ImplicitronTrainingLoop(TrainingLoopBase): 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) diff --git a/projects/implicitron_trainer/tests/test_experiment.py b/projects/implicitron_trainer/tests/test_experiment.py index 46ceb922..c850a004 100644 --- a/projects/implicitron_trainer/tests/test_experiment.py +++ b/projects/implicitron_trainer/tests/test_experiment.py @@ -53,12 +53,8 @@ class TestExperiment(unittest.TestCase): 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" @@ -94,12 +90,8 @@ class TestExperiment(unittest.TestCase): 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" @@ -111,9 +103,7 @@ class TestExperiment(unittest.TestCase): 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) diff --git a/projects/implicitron_trainer/tests/test_optimizer_factory.py b/projects/implicitron_trainer/tests/test_optimizer_factory.py index 07cb93fc..0c62f18f 100644 --- a/projects/implicitron_trainer/tests/test_optimizer_factory.py +++ b/projects/implicitron_trainer/tests/test_optimizer_factory.py @@ -81,8 +81,9 @@ class TestOptimizerFactory(unittest.TestCase): 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) diff --git a/projects/nerf/nerf/stats.py b/projects/nerf/nerf/stats.py index cb02472b..4eddc9a1 100644 --- a/projects/nerf/nerf/stats.py +++ b/projects/nerf/nerf/stats.py @@ -194,7 +194,6 @@ class Stats: 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() diff --git a/projects/nerf/test_nerf.py b/projects/nerf/test_nerf.py index 4d86aa37..67692817 100644 --- a/projects/nerf/test_nerf.py +++ b/projects/nerf/test_nerf.py @@ -24,7 +24,6 @@ CONFIG_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "configs" @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" diff --git a/projects/nerf/tests/test_raysampler.py b/projects/nerf/tests/test_raysampler.py index ba53713a..5734e085 100644 --- a/projects/nerf/tests/test_raysampler.py +++ b/projects/nerf/tests/test_raysampler.py @@ -42,7 +42,6 @@ class TestRaysampler(unittest.TestCase): cameras, rays = [], [] for _ in range(batch_size): - R = random_rotations(1) T = torch.randn(1, 3) focal_length = torch.rand(1, 2) + 0.5 diff --git a/projects/nerf/train_nerf.py b/projects/nerf/train_nerf.py index be7f40d6..18f8cb4c 100644 --- a/projects/nerf/train_nerf.py +++ b/projects/nerf/train_nerf.py @@ -25,7 +25,6 @@ CONFIG_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "configs" @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) @@ -219,7 +218,6 @@ def main(cfg: DictConfig): # 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() diff --git a/pytorch3d/common/compat.py b/pytorch3d/common/compat.py index e90680c8..02a64cef 100644 --- a/pytorch3d/common/compat.py +++ b/pytorch3d/common/compat.py @@ -17,7 +17,7 @@ Some functions which depend on PyTorch or Python versions. 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 diff --git a/pytorch3d/datasets/shapenet/shapenet_core.py b/pytorch3d/datasets/shapenet/shapenet_core.py index 70524b15..02291ed0 100644 --- a/pytorch3d/datasets/shapenet/shapenet_core.py +++ b/pytorch3d/datasets/shapenet/shapenet_core.py @@ -83,7 +83,7 @@ class ShapeNetCore(ShapeNetBase): # pragma: no cover ): 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: diff --git a/pytorch3d/datasets/utils.py b/pytorch3d/datasets/utils.py index f651604c..9974f1ea 100644 --- a/pytorch3d/datasets/utils.py +++ b/pytorch3d/datasets/utils.py @@ -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"]) diff --git a/pytorch3d/implicitron/dataset/json_index_dataset_map_provider_v2.py b/pytorch3d/implicitron/dataset/json_index_dataset_map_provider_v2.py index 765de109..15fb3a1d 100644 --- a/pytorch3d/implicitron/dataset/json_index_dataset_map_provider_v2.py +++ b/pytorch3d/implicitron/dataset/json_index_dataset_map_provider_v2.py @@ -222,7 +222,6 @@ class JsonIndexDatasetMapProviderV2(DatasetMapProviderBase): 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" diff --git a/pytorch3d/implicitron/dataset/load_llff.py b/pytorch3d/implicitron/dataset/load_llff.py index d29b650b..5cf03c3c 100644 --- a/pytorch3d/implicitron/dataset/load_llff.py +++ b/pytorch3d/implicitron/dataset/load_llff.py @@ -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")) ) @@ -164,7 +163,6 @@ def ptstocam(pts, c2w): def poses_avg(poses): - hwf = poses[0, :3, -1:] center = poses[:, :3, 3].mean(0) @@ -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) @@ -256,7 +253,6 @@ def spherify_poses(poses, bds): 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]) @@ -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 diff --git a/pytorch3d/implicitron/dataset/utils.py b/pytorch3d/implicitron/dataset/utils.py index 774efdf5..cb8828eb 100644 --- a/pytorch3d/implicitron/dataset/utils.py +++ b/pytorch3d/implicitron/dataset/utils.py @@ -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) diff --git a/pytorch3d/implicitron/evaluation/evaluate_new_view_synthesis.py b/pytorch3d/implicitron/evaluation/evaluate_new_view_synthesis.py index 05b893d7..1d7ab689 100644 --- a/pytorch3d/implicitron/evaluation/evaluate_new_view_synthesis.py +++ b/pytorch3d/implicitron/evaluation/evaluate_new_view_synthesis.py @@ -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( diff --git a/pytorch3d/implicitron/models/implicit_function/scene_representation_networks.py b/pytorch3d/implicitron/models/implicit_function/scene_representation_networks.py index f8702e50..8c170776 100644 --- a/pytorch3d/implicitron/models/implicit_function/scene_representation_networks.py +++ b/pytorch3d/implicitron/models/implicit_function/scene_representation_networks.py @@ -306,7 +306,6 @@ class SRNRaymarchHyperNet(Configurable, torch.nn.Module): global_code=None, **kwargs, ): - if global_code is None: raise ValueError("SRN Hypernetwork requires a non-trivial global code.") diff --git a/pytorch3d/implicitron/models/implicit_function/utils.py b/pytorch3d/implicitron/models/implicit_function/utils.py index ec453f43..5b345b3c 100644 --- a/pytorch3d/implicitron/models/implicit_function/utils.py +++ b/pytorch3d/implicitron/models/implicit_function/utils.py @@ -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: @@ -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, diff --git a/pytorch3d/implicitron/models/renderer/sdf_renderer.py b/pytorch3d/implicitron/models/renderer/sdf_renderer.py index 57d65b98..c769b5f5 100644 --- a/pytorch3d/implicitron/models/renderer/sdf_renderer.py +++ b/pytorch3d/implicitron/models/renderer/sdf_renderer.py @@ -220,8 +220,7 @@ class SignedDistanceFunctionRenderer(BaseRenderer, torch.nn.Module): ) 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 diff --git a/pytorch3d/implicitron/tools/depth_cleanup.py b/pytorch3d/implicitron/tools/depth_cleanup.py index 89d48d37..76edf963 100644 --- a/pytorch3d/implicitron/tools/depth_cleanup.py +++ b/pytorch3d/implicitron/tools/depth_cleanup.py @@ -21,7 +21,6 @@ def cleanup_eval_depth( sigma: float = 0.01, image=None, ): - ba, _, H, W = depth.shape pcl = point_cloud.points_padded() diff --git a/pytorch3d/implicitron/tools/point_cloud_utils.py b/pytorch3d/implicitron/tools/point_cloud_utils.py index 5c30a231..de124cf2 100644 --- a/pytorch3d/implicitron/tools/point_cloud_utils.py +++ b/pytorch3d/implicitron/tools/point_cloud_utils.py @@ -100,7 +100,6 @@ def render_point_cloud_pytorch3d( bin_size: Optional[int] = None, **kwargs, ): - # feature dimension featdim = point_cloud.features_packed().shape[-1] diff --git a/pytorch3d/implicitron/tools/stats.py b/pytorch3d/implicitron/tools/stats.py index 0625f3e3..06ca09a5 100644 --- a/pytorch3d/implicitron/tools/stats.py +++ b/pytorch3d/implicitron/tools/stats.py @@ -37,7 +37,6 @@ class AverageMeter: self.count = 0 def update(self, val, n=1, epoch=0): - # make sure the history is of the same len as epoch while len(self.history) <= epoch: self.history.append([]) @@ -115,7 +114,6 @@ class Stats: visdom_server="http://localhost", visdom_port=8097, ): - self.log_vars = log_vars self.visdom_env = visdom_env self.visdom_server = visdom_server @@ -202,7 +200,6 @@ class Stats: self.log_vars.append(add_log_var) def update(self, preds, time_start=None, freeze_iter=False, stat_set="train"): - if self.epoch == -1: # uninitialized logger.warning( "epoch==-1 means uninitialized stats structure -> new_epoch() called" @@ -219,7 +216,6 @@ class Stats: epoch = self.epoch for stat in self.log_vars: - if stat not in self.stats[stat_set]: self.stats[stat_set][stat] = AverageMeter() @@ -248,7 +244,6 @@ class Stats: self.stats[stat_set][stat].update(val, epoch=epoch, n=1) def get_epoch_averages(self, epoch=None): - stat_sets = list(self.stats.keys()) if epoch is None: @@ -345,7 +340,6 @@ class Stats: def plot_stats( self, visdom_env=None, plot_file=None, visdom_server=None, visdom_port=None ): - # use the cached visdom env if none supplied if visdom_env is None: visdom_env = self.visdom_env @@ -449,7 +443,6 @@ class Stats: warnings.warn("Cant dump stats due to insufficient permissions!") def synchronize_logged_vars(self, log_vars, default_val=float("NaN")): - stat_sets = list(self.stats.keys()) # remove the additional log_vars @@ -490,11 +483,12 @@ class Stats: for ep in range(lastep): self.stats[stat_set][stat].update(default_val, n=1, epoch=ep) epoch_generated = self.stats[stat_set][stat].get_epoch() - assert ( - epoch_generated == self.epoch + 1 - ), "bad epoch of synchronized log_var! %d vs %d" % ( - self.epoch + 1, - epoch_generated, + assert epoch_generated == self.epoch + 1, ( + "bad epoch of synchronized log_var! %d vs %d" + % ( + self.epoch + 1, + epoch_generated, + ) ) diff --git a/pytorch3d/io/mtl_io.py b/pytorch3d/io/mtl_io.py index 9fb6af3f..41e32bb3 100644 --- a/pytorch3d/io/mtl_io.py +++ b/pytorch3d/io/mtl_io.py @@ -7,6 +7,7 @@ # pyre-unsafe """This module implements utility functions for loading .mtl files and textures.""" + import os import warnings from typing import Dict, List, Optional, Tuple diff --git a/pytorch3d/io/obj_io.py b/pytorch3d/io/obj_io.py index 3cc29794..e6cd7540 100644 --- a/pytorch3d/io/obj_io.py +++ b/pytorch3d/io/obj_io.py @@ -8,6 +8,7 @@ """This module implements utility functions for loading and saving meshes.""" + import os import warnings from collections import namedtuple @@ -813,7 +814,6 @@ def _save( save_texture: bool = False, save_normals: bool = False, ) -> None: - if len(verts) and (verts.dim() != 2 or verts.size(1) != 3): message = "'verts' should either be empty or of shape (num_verts, 3)." raise ValueError(message) diff --git a/pytorch3d/io/off_io.py b/pytorch3d/io/off_io.py index 42181610..0ef4049e 100644 --- a/pytorch3d/io/off_io.py +++ b/pytorch3d/io/off_io.py @@ -14,6 +14,7 @@ meshes as .off files. This format is introduced, for example, at http://www.geomview.org/docs/html/OFF.html . """ + import warnings from typing import cast, Optional, Tuple, Union diff --git a/pytorch3d/io/ply_io.py b/pytorch3d/io/ply_io.py index 3e95ea22..cf491313 100644 --- a/pytorch3d/io/ply_io.py +++ b/pytorch3d/io/ply_io.py @@ -11,6 +11,7 @@ This module implements utility functions for loading and saving meshes and point clouds as PLY files. """ + import itertools import os import struct diff --git a/pytorch3d/ops/cubify.py b/pytorch3d/ops/cubify.py index ceab4bc7..76a46d29 100644 --- a/pytorch3d/ops/cubify.py +++ b/pytorch3d/ops/cubify.py @@ -62,7 +62,7 @@ def cubify( *, feats: Optional[torch.Tensor] = None, device=None, - align: str = "topleft" + align: str = "topleft", ) -> Meshes: r""" Converts a voxel to a mesh by replacing each occupied voxel with a cube diff --git a/pytorch3d/ops/points_to_volumes.py b/pytorch3d/ops/points_to_volumes.py index cebd7cef..d9fd7700 100644 --- a/pytorch3d/ops/points_to_volumes.py +++ b/pytorch3d/ops/points_to_volumes.py @@ -85,7 +85,6 @@ class _points_to_volumes_function(Function): align_corners: bool, splat: bool, ): - ctx.mark_dirty(volume_densities, volume_features) N, P, D = points_3d.shape @@ -497,7 +496,6 @@ def _check_points_to_volumes_inputs( grid_sizes: torch.LongTensor, mask: Optional[torch.Tensor] = None, ) -> None: - max_grid_size = grid_sizes.max(dim=0).values if torch.prod(max_grid_size) > volume_densities.shape[1]: raise ValueError( diff --git a/pytorch3d/ops/sample_points_from_meshes.py b/pytorch3d/ops/sample_points_from_meshes.py index 125fe683..000a0b2a 100644 --- a/pytorch3d/ops/sample_points_from_meshes.py +++ b/pytorch3d/ops/sample_points_from_meshes.py @@ -11,6 +11,7 @@ This module implements utility functions for sampling points from batches of meshes. """ + import sys from typing import Tuple, Union diff --git a/pytorch3d/renderer/camera_conversions.py b/pytorch3d/renderer/camera_conversions.py index 97e5ecb6..8a823486 100644 --- a/pytorch3d/renderer/camera_conversions.py +++ b/pytorch3d/renderer/camera_conversions.py @@ -110,30 +110,32 @@ def _pulsar_from_opencv_projection( # Validate parameters. image_size_wh = image_size.to(R).flip(dims=(1,)) - assert torch.all( - image_size_wh > 0 - ), "height and width must be positive but min is: %s" % ( - str(image_size_wh.min().item()) + assert torch.all(image_size_wh > 0), ( + "height and width must be positive but min is: %s" + % (str(image_size_wh.min().item())) ) - assert ( - camera_matrix.size(1) == 3 and camera_matrix.size(2) == 3 - ), "Incorrect camera matrix shape: expected 3x3 but got %dx%d" % ( - camera_matrix.size(1), - camera_matrix.size(2), + assert camera_matrix.size(1) == 3 and camera_matrix.size(2) == 3, ( + "Incorrect camera matrix shape: expected 3x3 but got %dx%d" + % ( + camera_matrix.size(1), + camera_matrix.size(2), + ) ) - assert ( - R.size(1) == 3 and R.size(2) == 3 - ), "Incorrect R shape: expected 3x3 but got %dx%d" % ( - R.size(1), - R.size(2), + assert R.size(1) == 3 and R.size(2) == 3, ( + "Incorrect R shape: expected 3x3 but got %dx%d" + % ( + R.size(1), + R.size(2), + ) ) if len(tvec.size()) == 2: tvec = tvec.unsqueeze(2) - assert ( - tvec.size(1) == 3 and tvec.size(2) == 1 - ), "Incorrect tvec shape: expected 3x1 but got %dx%d" % ( - tvec.size(1), - tvec.size(2), + assert tvec.size(1) == 3 and tvec.size(2) == 1, ( + "Incorrect tvec shape: expected 3x1 but got %dx%d" + % ( + tvec.size(1), + tvec.size(2), + ) ) # Check batch size. batch_size = camera_matrix.size(0) @@ -141,11 +143,12 @@ def _pulsar_from_opencv_projection( batch_size, R.size(0), ) - assert ( - tvec.size(0) == batch_size - ), "Expected tvec to have batch size %d. Has size %d." % ( - batch_size, - tvec.size(0), + assert tvec.size(0) == batch_size, ( + "Expected tvec to have batch size %d. Has size %d." + % ( + batch_size, + tvec.size(0), + ) ) # Check image sizes. image_w = image_size_wh[0, 0] diff --git a/pytorch3d/renderer/cameras.py b/pytorch3d/renderer/cameras.py index bab52aff..db4842dc 100644 --- a/pytorch3d/renderer/cameras.py +++ b/pytorch3d/renderer/cameras.py @@ -1176,7 +1176,12 @@ class PerspectiveCameras(CamerasBase): unprojection_transform = to_camera_transform.inverse() xy_inv_depth = torch.cat( - (xy_depth[..., :2], 1.0 / xy_depth[..., 2:3]), dim=-1 # type: ignore + # pyre-fixme[6]: For 1st argument expected `Union[List[Tensor], + # tuple[Tensor, ...]]` but got `Tuple[Tensor, float]`. + # pyre-fixme[58]: `/` is not supported for operand types `float` and + # `Tensor`. + (xy_depth[..., :2], 1.0 / xy_depth[..., 2:3]), + dim=-1, # type: ignore ) return unprojection_transform.transform_points(xy_inv_depth) diff --git a/pytorch3d/renderer/fisheyecameras.py b/pytorch3d/renderer/fisheyecameras.py index 5b464a0b..cf5261b7 100644 --- a/pytorch3d/renderer/fisheyecameras.py +++ b/pytorch3d/renderer/fisheyecameras.py @@ -281,8 +281,10 @@ class FishEyeCameras(CamerasBase): # project from camera space to image space N = len(self.radial_params) if not self.check_input(points, N): - msg = "Expected points of (P, 3) with batch_size 1 or N, or shape (M, P, 3) \ + msg = ( + "Expected points of (P, 3) with batch_size 1 or N, or shape (M, P, 3) \ with batch_size 1; got points of shape %r and batch_size %r" + ) raise ValueError(msg % (points.shape, N)) if N == 1: diff --git a/pytorch3d/renderer/implicit/utils.py b/pytorch3d/renderer/implicit/utils.py index bd6bcc31..211f46b2 100644 --- a/pytorch3d/renderer/implicit/utils.py +++ b/pytorch3d/renderer/implicit/utils.py @@ -67,7 +67,7 @@ class HeterogeneousRayBundle: def ray_bundle_to_ray_points( - ray_bundle: Union[RayBundle, HeterogeneousRayBundle] + ray_bundle: Union[RayBundle, HeterogeneousRayBundle], ) -> torch.Tensor: """ Converts rays parametrized with a `ray_bundle` (an instance of the `RayBundle` diff --git a/pytorch3d/renderer/points/pulsar/renderer.py b/pytorch3d/renderer/points/pulsar/renderer.py index 5aceda6f..96c8566b 100644 --- a/pytorch3d/renderer/points/pulsar/renderer.py +++ b/pytorch3d/renderer/points/pulsar/renderer.py @@ -12,6 +12,7 @@ Proper Python support for pytorch requires creating a torch.autograd.function (independent of whether this is being done within the C++ module). This is done here and a torch.nn.Module is exposed for the use in more complex models. """ + import logging import warnings from typing import Optional, Tuple, Union diff --git a/pytorch3d/renderer/splatter_blend.py b/pytorch3d/renderer/splatter_blend.py index e753d29a..f0781a10 100644 --- a/pytorch3d/renderer/splatter_blend.py +++ b/pytorch3d/renderer/splatter_blend.py @@ -133,8 +133,7 @@ def _get_splat_kernel_normalization( epsilon = 0.05 normalization_constant = torch.exp( # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`. - -(offsets**2).sum(dim=1) - / (2 * sigma**2) + -(offsets**2).sum(dim=1) / (2 * sigma**2) ).sum() # We add an epsilon to the normalization constant to ensure the gradient will travel diff --git a/pytorch3d/renderer/utils.py b/pytorch3d/renderer/utils.py index ac7e8c85..71cb3920 100644 --- a/pytorch3d/renderer/utils.py +++ b/pytorch3d/renderer/utils.py @@ -114,7 +114,6 @@ class TensorProperties(nn.Module): self.device = make_device(device) self._N = 0 if kwargs is not None: - # broadcast all inputs which are float/int/list/tuple/tensor/array # set as attributes anything else e.g. strings, bools args_to_broadcast = {} @@ -439,7 +438,7 @@ def ndc_to_grid_sample_coords( def parse_image_size( - image_size: Union[List[int], Tuple[int, int], int] + image_size: Union[List[int], Tuple[int, int], int], ) -> Tuple[int, int]: """ Args: diff --git a/pytorch3d/structures/meshes.py b/pytorch3d/structures/meshes.py index 53f3f454..1f9e219f 100644 --- a/pytorch3d/structures/meshes.py +++ b/pytorch3d/structures/meshes.py @@ -1531,7 +1531,6 @@ class Meshes: def sample_textures(self, fragments): if self.textures is not None: - # Check dimensions of textures match that of meshes shape_ok = self.textures.check_shapes(self._N, self._V, self._F) if not shape_ok: diff --git a/pytorch3d/structures/pointclouds.py b/pytorch3d/structures/pointclouds.py index f699881c..0226d4bc 100644 --- a/pytorch3d/structures/pointclouds.py +++ b/pytorch3d/structures/pointclouds.py @@ -1274,7 +1274,7 @@ def join_pointclouds_as_batch(pointclouds: Sequence[Pointclouds]) -> Pointclouds def join_pointclouds_as_scene( - pointclouds: Union[Pointclouds, List[Pointclouds]] + pointclouds: Union[Pointclouds, List[Pointclouds]], ) -> Pointclouds: """ Joins a batch of point cloud in the form of a Pointclouds object or a list of Pointclouds diff --git a/pytorch3d/vis/plotly_vis.py b/pytorch3d/vis/plotly_vis.py index bb15c764..595a7b54 100644 --- a/pytorch3d/vis/plotly_vis.py +++ b/pytorch3d/vis/plotly_vis.py @@ -311,9 +311,7 @@ def plot_scene( ) else: msg = "Invalid number {} of viewpoint cameras were provided. Either 1 \ - or {} cameras are required".format( - len(viewpoint_cameras), len(subplots) - ) + or {} cameras are required".format(len(viewpoint_cameras), len(subplots)) warnings.warn(msg) for subplot_idx in range(len(subplots)): diff --git a/tests/benchmarks/bm_ball_query.py b/tests/benchmarks/bm_ball_query.py index 73aefd0a..80d6db53 100644 --- a/tests/benchmarks/bm_ball_query.py +++ b/tests/benchmarks/bm_ball_query.py @@ -11,7 +11,6 @@ from tests.test_ball_query import TestBallQuery def bm_ball_query() -> None: - backends = ["cpu", "cuda:0"] kwargs_list = [] diff --git a/tests/benchmarks/bm_cameras_alignment.py b/tests/benchmarks/bm_cameras_alignment.py index 22dd1570..75e4e9ae 100644 --- a/tests/benchmarks/bm_cameras_alignment.py +++ b/tests/benchmarks/bm_cameras_alignment.py @@ -11,7 +11,6 @@ from tests.test_cameras_alignment import TestCamerasAlignment def bm_cameras_alignment() -> None: - case_grid = { "batch_size": [10, 100, 1000], "mode": ["centers", "extrinsics"], diff --git a/tests/benchmarks/bm_knn.py b/tests/benchmarks/bm_knn.py index f6ffa5e8..918ea567 100644 --- a/tests/benchmarks/bm_knn.py +++ b/tests/benchmarks/bm_knn.py @@ -11,7 +11,6 @@ from tests.test_knn import TestKNN def bm_knn() -> None: - backends = ["cpu", "cuda:0"] kwargs_list = [] diff --git a/tests/benchmarks/bm_point_mesh_distance.py b/tests/benchmarks/bm_point_mesh_distance.py index bc1da128..1ebeaa64 100644 --- a/tests/benchmarks/bm_point_mesh_distance.py +++ b/tests/benchmarks/bm_point_mesh_distance.py @@ -12,7 +12,6 @@ from tests.test_point_mesh_distance import TestPointMeshDistance def bm_point_mesh_distance() -> None: - backend = ["cuda:0"] kwargs_list = [] diff --git a/tests/benchmarks/bm_points_alignment.py b/tests/benchmarks/bm_points_alignment.py index 842773fb..25c6c1a5 100644 --- a/tests/benchmarks/bm_points_alignment.py +++ b/tests/benchmarks/bm_points_alignment.py @@ -12,7 +12,6 @@ from tests.test_points_alignment import TestCorrespondingPointsAlignment, TestIC def bm_iterative_closest_point() -> None: - case_grid = { "batch_size": [1, 10], "dim": [3, 20], @@ -43,7 +42,6 @@ def bm_iterative_closest_point() -> None: def bm_corresponding_points_alignment() -> None: - case_grid = { "allow_reflection": [True, False], "batch_size": [1, 10, 100], diff --git a/tests/benchmarks/bm_pulsar.py b/tests/benchmarks/bm_pulsar.py index 74110ef1..157d04a2 100755 --- a/tests/benchmarks/bm_pulsar.py +++ b/tests/benchmarks/bm_pulsar.py @@ -5,6 +5,7 @@ # LICENSE file in the root directory of this source tree. """Test render speed.""" + import logging import sys from os import path diff --git a/tests/benchmarks/bm_sample_pdf.py b/tests/benchmarks/bm_sample_pdf.py index 0f94df8f..f2c3888d 100644 --- a/tests/benchmarks/bm_sample_pdf.py +++ b/tests/benchmarks/bm_sample_pdf.py @@ -11,7 +11,6 @@ from tests.test_sample_pdf import TestSamplePDF def bm_sample_pdf() -> None: - backends = ["python_cuda", "cuda", "python_cpu", "cpu"] kwargs_list = [] diff --git a/tests/benchmarks/bm_sample_points_from_meshes.py b/tests/benchmarks/bm_sample_points_from_meshes.py index 480e7eb9..27c1484e 100644 --- a/tests/benchmarks/bm_sample_points_from_meshes.py +++ b/tests/benchmarks/bm_sample_points_from_meshes.py @@ -13,7 +13,6 @@ from tests.test_sample_points_from_meshes import TestSamplePoints def bm_sample_points() -> None: - backend = ["cpu"] if torch.cuda.is_available(): backend.append("cuda:0") diff --git a/tests/implicitron/test_config.py b/tests/implicitron/test_config.py index 2ae4f4a1..f55acac1 100644 --- a/tests/implicitron/test_config.py +++ b/tests/implicitron/test_config.py @@ -576,7 +576,6 @@ class TestConfig(unittest.TestCase): a: int = 9 for Unprocessed in [UnprocessedConfigurable, UnprocessedReplaceable]: - self.assertFalse(_is_actually_dataclass(Unprocessed)) unprocessed = Unprocessed() self.assertTrue(_is_actually_dataclass(Unprocessed)) diff --git a/tests/implicitron/test_evaluation.py b/tests/implicitron/test_evaluation.py index 400d7835..ee0edc51 100644 --- a/tests/implicitron/test_evaluation.py +++ b/tests/implicitron/test_evaluation.py @@ -71,7 +71,6 @@ class TestEvaluation(unittest.TestCase): for diff in 10 ** torch.linspace(-5, 0, 6): for crop in (0, 5): - pred = gt + (torch.rand_like(gt) - 0.5) * 2 * diff # scaled prediction test diff --git a/tests/implicitron/test_forward_pass.py b/tests/implicitron/test_forward_pass.py index 64c9a1d5..32e726a8 100644 --- a/tests/implicitron/test_forward_pass.py +++ b/tests/implicitron/test_forward_pass.py @@ -74,7 +74,6 @@ class TestGenericModel(unittest.TestCase): eval_test: bool = True, bw_test: bool = True, ): - R, T = look_at_view_transform(azim=torch.rand(n_train_cameras) * 360) cameras = PerspectiveCameras(R=R, T=T, device=device) diff --git a/tests/implicitron/test_json_index_dataset_provider_v2.py b/tests/implicitron/test_json_index_dataset_provider_v2.py index 456b44fa..7f74cf19 100644 --- a/tests/implicitron/test_json_index_dataset_provider_v2.py +++ b/tests/implicitron/test_json_index_dataset_provider_v2.py @@ -171,9 +171,7 @@ def _make_random_json_dataset_map_provider_v2_data( Image.fromarray( (mask * 255.0).astype(np.uint8), mode="L", - ).convert( - "L" - ).save(mask_path) + ).convert("L").save(mask_path) fa = FrameAnnotation( sequence_name=seq_name, diff --git a/tests/implicitron/test_model_visualize.py b/tests/implicitron/test_model_visualize.py index 2c9b1f9a..901951a6 100644 --- a/tests/implicitron/test_model_visualize.py +++ b/tests/implicitron/test_model_visualize.py @@ -65,7 +65,6 @@ class TestModelVisualize(unittest.TestCase): visdom_show_preds = Visdom().check_connection() for load_dataset_pointcloud in [True, False]: - model = _PointcloudRenderingModel( train_dataset, show_sequence_name, diff --git a/tests/implicitron/test_viewsampling.py b/tests/implicitron/test_viewsampling.py index 4094bf4a..a74b6c46 100644 --- a/tests/implicitron/test_viewsampling.py +++ b/tests/implicitron/test_viewsampling.py @@ -142,7 +142,6 @@ class TestViewsampling(unittest.TestCase): expand_args_fields(ViewSampler) for masked_sampling in (True, False): - view_sampler = ViewSampler(masked_sampling=masked_sampling) feats_sampled, masks_sampled = view_sampler( diff --git a/tests/implicitron/test_voxel_grids.py b/tests/implicitron/test_voxel_grids.py index 2b47de7f..6be65439 100644 --- a/tests/implicitron/test_voxel_grids.py +++ b/tests/implicitron/test_voxel_grids.py @@ -275,7 +275,6 @@ class TestVoxelGrids(TestCaseMixin, unittest.TestCase): return torch.cat(result) def test_interpolation(self): - with self.subTest("1D interpolation"): points = self.get_random_normalized_points( n_grids=4, n_points=5, dimension=1 diff --git a/tests/pulsar/create_multiview.py b/tests/pulsar/create_multiview.py index 7dfc9c5b..ae36cf79 100644 --- a/tests/pulsar/create_multiview.py +++ b/tests/pulsar/create_multiview.py @@ -6,6 +6,7 @@ # LICENSE file in the root directory of this source tree. """Create multiview data.""" + import sys from os import path diff --git a/tests/pulsar/test_channels.py b/tests/pulsar/test_channels.py index adbf4e56..4b9aa946 100644 --- a/tests/pulsar/test_channels.py +++ b/tests/pulsar/test_channels.py @@ -5,6 +5,7 @@ # LICENSE file in the root directory of this source tree. """Test number of channels.""" + import logging import sys import unittest diff --git a/tests/pulsar/test_depth.py b/tests/pulsar/test_depth.py index 023571ac..31d0564d 100644 --- a/tests/pulsar/test_depth.py +++ b/tests/pulsar/test_depth.py @@ -5,6 +5,7 @@ # LICENSE file in the root directory of this source tree. """Test the sorting of the closest spheres.""" + import logging import os import sys diff --git a/tests/pulsar/test_forward.py b/tests/pulsar/test_forward.py index d8cddbf3..952e6779 100644 --- a/tests/pulsar/test_forward.py +++ b/tests/pulsar/test_forward.py @@ -5,6 +5,7 @@ # LICENSE file in the root directory of this source tree. """Basic rendering test.""" + import logging import os import sys diff --git a/tests/pulsar/test_hands.py b/tests/pulsar/test_hands.py index 128b2285..83dd9665 100644 --- a/tests/pulsar/test_hands.py +++ b/tests/pulsar/test_hands.py @@ -5,6 +5,7 @@ # LICENSE file in the root directory of this source tree. """Test right hand/left hand system compatibility.""" + import logging import sys import unittest diff --git a/tests/pulsar/test_ortho.py b/tests/pulsar/test_ortho.py index 3da5ea70..fc6fef7f 100644 --- a/tests/pulsar/test_ortho.py +++ b/tests/pulsar/test_ortho.py @@ -5,6 +5,7 @@ # LICENSE file in the root directory of this source tree. """Tests for the orthogonal projection.""" + import logging import sys import unittest diff --git a/tests/pulsar/test_small_spheres.py b/tests/pulsar/test_small_spheres.py index d1282c70..c8488de6 100644 --- a/tests/pulsar/test_small_spheres.py +++ b/tests/pulsar/test_small_spheres.py @@ -6,6 +6,7 @@ # LICENSE file in the root directory of this source tree. """Test right hand/left hand system compatibility.""" + import sys import unittest from os import path diff --git a/tests/test_blending.py b/tests/test_blending.py index 7f73ae9d..f24502de 100644 --- a/tests/test_blending.py +++ b/tests/test_blending.py @@ -401,7 +401,10 @@ class TestBlending(TestCaseMixin, unittest.TestCase): dists1 = torch.randn(size=(N, S, S, K), requires_grad=True, device=device) zbuf = torch.randn(size=(N, S, S, K), requires_grad=True, device=device) fragments = Fragments( - pix_to_face=pix_to_face, bary_coords=empty, zbuf=zbuf, dists=dists1 # dummy + pix_to_face=pix_to_face, + bary_coords=empty, + zbuf=zbuf, + dists=dists1, # dummy ) blend_params = BlendParams(sigma=1e-3) diff --git a/tests/test_cameras.py b/tests/test_cameras.py index c953e457..b13c514e 100644 --- a/tests/test_cameras.py +++ b/tests/test_cameras.py @@ -495,8 +495,8 @@ class TestCamerasCommon(TestCaseMixin, unittest.TestCase): screen_cam_params["image_size"] = image_size screen_cam_params["focal_length"] = fcl * scale screen_cam_params["principal_point"] = ( - image_size[:, [1, 0]] - ) / 2.0 - prc * scale + (image_size[:, [1, 0]]) / 2.0 - prc * scale + ) screen_cam_params["in_ndc"] = False else: raise ValueError(str(cam_type)) @@ -615,7 +615,6 @@ class TestCamerasCommon(TestCaseMixin, unittest.TestCase): OrthographicCameras, PerspectiveCameras, ): - # init the cameras cameras = init_random_cameras(cam_type, batch_size) # xyz - the ground truth point cloud diff --git a/tests/test_compositing.py b/tests/test_compositing.py index 5101ad1e..ec5e9e11 100644 --- a/tests/test_compositing.py +++ b/tests/test_compositing.py @@ -17,7 +17,6 @@ from .common_testing import get_random_cuda_device, TestCaseMixin class TestAccumulatePoints(TestCaseMixin, unittest.TestCase): - # NAIVE PYTHON IMPLEMENTATIONS (USED FOR TESTING) @staticmethod def accumulate_alphacomposite_python(points_idx, alphas, features): @@ -63,7 +62,6 @@ class TestAccumulatePoints(TestCaseMixin, unittest.TestCase): for c in range(0, C): for i in range(0, W): for j in range(0, H): - for k in range(0, K): n_idx = points_idx[b, k, j, i] @@ -237,16 +235,16 @@ class TestAccumulatePoints(TestCaseMixin, unittest.TestCase): [ # fmt: off [ - [0, 0, 0, 0], # noqa: E241, E201 + [0, 0, 0, 0], # noqa: E241, E201 [0, -1, -1, -1], # noqa: E241, E201 - [0, 1, 1, 0], # noqa: E241, E201 - [0, 0, 0, 0], # noqa: E241, E201 + [0, 1, 1, 0], # noqa: E241, E201 + [0, 0, 0, 0], # noqa: E241, E201 ], [ - [2, 2, 2, 2], # noqa: E241, E201 - [2, 3, 3, 2], # noqa: E241, E201 - [2, 3, 3, 2], # noqa: E241, E201 - [2, 2, -1, 2], # noqa: E241, E201 + [2, 2, 2, 2], # noqa: E241, E201 + [2, 3, 3, 2], # noqa: E241, E201 + [2, 3, 3, 2], # noqa: E241, E201 + [2, 2, -1, 2], # noqa: E241, E201 ], # fmt: on ] diff --git a/tests/test_iou_box3d.py b/tests/test_iou_box3d.py index f5f2b9e4..1a221580 100644 --- a/tests/test_iou_box3d.py +++ b/tests/test_iou_box3d.py @@ -95,7 +95,6 @@ class TestIoU3D(TestCaseMixin, unittest.TestCase): return ious def _test_iou(self, overlap_fn, device): - box1 = torch.tensor( UNIT_BOX, dtype=torch.float32, diff --git a/tests/test_marching_cubes.py b/tests/test_marching_cubes.py index 324ef8d0..b48ed038 100644 --- a/tests/test_marching_cubes.py +++ b/tests/test_marching_cubes.py @@ -23,7 +23,6 @@ def convert_to_local(verts, volume_dim): class TestCubeConfiguration(TestCaseMixin, unittest.TestCase): - # Test single cubes. Each case corresponds to the corresponding # cube vertex configuration in each case here (0-indexed): # https://en.wikipedia.org/wiki/Marching_cubes#/media/File:MarchingCubes.svg diff --git a/tests/test_meshes.py b/tests/test_meshes.py index 564694a5..71d6ae67 100644 --- a/tests/test_meshes.py +++ b/tests/test_meshes.py @@ -335,7 +335,6 @@ class TestMeshes(TestCaseMixin, unittest.TestCase): Meshes(verts=verts_padded, faces=faces_padded) def test_simple_random_meshes(self): - # Define the test mesh object either as a list or tensor of faces/verts. for lists_to_tensors in (False, True): N = 10 @@ -1120,7 +1119,6 @@ class TestMeshes(TestCaseMixin, unittest.TestCase): self.assertClose(face_areas, expected_areas) def test_compute_normals(self): - # Simple case with one mesh where normals point in either +/- ijk verts = torch.tensor( [ diff --git a/tests/test_pointclouds.py b/tests/test_pointclouds.py index 25289263..07a36ec1 100644 --- a/tests/test_pointclouds.py +++ b/tests/test_pointclouds.py @@ -1072,7 +1072,6 @@ class TestPointclouds(TestCaseMixin, unittest.TestCase): for with_normals in (True, False): for run_padded in (True, False): for run_packed in (True, False): - clouds = TestPointclouds.init_cloud( 3, 100, diff --git a/tests/test_points_alignment.py b/tests/test_points_alignment.py index 39b07a2a..62da8672 100644 --- a/tests/test_points_alignment.py +++ b/tests/test_points_alignment.py @@ -56,7 +56,6 @@ class TestICP(TestCaseMixin, unittest.TestCase): use_pointclouds=False, estimate_scale=False, ): - device = torch.device("cuda:0") # initialize a ground truth point cloud @@ -433,7 +432,6 @@ class TestCorrespondingPointsAlignment(TestCaseMixin, unittest.TestCase): reflect=False, random_weights=False, ): - device = torch.device("cuda:0") # initialize a ground truth point cloud diff --git a/tests/test_points_to_volumes.py b/tests/test_points_to_volumes.py index f31088dc..f1d24e72 100644 --- a/tests/test_points_to_volumes.py +++ b/tests/test_points_to_volumes.py @@ -258,9 +258,7 @@ class TestPointsToVolumes(TestCaseMixin, unittest.TestCase): batch_size = 4 for volume_size in ([25, 25, 25], [30, 25, 15]): - for python, interp_mode in product([True, False], ["trilinear", "nearest"]): - (pointclouds, initial_volumes) = init_volume_boundary_pointcloud( volume_size=volume_size, n_points=int(1e5), diff --git a/tests/test_r2n2.py b/tests/test_r2n2.py index 25966631..b892e89a 100644 --- a/tests/test_r2n2.py +++ b/tests/test_r2n2.py @@ -7,6 +7,7 @@ """ Sanity checks for loading R2N2. """ + import json import os import unittest diff --git a/tests/test_raysampling.py b/tests/test_raysampling.py index db773d95..3946a351 100644 --- a/tests/test_raysampling.py +++ b/tests/test_raysampling.py @@ -210,13 +210,11 @@ class TestRaysampling(TestCaseMixin, unittest.TestCase): device = torch.device("cuda") for n_pts_per_ray in (100, 1): - for raysampler_type in ( MonteCarloRaysampler, MultinomialRaysampler, NDCMultinomialRaysampler, ): - raysampler = TestRaysampling.init_raysampler( raysampler_type=raysampler_type, min_x=min_x, @@ -258,7 +256,6 @@ class TestRaysampling(TestCaseMixin, unittest.TestCase): OrthographicCameras, PerspectiveCameras, ): - # init a batch of random cameras cameras = init_random_cameras( cam_type, batch_size, random_z=True diff --git a/tests/test_render_implicit.py b/tests/test_render_implicit.py index 4609cbc5..dd57abb9 100644 --- a/tests/test_render_implicit.py +++ b/tests/test_render_implicit.py @@ -215,9 +215,7 @@ class TestRenderImplicit(TestCaseMixin, unittest.TestCase): volumetric_function=spherical_volumetric_function, sphere_centroid=sphere_centroid, sphere_diameter=sphere_diameter, - )[ - 0 - ] + )[0] # check that the renderer does not erase gradients loss = images_opacities.sum() diff --git a/tests/test_render_meshes.py b/tests/test_render_meshes.py index 31627d99..d9782490 100644 --- a/tests/test_render_meshes.py +++ b/tests/test_render_meshes.py @@ -8,6 +8,7 @@ """ Sanity checks for output images from the renderer. """ + import os import unittest from collections import namedtuple diff --git a/tests/test_render_meshes_clipped.py b/tests/test_render_meshes_clipped.py index 28241fe1..b47eef56 100644 --- a/tests/test_render_meshes_clipped.py +++ b/tests/test_render_meshes_clipped.py @@ -12,6 +12,7 @@ behind the image plane. These faces are clipped and then rasterized. See pytorch3d/renderer/mesh/clip.py for more details about the clipping process. """ + import unittest import imageio diff --git a/tests/test_render_multigpu.py b/tests/test_render_multigpu.py index 987e19fc..6dd82568 100644 --- a/tests/test_render_multigpu.py +++ b/tests/test_render_multigpu.py @@ -134,7 +134,6 @@ class TestRenderMeshesMultiGPU(TestCaseMixin, unittest.TestCase): self.renderer = self.init_render(device) def init_render(self, device): - cameras = FoVPerspectiveCameras().to(device) raster_settings = RasterizationSettings( image_size=128, blur_radius=0.0, faces_per_pixel=1 diff --git a/tests/test_render_points.py b/tests/test_render_points.py index 84dc70dd..7a4ee322 100644 --- a/tests/test_render_points.py +++ b/tests/test_render_points.py @@ -8,6 +8,7 @@ """ Sanity checks for output images from the pointcloud renderer. """ + import unittest import warnings from os import path @@ -220,7 +221,8 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase): # znear and zfar is required in this case. self.assertRaises( ValueError, - lambda renderer=renderer, pointclouds=pointclouds: renderer.forward( + lambda renderer=renderer, + pointclouds=pointclouds: renderer.forward( point_clouds=pointclouds, gamma=(1e-4,) ), ) @@ -233,7 +235,8 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase): # znear and zfar must be batched. self.assertRaises( TypeError, - lambda renderer=renderer, pointclouds=pointclouds: renderer.forward( + lambda renderer=renderer, + pointclouds=pointclouds: renderer.forward( point_clouds=pointclouds, gamma=(1e-4,), znear=1.0, @@ -242,7 +245,8 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase): ) self.assertRaises( TypeError, - lambda renderer=renderer, pointclouds=pointclouds: renderer.forward( + lambda renderer=renderer, + pointclouds=pointclouds: renderer.forward( point_clouds=pointclouds, gamma=(1e-4,), znear=(1.0,), @@ -253,7 +257,8 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase): # gamma must be batched. self.assertRaises( TypeError, - lambda renderer=renderer, pointclouds=pointclouds: renderer.forward( + lambda renderer=renderer, + pointclouds=pointclouds: renderer.forward( point_clouds=pointclouds, gamma=1e-4 ), ) @@ -262,7 +267,8 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase): renderer.rasterizer.raster_settings.image_size = 0 self.assertRaises( ValueError, - lambda renderer=renderer, pointclouds=pointclouds: renderer.forward( + lambda renderer=renderer, + pointclouds=pointclouds: renderer.forward( point_clouds=pointclouds, gamma=(1e-4,) ), ) @@ -372,7 +378,6 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase): self.assertClose(rgb, image_ref) def test_compositor_background_color_rgba(self): - N, H, W, K, C, P = 1, 15, 15, 20, 4, 225 ptclds = torch.randn((C, P)) alphas = torch.rand((N, K, H, W)) @@ -385,7 +390,6 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase): ] for compositor_class, composite_func in compositor_funcs: - compositor = compositor_class(background_color) # run the forward method to generate masked images @@ -423,7 +427,6 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase): ) def test_compositor_background_color_rgb(self): - N, H, W, K, C, P = 1, 15, 15, 20, 3, 225 ptclds = torch.randn((C, P)) alphas = torch.rand((N, K, H, W)) @@ -436,7 +439,6 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase): ] for compositor_class, composite_func in compositor_funcs: - compositor = compositor_class(background_color) # run the forward method to generate masked images diff --git a/tests/test_render_volumes.py b/tests/test_render_volumes.py index 5c47ae9c..67660ede 100644 --- a/tests/test_render_volumes.py +++ b/tests/test_render_volumes.py @@ -308,7 +308,6 @@ class TestRenderVolumes(TestCaseMixin, unittest.TestCase): # init the boundary volume for shape in ("sphere", "cube"): - if not DEBUG and shape == "cube": # do not run numeric checks for the cube as the # differences in rendering equations make the renders incomparable @@ -515,7 +514,6 @@ class TestRenderVolumes(TestCaseMixin, unittest.TestCase): for shape in ("sphere", "cube"): for sample_mode in ("bilinear", "nearest"): - volumes = init_boundary_volume( volume_size=volume_size, batch_size=n_frames, shape=shape )[0] @@ -593,7 +591,6 @@ class TestRenderVolumes(TestCaseMixin, unittest.TestCase): for volume_size in ([25, 25, 25],): for sample_mode in ("bilinear", "nearest"): - volume_translation = torch.zeros(4, 3) volume_translation.requires_grad = True volumes, volume_voxel_size, _ = init_boundary_volume( diff --git a/tests/test_rendering_utils.py b/tests/test_rendering_utils.py index fca51d9e..b5895c92 100644 --- a/tests/test_rendering_utils.py +++ b/tests/test_rendering_utils.py @@ -231,7 +231,6 @@ class TestTensorProperties(TestCaseMixin, unittest.TestCase): # check both H > W and W > H for flip_axes in [False, True]: - # non-batched version for xy_ndc, xy_gs in xy_ndc_gs: xy_gs_predicted = ndc_to_grid_sample_coords( diff --git a/tests/test_sample_points_from_meshes.py b/tests/test_sample_points_from_meshes.py index afe4a3a1..3f48a20e 100644 --- a/tests/test_sample_points_from_meshes.py +++ b/tests/test_sample_points_from_meshes.py @@ -301,7 +301,6 @@ class TestSamplePoints(TestCaseMixin, unittest.TestCase): ) def test_outputs(self): - for add_texture in (True, False): meshes = init_meshes(device=torch.device("cuda:0"), add_texture=add_texture) out1 = sample_points_from_meshes(meshes, num_samples=100) diff --git a/tests/test_shapenet_core.py b/tests/test_shapenet_core.py index 63f1c855..87b0f530 100644 --- a/tests/test_shapenet_core.py +++ b/tests/test_shapenet_core.py @@ -7,6 +7,7 @@ """ Sanity checks for loading ShapeNetCore. """ + import os import unittest diff --git a/tests/test_struct_utils.py b/tests/test_struct_utils.py index a40a6548..67b3b27b 100644 --- a/tests/test_struct_utils.py +++ b/tests/test_struct_utils.py @@ -105,7 +105,6 @@ class TestStructUtils(TestCaseMixin, unittest.TestCase): ndim = 2 for ndim in (2, 3, 4): - dims = [K] * ndim x = torch.rand([N] + dims, device=device) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index 6851afbf..230af6b6 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -308,9 +308,7 @@ class TestTransform(TestCaseMixin, unittest.TestCase): t1._matrix = torch.FloatTensor(persp_proj) points = torch.tensor( [[0.0, 1.0, 0.0], [0.0, 0.0, 1e-5], [-1.0, 0.0, 1e-5]] - ).view( - 1, 3, 3 - ) # a set of points with z-coord very close to 0 + ).view(1, 3, 3) # a set of points with z-coord very close to 0 proj = t1.transform_points(points) proj_eps = t1.transform_points(points, eps=1e-4) @@ -323,7 +321,6 @@ class TestTransform(TestCaseMixin, unittest.TestCase): # generate a random chain of transforms for _ in range(10): # 10 different tries - # list of transform matrices ts = [] diff --git a/tests/test_volumes.py b/tests/test_volumes.py index 76a30413..23cbe323 100644 --- a/tests/test_volumes.py +++ b/tests/test_volumes.py @@ -66,7 +66,6 @@ class TestVolumes(TestCaseMixin, unittest.TestCase): volume_size=(10, 13, 8), dtype=torch.float32, ): - device = torch.device("cuda:0") # make sure we have at least 3 volumes to prevent indexing crash @@ -94,7 +93,6 @@ class TestVolumes(TestCaseMixin, unittest.TestCase): for features_, densities_ in zip( (None, features, features_list), (densities, densities, densities_list) ): - # init the volume structure v = Volumes( features=features_, @@ -205,7 +203,6 @@ class TestVolumes(TestCaseMixin, unittest.TestCase): # try for 10 sets of different random sizes/centers/voxel_sizes for _ in range(10): - size = torch.randint(high=10, size=(3,), low=3).tolist() densities = torch.randn( @@ -433,7 +430,6 @@ class TestVolumes(TestCaseMixin, unittest.TestCase): # try for 10 sets of different random sizes/centers/voxel_sizes for _ in range(10): - size = torch.randint(high=10, size=(3,), low=3).tolist() center = torch.randn(num_volumes, 3, dtype=torch.float32, device=device) @@ -449,7 +445,6 @@ class TestVolumes(TestCaseMixin, unittest.TestCase): num_volumes, 3, size, num_channels, device, rand_sizes=None )[0], ): - # init the volume structure v = Volumes( densities=densities, @@ -794,9 +789,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase): size=[num_volumes + 1, num_channels, *size], device=device, dtype=torch.float32, - ).unbind( - 0 - ), # list with diff batch size + ).unbind(0), # list with diff batch size torch.randn( size=[num_volumes + 1, num_channels, *size], device=device, @@ -806,9 +799,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase): size=[num_volumes, num_channels, *diff_size], device=device, dtype=torch.float32, - ).unbind( - 0 - ), # list with different size + ).unbind(0), # list with different size torch.randn( size=[num_volumes, num_channels, *diff_size], device=device, @@ -823,9 +814,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase): size=[num_volumes, num_channels, *size], device=diff_device, dtype=torch.float32, - ).unbind( - 0 - ), # list with different device + ).unbind(0), # list with different device ] # good ways to define features @@ -834,9 +823,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase): size=[num_volumes, num_channels, *size], device=device, dtype=torch.float32, - ).unbind( - 0 - ), # list of features of correct size + ).unbind(0), # list of features of correct size torch.randn( size=[num_volumes, num_channels, *size], device=device, @@ -872,9 +859,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase): size=[num_volumes, num_channels, *size], device=device, dtype=torch.float32, - ).unbind( - 0 - ), # list of features + ).unbind(0), # list of features None, # no features ] @@ -890,9 +875,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase): ), # 4 dims torch.randn( size=[num_volumes, *size], device=device, dtype=torch.float32 - ).unbind( - 0 - ), # list of 4 dim tensors + ).unbind(0), # list of 4 dim tensors ] # all ways to define densities @@ -902,9 +885,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase): ), # padded tensor torch.randn( size=[num_volumes, 1, *size], device=device, dtype=torch.float32 - ).unbind( - 0 - ), # list of densities + ).unbind(0), # list of densities ] # bad ways to define densities @@ -915,9 +896,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase): ), # 6-dim tensor torch.randn( size=[num_volumes, 1, 1, *size], device=device, dtype=torch.float32 - ).unbind( - 0 - ), # list of 5-dim densities + ).unbind(0), # list of 5-dim densities ] # all possible ways to define the voxels sizes