Switch to ruff (#1939)

* `isort` -> `ruff`

* `pylint` -> `ruff`

* Remove line

* More minor cleanup

* Better documentation for rules we are enabling

* Fix gitignore, run black

* vscode settings

---------

Co-authored-by: Matt Tancik <mattt4001@gmail.com>
This commit is contained in:
Brent YiandMatt Tancik authored and GitHub committed 2023-05-17 10:08:14 -07:00
1 parent 814db32ec4
commit d542646c72
79 files changed
+158 -237

No files matched your search

@@ -278,18 +278,18 @@ class DataManager(nn.Module):
"""Returns the number of rays per batch for evaluation."""
raise NotImplementedError
def get_datapath(self) -> Optional[Path]: # pylint:disable=no-self-use
def get_datapath(self) -> Optional[Path]:
"""Returns the path to the data. This is used to determine where to save camera paths."""
return None
def get_training_callbacks( # pylint:disable=no-self-use
self, training_callback_attributes: TrainingCallbackAttributes # pylint: disable=unused-argument
def get_training_callbacks(
self, training_callback_attributes: TrainingCallbackAttributes
) -> List[TrainingCallback]:
"""Returns a list of callbacks to be used during training."""
return []
@abstractmethod
def get_param_groups(self) -> Dict[str, List[Parameter]]: # pylint: disable=no-self-use
def get_param_groups(self) -> Dict[str, List[Parameter]]:
"""Get the param groups for the data manager.
Returns:
@@ -338,7 +338,7 @@ class VanillaDataManagerConfig(DataManagerConfig):
TDataset = TypeVar("TDataset", bound=InputDataset, default=InputDataset)
class VanillaDataManager(DataManager, Generic[TDataset]): # pylint: disable=abstract-method
class VanillaDataManager(DataManager, Generic[TDataset]):
"""Basic stored data manager implementation.
This is pretty much a port over from our old dataloading utilities, and is a little jank
@@ -365,7 +365,7 @@ class VanillaDataManager(DataManager, Generic[TDataset]): # pylint: disable=abs
test_mode: Literal["test", "val", "inference"] = "val",
world_size: int = 1,
local_rank: int = 0,
**kwargs, # pylint: disable=unused-argument
**kwargs,
):
self.dataset_type: Type[TDataset] = kwargs.get("_dataset_type", getattr(TDataset, "__default__"))
self.config = config
@@ -419,9 +419,7 @@ class VanillaDataManager(DataManager, Generic[TDataset]): # pylint: disable=abs
scale_factor=self.config.camera_res_scale_factor,
)
def _get_pixel_sampler( # pylint: disable=no-self-use
self, dataset: TDataset, *args: Any, **kwargs: Any
) -> PixelSampler:
def _get_pixel_sampler(self, dataset: TDataset, *args: Any, **kwargs: Any) -> PixelSampler:
"""Infer pixel sampler to use."""
if self.config.patch_size > 1:
return PatchPixelSampler(*args, **kwargs, patch_size=self.config.patch_size)
@@ -530,7 +528,7 @@ class VanillaDataManager(DataManager, Generic[TDataset]): # pylint: disable=abs
def get_datapath(self) -> Path:
return self.config.dataparser.data
def get_param_groups(self) -> Dict[str, List[Parameter]]: # pylint: disable=no-self-use
def get_param_groups(self) -> Dict[str, List[Parameter]]:
"""Get the param groups for the data manager.
Returns:
A list of dictionaries containing the data manager's param groups.
@@ -72,8 +72,6 @@ class Nerfstudio(DataParser):
downscale_factor: Optional[int] = None
def _generate_dataparser_outputs(self, split="train"):
# pylint: disable=too-many-statements
assert self.config.data.exists(), f"Data directory {self.config.data} does not exist."
if self.config.data.suffix == ".json":
@@ -85,8 +85,6 @@ class NuScenes(DataParser):
config: NuScenesDataParserConfig
def _generate_dataparser_outputs(self, split="train"):
# pylint: disable=too-many-statements
nusc = NuScenesDatabase(
version=self.config.version,
dataroot=str(self.config.data_dir.absolute()),
@@ -77,7 +77,6 @@ class Phototourism(DataParser):
super().__init__(config=config)
self.data: Path = config.data
# pylint: disable=too-many-statements
def _generate_dataparser_outputs(self, split="train"):
image_filenames = []
poses = []
@@ -61,7 +61,7 @@ class SDFStudio(DataParser):
config: SDFStudioDataParserConfig
def _generate_dataparser_outputs(self, split="train"): # pylint: disable=unused-argument,too-many-statements
def _generate_dataparser_outputs(self, split="train"):
# load meta data
meta = load_from_json(self.config.data / "meta_data.json")
@@ -61,7 +61,7 @@ class Sitcoms3D(DataParser):
config: Sitcoms3DDataParserConfig
def _generate_dataparser_outputs(self, split="train"): # pylint: disable=unused-argument,too-many-statements
def _generate_dataparser_outputs(self, split="train"):
cameras_json = load_from_json(self.config.data / "cameras.json")
frames = cameras_json["frames"]
bbox = torch.tensor(cameras_json["bbox"])
-1
View File
@@ -105,7 +105,6 @@ class InputDataset(Dataset):
data.update(metadata)
return data
# pylint: disable=no-self-use
def get_metadata(self, data: Dict) -> Dict:
"""Method that can be used to process any additional metadata that may be part of the model inputs.
+6 -6
View File
@@ -24,7 +24,7 @@ from jaxtyping import Int
from torch import Tensor
class PixelSampler: # pylint: disable=too-few-public-methods
class PixelSampler:
"""Samples 'pixel_batch's from 'image_batch's.
Args:
@@ -45,7 +45,7 @@ class PixelSampler: # pylint: disable=too-few-public-methods
"""
self.num_rays_per_batch = num_rays_per_batch
def sample_method( # pylint: disable=no-self-use
def sample_method(
self,
batch_size: int,
num_images: int,
@@ -203,7 +203,7 @@ class PixelSampler: # pylint: disable=too-few-public-methods
return pixel_batch
class EquirectangularPixelSampler(PixelSampler): # pylint: disable=too-few-public-methods
class EquirectangularPixelSampler(PixelSampler):
"""Samples 'pixel_batch's from 'image_batch's. Assumes images are
equirectangular and the sampling is done uniformly on the sphere.
@@ -213,7 +213,7 @@ class EquirectangularPixelSampler(PixelSampler): # pylint: disable=too-few-publ
"""
# overrides base method
def sample_method( # pylint: disable=no-self-use
def sample_method(
self,
batch_size: int,
num_images: int,
@@ -244,7 +244,7 @@ class EquirectangularPixelSampler(PixelSampler): # pylint: disable=too-few-publ
return indices
class PatchPixelSampler(PixelSampler): # pylint: disable=too-few-public-methods
class PatchPixelSampler(PixelSampler):
"""Samples 'pixel_batch's from 'image_batch's. Samples square patches
from the images randomly. Useful for patch-based losses.
@@ -269,7 +269,7 @@ class PatchPixelSampler(PixelSampler): # pylint: disable=too-few-public-methods
self.num_rays_per_batch = (num_rays_per_batch // (self.patch_size**2)) * (self.patch_size**2)
# overrides base method
def sample_method( # pylint: disable=no-self-use
def sample_method(
self,
batch_size: int,
num_images: int,
@@ -6,8 +6,6 @@ TODO(1480) Delete this file when moving to pycolmap.
"""
# pylint: disable-all
# Disabling all pylinting since this file is copy-pasted over from COLMAP
# Copyright (c) 2023, ETH Zurich and UNC Chapel Hill.
# All rights reserved.
+3 -7
View File
@@ -26,16 +26,13 @@ import torch.utils.data
from nerfstudio.cameras.cameras import Cameras
# pylint: disable=implicit-str-concat
NERFSTUDIO_COLLATE_ERR_MSG_FORMAT = (
"default_collate: batch must contain tensors, numpy arrays, numbers, " "dicts, lists or anything in {}; found {}"
)
np_str_obj_array_pattern = re.compile(r"[SaUO]")
def nerfstudio_collate( # pylint: disable=too-many-return-statements
batch: Any, extra_mappings: Union[Dict[type, Callable], None] = None
) -> Any:
def nerfstudio_collate(batch: Any, extra_mappings: Union[Dict[type, Callable], None] = None) -> Any:
r"""
This is the default pytorch collate function, but with support for nerfstudio types. All documentation
below is copied straight over from pytorch's default_collate function, python version 3.8.13,
@@ -95,17 +92,16 @@ def nerfstudio_collate( # pylint: disable=too-many-return-statements
extra_mappings = {}
elem = batch[0]
elem_type = type(elem)
if isinstance(elem, torch.Tensor): # pylint: disable=no-else-return
if isinstance(elem, torch.Tensor):
out = None
if torch.utils.data.get_worker_info() is not None:
# If we're in a background process, concatenate directly into a
# shared memory tensor to avoid an extra copy
numel = sum(x.numel() for x in batch)
storage = elem.storage()._new_shared(numel, device=elem.device) # pylint: disable=protected-access
storage = elem.storage()._new_shared(numel, device=elem.device)
out = elem.new(storage).resize_(len(batch), *list(elem.size()))
return torch.stack(batch, 0, out=out)
elif elem_type.__module__ == "numpy" and elem_type.__name__ != "str_" and elem_type.__name__ != "string_":
# pylint: disable=no-else-return, consider-using-in
if elem_type.__name__ == "ndarray" or elem_type.__name__ == "memmap":
# array of string classes and object
if np_str_obj_array_pattern.search(elem.dtype.str) is not None: