From 66cd6817f92d88dbce8ff9a364d2b3bb69102270 Mon Sep 17 00:00:00 2001 From: Justin Kerr Date: Mon, 13 Jan 2025 10:46:11 -0800 Subject: [PATCH] rerun formatting with ruff 0.9.1 (#3569) rerun with ruff 0.9.1 --- .../model_components/visualize_encoders.ipynb | 2 +- nerfstudio/cameras/cameras.py | 18 +++++++------- .../datamanagers/full_images_datamanager.py | 4 ++-- .../data/dataparsers/dycheck_dataparser.py | 2 +- .../data/dataparsers/nerfstudio_dataparser.py | 2 +- .../data/dataparsers/nuscenes_dataparser.py | 6 ++--- nerfstudio/data/datasets/base_dataset.py | 6 ++--- nerfstudio/data/pixel_samplers.py | 6 ++--- nerfstudio/data/utils/nerfstudio_collate.py | 12 ++++++---- nerfstudio/engine/callbacks.py | 6 ++--- nerfstudio/exporter/exporter_utils.py | 6 ++--- nerfstudio/field_components/encodings.py | 6 ++--- nerfstudio/fields/base_field.py | 6 ++--- nerfstudio/model_components/ray_samplers.py | 6 ++--- nerfstudio/models/base_surface_model.py | 6 ++--- nerfstudio/models/tensorf.py | 6 ++--- nerfstudio/pipelines/base_pipeline.py | 6 ++--- nerfstudio/pipelines/dynamic_batch.py | 6 ++--- .../colmap_converter_to_nerfstudio_dataset.py | 8 +++---- nerfstudio/process_data/polycam_utils.py | 4 ++-- nerfstudio/process_data/process_data_utils.py | 4 ++-- nerfstudio/scripts/downloads/download_data.py | 24 +++++++++---------- nerfstudio/scripts/downloads/eyeful_tower.py | 2 +- nerfstudio/scripts/render.py | 8 +++---- nerfstudio/utils/comms.py | 6 ++--- nerfstudio/utils/tensor_dataclass.py | 6 ++--- nerfstudio/utils/writer.py | 2 +- nerfstudio/viewer/viewer_elements.py | 6 ++--- .../viewer_legacy/server/viewer_state.py | 2 +- 29 files changed, 92 insertions(+), 92 deletions(-) diff --git a/docs/nerfology/model_components/visualize_encoders.ipynb b/docs/nerfology/model_components/visualize_encoders.ipynb index b05e2d0ad..aef50799e 100644 --- a/docs/nerfology/model_components/visualize_encoders.ipynb +++ b/docs/nerfology/model_components/visualize_encoders.ipynb @@ -541,7 +541,7 @@ "encoded_values = torch.moveaxis(encoded_values, 2, 0)\n", "\n", "for level in range(levels):\n", - " print(f\"Level: {level+1}\")\n", + " print(f\"Level: {level + 1}\")\n", " media.show_images(encoded_values[level**2 : (level + 1) ** 2, ...], cmap=\"plasma\", border=True)" ] } diff --git a/nerfstudio/cameras/cameras.py b/nerfstudio/cameras/cameras.py index 75f2671b0..b1561e65b 100644 --- a/nerfstudio/cameras/cameras.py +++ b/nerfstudio/cameras/cameras.py @@ -205,9 +205,9 @@ class Cameras(TensorDataclass): elif isinstance(camera_type, int): camera_type = torch.tensor([camera_type], device=self.device) elif isinstance(camera_type, torch.Tensor): - assert not torch.is_floating_point( - camera_type - ), f"camera_type tensor must be of type int, not: {camera_type.dtype}" + assert not torch.is_floating_point(camera_type), ( + f"camera_type tensor must be of type int, not: {camera_type.dtype}" + ) camera_type = camera_type.to(self.device) if camera_type.ndim == 0 or camera_type.shape[-1] != 1: camera_type = camera_type.unsqueeze(-1) @@ -400,14 +400,14 @@ class Cameras(TensorDataclass): # If the camera indices are an int, then we need to make sure that the camera batch is 1D if isinstance(camera_indices, int): - assert ( - len(cameras.shape) == 1 - ), "camera_indices must be a tensor if cameras are batched with more than 1 batch dimension" + assert len(cameras.shape) == 1, ( + "camera_indices must be a tensor if cameras are batched with more than 1 batch dimension" + ) camera_indices = torch.tensor([camera_indices], device=cameras.device) - assert camera_indices.shape[-1] == len( - cameras.shape - ), "camera_indices must have shape (num_rays:..., num_cameras_batch_dims)" + assert camera_indices.shape[-1] == len(cameras.shape), ( + "camera_indices must have shape (num_rays:..., num_cameras_batch_dims)" + ) # If keep_shape is True, then we need to make sure that the camera indices in question # are all the same height and width and can actually be batched while maintaining the image diff --git a/nerfstudio/data/datamanagers/full_images_datamanager.py b/nerfstudio/data/datamanagers/full_images_datamanager.py index 772139ce5..6ffff9177 100644 --- a/nerfstudio/data/datamanagers/full_images_datamanager.py +++ b/nerfstudio/data/datamanagers/full_images_datamanager.py @@ -205,8 +205,8 @@ class FullImageDatamanager(DataManager, Generic[TDataset]): data = dataset.get_data(idx, image_type=self.config.cache_images_type) camera = dataset.cameras[idx].reshape(()) assert data["image"].shape[1] == camera.width.item() and data["image"].shape[0] == camera.height.item(), ( - f'The size of image ({data["image"].shape[1]}, {data["image"].shape[0]}) loaded ' - f'does not match the camera parameters ({camera.width.item(), camera.height.item()})' + f"The size of image ({data['image'].shape[1]}, {data['image'].shape[0]}) loaded " + f"does not match the camera parameters ({camera.width.item(), camera.height.item()})" ) if camera.distortion_params is None or torch.all(camera.distortion_params == 0): return data diff --git a/nerfstudio/data/dataparsers/dycheck_dataparser.py b/nerfstudio/data/dataparsers/dycheck_dataparser.py index c92cad339..42ce6afce 100644 --- a/nerfstudio/data/dataparsers/dycheck_dataparser.py +++ b/nerfstudio/data/dataparsers/dycheck_dataparser.py @@ -47,7 +47,7 @@ def downscale(img, scale: int) -> np.ndarray: return img height, width = img.shape[:2] if height % scale > 0 or width % scale > 0: - raise ValueError(f"Image shape ({height},{width}) must be divisible by the" f" scale ({scale}).") + raise ValueError(f"Image shape ({height},{width}) must be divisible by the scale ({scale}).") out_height, out_width = height // scale, width // scale resized = cv2.resize(img, (out_width, out_height), cv2.INTER_AREA) # type: ignore return resized diff --git a/nerfstudio/data/dataparsers/nerfstudio_dataparser.py b/nerfstudio/data/dataparsers/nerfstudio_dataparser.py index e11902c09..24dc456d1 100644 --- a/nerfstudio/data/dataparsers/nerfstudio_dataparser.py +++ b/nerfstudio/data/dataparsers/nerfstudio_dataparser.py @@ -476,7 +476,7 @@ class Nerfstudio(DataParser): while True: if (max_res / 2 ** (df)) <= MAX_AUTO_RESOLUTION: break - if not (data_dir / f"{downsample_folder_prefix}{2**(df+1)}" / filepath.name).exists(): + if not (data_dir / f"{downsample_folder_prefix}{2 ** (df + 1)}" / filepath.name).exists(): break df += 1 diff --git a/nerfstudio/data/dataparsers/nuscenes_dataparser.py b/nerfstudio/data/dataparsers/nuscenes_dataparser.py index 69ec26315..89440b4ff 100644 --- a/nerfstudio/data/dataparsers/nuscenes_dataparser.py +++ b/nerfstudio/data/dataparsers/nuscenes_dataparser.py @@ -91,9 +91,9 @@ class NuScenes(DataParser): ) cameras = ["CAM_" + camera for camera in self.config.cameras] - assert ( - len(cameras) == 1 - ), "waiting on multiple camera support" # TODO: remove once multiple cameras are supported + assert len(cameras) == 1, ( + "waiting on multiple camera support" + ) # TODO: remove once multiple cameras are supported # get samples for scene samples = [ diff --git a/nerfstudio/data/datasets/base_dataset.py b/nerfstudio/data/datasets/base_dataset.py index 449720bd3..e9493dcbc 100644 --- a/nerfstudio/data/datasets/base_dataset.py +++ b/nerfstudio/data/datasets/base_dataset.py @@ -128,9 +128,9 @@ class InputDataset(Dataset): if self._dataparser_outputs.mask_filenames is not None: mask_filepath = self._dataparser_outputs.mask_filenames[image_idx] data["mask"] = get_image_mask_tensor_from_path(filepath=mask_filepath, scale_factor=self.scale_factor) - assert ( - data["mask"].shape[:2] == data["image"].shape[:2] - ), f"Mask and image have different shapes. Got {data['mask'].shape[:2]} and {data['image'].shape[:2]}" + assert data["mask"].shape[:2] == data["image"].shape[:2], ( + f"Mask and image have different shapes. Got {data['mask'].shape[:2]} and {data['image'].shape[:2]}" + ) if self.mask_color: data["image"] = torch.where( data["mask"] == 1.0, data["image"], torch.ones_like(data["image"]) * torch.tensor(self.mask_color) diff --git a/nerfstudio/data/pixel_samplers.py b/nerfstudio/data/pixel_samplers.py index 63b4a35b0..009d40571 100644 --- a/nerfstudio/data/pixel_samplers.py +++ b/nerfstudio/data/pixel_samplers.py @@ -556,9 +556,9 @@ class PairPixelSampler(PixelSampler): # pylint: disable=too-few-public-methods ) -> Int[Tensor, "batch_size 3"]: rays_to_sample = self.rays_to_sample if batch_size is not None: - assert ( - int(batch_size) % 2 == 0 - ), f"PairPixelSampler can only return batch sizes in multiples of two (got {batch_size})" + assert int(batch_size) % 2 == 0, ( + f"PairPixelSampler can only return batch sizes in multiples of two (got {batch_size})" + ) rays_to_sample = batch_size // 2 if isinstance(mask, Tensor) and not self.config.ignore_mask: diff --git a/nerfstudio/data/utils/nerfstudio_collate.py b/nerfstudio/data/utils/nerfstudio_collate.py index b5b391f54..c2cca9a74 100644 --- a/nerfstudio/data/utils/nerfstudio_collate.py +++ b/nerfstudio/data/utils/nerfstudio_collate.py @@ -27,7 +27,7 @@ import torch.utils.data from nerfstudio.cameras.cameras import Cameras NERFSTUDIO_COLLATE_ERR_MSG_FORMAT = ( - "default_collate: batch must contain tensors, numpy arrays, numbers, " "dicts, lists or anything in {}; found {}" + "default_collate: batch must contain tensors, numpy arrays, numbers, dicts, lists or anything in {}; found {}" ) np_str_obj_array_pattern = re.compile(r"[SaUO]") @@ -152,14 +152,16 @@ def nerfstudio_collate(batch: Any, extra_mappings: Union[Dict[type, Callable], N assert all((isinstance(cam, Cameras) for cam in batch)) assert all((cam.distortion_params is None for cam in batch)) or all( (cam.distortion_params is not None for cam in batch) - ), "All cameras must have distortion parameters or none of them should have distortion parameters.\ + ), ( + "All cameras must have distortion parameters or none of them should have distortion parameters.\ Generalized batching will be supported in the future." + ) if batch[0].metadata is not None: metadata_keys = batch[0].metadata.keys() - assert all( - (cam.metadata.keys() == metadata_keys for cam in batch) - ), "All cameras must have the same metadata keys." + assert all((cam.metadata.keys() == metadata_keys for cam in batch)), ( + "All cameras must have the same metadata keys." + ) else: assert all((cam.metadata is None for cam in batch)), "All cameras must have the same metadata keys." diff --git a/nerfstudio/engine/callbacks.py b/nerfstudio/engine/callbacks.py index 776fd829b..c8bd8e58d 100644 --- a/nerfstudio/engine/callbacks.py +++ b/nerfstudio/engine/callbacks.py @@ -80,9 +80,9 @@ class TrainingCallback: args: Optional[List] = None, kwargs: Optional[Dict] = None, ): - assert ( - "step" in signature(func).parameters.keys() - ), f"'step: int' must be an argument in the callback function 'func': {func.__name__}" + assert "step" in signature(func).parameters.keys(), ( + f"'step: int' must be an argument in the callback function 'func': {func.__name__}" + ) self.where_to_run = where_to_run self.update_every_num_iters = update_every_num_iters self.iters = iters diff --git a/nerfstudio/exporter/exporter_utils.py b/nerfstudio/exporter/exporter_utils.py index 9435a3b91..49b7994d5 100644 --- a/nerfstudio/exporter/exporter_utils.py +++ b/nerfstudio/exporter/exporter_utils.py @@ -148,9 +148,9 @@ def generate_point_cloud( CONSOLE.print(f"Please set --normal_output_name to one of: {outputs.keys()}", justify="center") sys.exit(1) normal = outputs[normal_output_name] - assert ( - torch.min(normal) >= 0.0 and torch.max(normal) <= 1.0 - ), "Normal values from method output must be in [0, 1]" + assert torch.min(normal) >= 0.0 and torch.max(normal) <= 1.0, ( + "Normal values from method output must be in [0, 1]" + ) normal = (normal * 2.0) - 1.0 point = ray_bundle.origins + ray_bundle.directions * depth view_direction = ray_bundle.directions diff --git a/nerfstudio/field_components/encodings.py b/nerfstudio/field_components/encodings.py index b5f8bf4f0..48845748b 100644 --- a/nerfstudio/field_components/encodings.py +++ b/nerfstudio/field_components/encodings.py @@ -369,9 +369,9 @@ class HashEncoding(Encoding): ) if self.tcnn_encoding is None: - assert ( - interpolation is None or interpolation == "Linear" - ), f"interpolation '{interpolation}' is not supported for torch encoding backend" + assert interpolation is None or interpolation == "Linear", ( + f"interpolation '{interpolation}' is not supported for torch encoding backend" + ) def build_nn_modules(self) -> None: """Initialize the torch version of the hash encoding.""" diff --git a/nerfstudio/fields/base_field.py b/nerfstudio/fields/base_field.py index b0215aae6..d70fda6cd 100644 --- a/nerfstudio/fields/base_field.py +++ b/nerfstudio/fields/base_field.py @@ -85,9 +85,9 @@ class Field(nn.Module): """ assert self._sample_locations is not None, "Sample locations must be set before calling get_normals." assert self._density_before_activation is not None, "Density must be set before calling get_normals." - assert ( - self._sample_locations.shape[:-1] == self._density_before_activation.shape[:-1] - ), "Sample locations and density must have the same shape besides the last dimension." + assert self._sample_locations.shape[:-1] == self._density_before_activation.shape[:-1], ( + "Sample locations and density must have the same shape besides the last dimension." + ) normals = torch.autograd.grad( self._density_before_activation, diff --git a/nerfstudio/model_components/ray_samplers.py b/nerfstudio/model_components/ray_samplers.py index e0d15db92..182e255f0 100644 --- a/nerfstudio/model_components/ray_samplers.py +++ b/nerfstudio/model_components/ray_samplers.py @@ -330,9 +330,9 @@ class PDFSampler(Sampler): u = u.expand(size=(*cdf.shape[:-1], num_bins)) u = u.contiguous() - assert ( - ray_samples.spacing_starts is not None and ray_samples.spacing_ends is not None - ), "ray_sample spacing_starts and spacing_ends must be provided" + assert ray_samples.spacing_starts is not None and ray_samples.spacing_ends is not None, ( + "ray_sample spacing_starts and spacing_ends must be provided" + ) assert ray_samples.spacing_to_euclidean_fn is not None, "ray_samples.spacing_to_euclidean_fn must be provided" existing_bins = torch.cat( [ diff --git a/nerfstudio/models/base_surface_model.py b/nerfstudio/models/base_surface_model.py index 992968321..ffc1d069d 100644 --- a/nerfstudio/models/base_surface_model.py +++ b/nerfstudio/models/base_surface_model.py @@ -193,9 +193,9 @@ class SurfaceModel(Model): Returns: Outputs of model. (ie. rendered colors) """ - assert ( - ray_bundle.metadata is not None and "directions_norm" in ray_bundle.metadata - ), "directions_norm is required in ray_bundle.metadata" + assert ray_bundle.metadata is not None and "directions_norm" in ray_bundle.metadata, ( + "directions_norm is required in ray_bundle.metadata" + ) samples_and_field_outputs = self.sample_and_forward_field(ray_bundle=ray_bundle) diff --git a/nerfstudio/models/tensorf.py b/nerfstudio/models/tensorf.py index 6c149b4b6..02a0bbfaf 100644 --- a/nerfstudio/models/tensorf.py +++ b/nerfstudio/models/tensorf.py @@ -327,9 +327,9 @@ class TensoRFModel(Model): elif self.config.regularization == "tv": density_plane_coef = self.field.density_encoding.plane_coef color_plane_coef = self.field.color_encoding.plane_coef - assert isinstance(color_plane_coef, torch.Tensor) and isinstance( - density_plane_coef, torch.Tensor - ), "TV reg only supported for TensoRF encoding types with plane_coef attribute" + assert isinstance(color_plane_coef, torch.Tensor) and isinstance(density_plane_coef, torch.Tensor), ( + "TV reg only supported for TensoRF encoding types with plane_coef attribute" + ) loss_dict["tv_reg_density"] = tv_loss(density_plane_coef) loss_dict["tv_reg_color"] = tv_loss(color_plane_coef) elif self.config.regularization == "none": diff --git a/nerfstudio/pipelines/base_pipeline.py b/nerfstudio/pipelines/base_pipeline.py index 20392dcb6..6695deb8f 100644 --- a/nerfstudio/pipelines/base_pipeline.py +++ b/nerfstudio/pipelines/base_pipeline.py @@ -422,9 +422,9 @@ class VanillaPipeline(Pipeline): self, step: Optional[int] = None, output_path: Optional[Path] = None, get_std: bool = False ): """Get the average metrics for evaluation images.""" - assert hasattr( - self.datamanager, "fixed_indices_eval_dataloader" - ), "datamanager must have 'fixed_indices_eval_dataloader' attribute" + assert hasattr(self.datamanager, "fixed_indices_eval_dataloader"), ( + "datamanager must have 'fixed_indices_eval_dataloader' attribute" + ) image_prefix = "eval" return self.get_average_image_metrics( self.datamanager.fixed_indices_eval_dataloader, image_prefix, step, output_path, get_std diff --git a/nerfstudio/pipelines/dynamic_batch.py b/nerfstudio/pipelines/dynamic_batch.py index 2d0eb37ce..26ac7e58c 100644 --- a/nerfstudio/pipelines/dynamic_batch.py +++ b/nerfstudio/pipelines/dynamic_batch.py @@ -54,9 +54,9 @@ class DynamicBatchPipeline(VanillaPipeline): grad_scaler: Optional[GradScaler] = None, ): super().__init__(config, device, test_mode, world_size, local_rank) - assert isinstance( - self.datamanager, VanillaDataManager - ), "DynamicBatchPipeline only works with VanillaDataManager." + assert isinstance(self.datamanager, VanillaDataManager), ( + "DynamicBatchPipeline only works with VanillaDataManager." + ) self.dynamic_num_rays_per_batch = self.config.target_num_samples // self.config.max_num_samples_per_ray self._update_pixel_samplers() diff --git a/nerfstudio/process_data/colmap_converter_to_nerfstudio_dataset.py b/nerfstudio/process_data/colmap_converter_to_nerfstudio_dataset.py index ec82f0ad7..55f657a3a 100644 --- a/nerfstudio/process_data/colmap_converter_to_nerfstudio_dataset.py +++ b/nerfstudio/process_data/colmap_converter_to_nerfstudio_dataset.py @@ -145,9 +145,7 @@ class ColmapConverterToNerfstudioDataset(BaseConverterToNerfstudioDataset): summary_log.append(colmap_utils.get_matching_summary(num_frames, num_matched_frames)) else: - CONSOLE.log( - "[bold yellow]Warning: Could not find existing COLMAP results. " "Not generating transforms.json" - ) + CONSOLE.log("[bold yellow]Warning: Could not find existing COLMAP results. Not generating transforms.json") return summary_log def _export_depth(self) -> Tuple[Optional[Dict[int, Path]], List[str]]: @@ -224,7 +222,7 @@ class ColmapConverterToNerfstudioDataset(BaseConverterToNerfstudioDataset): ) elif sfm_tool == "hloc": if mask_path is not None: - raise RuntimeError("Cannot use a mask with hloc. Please remove the cropping options " "and try again.") + raise RuntimeError("Cannot use a mask with hloc. Please remove the cropping options and try again.") assert feature_type is not None assert matcher_type is not None @@ -241,7 +239,7 @@ class ColmapConverterToNerfstudioDataset(BaseConverterToNerfstudioDataset): use_single_camera_mode=self.use_single_camera_mode, ) else: - raise RuntimeError("Invalid combination of sfm_tool, feature_type, and matcher_type, " "exiting") + raise RuntimeError("Invalid combination of sfm_tool, feature_type, and matcher_type, exiting") def __post_init__(self) -> None: super().__post_init__() diff --git a/nerfstudio/process_data/polycam_utils.py b/nerfstudio/process_data/polycam_utils.py index a84de5a31..0d9107d98 100644 --- a/nerfstudio/process_data/polycam_utils.py +++ b/nerfstudio/process_data/polycam_utils.py @@ -70,9 +70,9 @@ def polycam_to_json( frame["cy"] = frame_json["cy"] - crop_border_pixels frame["w"] = frame_json["width"] - crop_border_pixels * 2 frame["h"] = frame_json["height"] - crop_border_pixels * 2 - frame["file_path"] = f"./images/frame_{i+1:05d}{image_filename.suffix}" + frame["file_path"] = f"./images/frame_{i + 1:05d}{image_filename.suffix}" if use_depth: - frame["depth_file_path"] = f"./depth/frame_{i+1:05d}{depth_filenames[i].suffix}" + frame["depth_file_path"] = f"./depth/frame_{i + 1:05d}{depth_filenames[i].suffix}" # Transform matrix to nerfstudio format. Please refer to the documentation for coordinate system conventions. frame["transform_matrix"] = [ [frame_json["t_20"], frame_json["t_21"], frame_json["t_22"], frame_json["t_23"]], diff --git a/nerfstudio/process_data/process_data_utils.py b/nerfstudio/process_data/process_data_utils.py index 3c9013abe..89f78ed53 100644 --- a/nerfstudio/process_data/process_data_utils.py +++ b/nerfstudio/process_data/process_data_utils.py @@ -318,7 +318,7 @@ def copy_images_list( crop_cmd = "" if crop_border_pixels is not None: - crop_cmd = f"crop=iw-{crop_border_pixels*2}:ih-{crop_border_pixels*2}[cropped];[cropped]" + crop_cmd = f"crop=iw-{crop_border_pixels * 2}:ih-{crop_border_pixels * 2}[cropped];[cropped]" elif crop_factor != (0.0, 0.0, 0.0, 0.0): height = 1 - crop_factor[0] - crop_factor[1] width = 1 - crop_factor[2] - crop_factor[3] @@ -484,7 +484,7 @@ def downscale_images( run_command(ffmpeg_cmd, verbose=verbose) CONSOLE.log("[bold green]:tada: Done downscaling images.") - downscale_text = [f"[bold blue]{2**(i+1)}x[/bold blue]" for i in range(num_downscales)] + downscale_text = [f"[bold blue]{2 ** (i + 1)}x[/bold blue]" for i in range(num_downscales)] downscale_text = ", ".join(downscale_text[:-1]) + " and " + downscale_text[-1] return f"We downsampled the images by {downscale_text}" diff --git a/nerfstudio/scripts/downloads/download_data.py b/nerfstudio/scripts/downloads/download_data.py index 5c976ba16..a2c9d2758 100644 --- a/nerfstudio/scripts/downloads/download_data.py +++ b/nerfstudio/scripts/downloads/download_data.py @@ -289,9 +289,9 @@ class PhototourismDownload(DatasetDownload): PhototourismDownload(capture_name=capture_name).download(save_dir) return - assert ( - self.capture_name in phototourism_downloads - ), f"Capture name {self.capture_name} not found in {phototourism_downloads.keys()}" + assert self.capture_name in phototourism_downloads, ( + f"Capture name {self.capture_name} not found in {phototourism_downloads.keys()}" + ) url = phototourism_downloads[self.capture_name] target_path = str(save_dir / "phototourism" / self.capture_name) os.makedirs(target_path, exist_ok=True) @@ -350,9 +350,9 @@ class SDFstudioDemoDownload(DatasetDownload): SDFstudioDemoDownload(dataset_name=dataset_name).download(save_dir) return - assert ( - self.dataset_name in sdfstudio_downloads - ), f"Capture name {self.dataset_name} not found in {sdfstudio_downloads.keys()}" + assert self.dataset_name in sdfstudio_downloads, ( + f"Capture name {self.dataset_name} not found in {sdfstudio_downloads.keys()}" + ) url = sdfstudio_downloads[self.dataset_name] @@ -421,9 +421,9 @@ class NeRFOSRDownload(DatasetDownload): NeRFOSRDownload(capture_name=capture_name).download(save_dir) return - assert ( - self.capture_name in nerfosr_downloads - ), f"Capture name {self.capture_name} not found in {nerfosr_downloads.keys()}" + assert self.capture_name in nerfosr_downloads, ( + f"Capture name {self.capture_name} not found in {nerfosr_downloads.keys()}" + ) url = nerfosr_downloads[self.capture_name] target_path = str(save_dir / "nerfosr" / self.capture_name) os.makedirs(target_path, exist_ok=True) @@ -475,9 +475,9 @@ class Mill19Download(DatasetDownload): Mill19Download(capture_name=capture_name).download(save_dir) return - assert ( - self.capture_name in mill19_downloads - ), f"Capture name {self.capture_name} not found in {mill19_downloads.keys()}" + assert self.capture_name in mill19_downloads, ( + f"Capture name {self.capture_name} not found in {mill19_downloads.keys()}" + ) url = mill19_downloads[self.capture_name] target_path = save_dir / "mill19" / self.capture_name target_path.mkdir(parents=True, exist_ok=True) diff --git a/nerfstudio/scripts/downloads/eyeful_tower.py b/nerfstudio/scripts/downloads/eyeful_tower.py index d4b1d7628..b9d5d8c26 100644 --- a/nerfstudio/scripts/downloads/eyeful_tower.py +++ b/nerfstudio/scripts/downloads/eyeful_tower.py @@ -360,7 +360,7 @@ class EyefulTowerDownload(DatasetDownload): + includes + [base_url, str(output_path)] ) - CONSOLE.print(f"[EyefulTower Capture {i+1: >2d}/{len(captures)}]: '{capture}'") + CONSOLE.print(f"[EyefulTower Capture {i + 1: >2d}/{len(captures)}]: '{capture}'") print( f"\tDownloading resolutions {resolutions}", f"to '{output_path.resolve()}' with command `aws {' '.join(command)}` ...", diff --git a/nerfstudio/scripts/render.py b/nerfstudio/scripts/render.py index 4eb4a7184..fc035c4a9 100644 --- a/nerfstudio/scripts/render.py +++ b/nerfstudio/scripts/render.py @@ -556,9 +556,9 @@ class RenderCameraPath(BaseRender): self.output_path = Path(str(left_eye_path.parent)[:-5]) self.output_path.mkdir(parents=True, exist_ok=True) if self.image_format == "png": - ffmpeg_ods_command = f'ffmpeg -y -pattern_type glob -i "{str(left_eye_path.with_suffix("") / "*.png")}" -pattern_type glob -i "{str(right_eye_path.with_suffix("") / "*.png")}" -filter_complex vstack -start_number 0 "{str(self.output_path)+"//%05d.png"}"' + ffmpeg_ods_command = f'ffmpeg -y -pattern_type glob -i "{str(left_eye_path.with_suffix("") / "*.png")}" -pattern_type glob -i "{str(right_eye_path.with_suffix("") / "*.png")}" -filter_complex vstack -start_number 0 "{str(self.output_path) + "//%05d.png"}"' elif self.image_format == "jpeg": - ffmpeg_ods_command = f'ffmpeg -y -pattern_type glob -i "{str(left_eye_path.with_suffix("") / "*.jpg")}" -pattern_type glob -i "{str(right_eye_path.with_suffix("") / "*.jpg")}" -filter_complex vstack -start_number 0 "{str(self.output_path)+"//%05d.jpg"}"' + ffmpeg_ods_command = f'ffmpeg -y -pattern_type glob -i "{str(left_eye_path.with_suffix("") / "*.jpg")}" -pattern_type glob -i "{str(right_eye_path.with_suffix("") / "*.jpg")}" -filter_complex vstack -start_number 0 "{str(self.output_path) + "//%05d.jpg"}"' run_command(ffmpeg_ods_command, verbose=False) # remove the temp files directory @@ -577,9 +577,9 @@ class RenderCameraPath(BaseRender): self.output_path = Path(str(left_eye_path.parent)[:-5]) self.output_path.mkdir(parents=True, exist_ok=True) if self.image_format == "png": - ffmpeg_vr180_command = f'ffmpeg -y -pattern_type glob -i "{str(left_eye_path.with_suffix("") / "*.png")}" -pattern_type glob -i "{str(right_eye_path.with_suffix("") / "*.png")}" -filter_complex hstack -start_number 0 "{str(self.output_path)+"//%05d.png"}"' + ffmpeg_vr180_command = f'ffmpeg -y -pattern_type glob -i "{str(left_eye_path.with_suffix("") / "*.png")}" -pattern_type glob -i "{str(right_eye_path.with_suffix("") / "*.png")}" -filter_complex hstack -start_number 0 "{str(self.output_path) + "//%05d.png"}"' elif self.image_format == "jpeg": - ffmpeg_vr180_command = f'ffmpeg -y -pattern_type glob -i "{str(left_eye_path.with_suffix("") / "*.jpg")}" -pattern_type glob -i "{str(right_eye_path.with_suffix("") / "*.jpg")}" -filter_complex hstack -start_number 0 "{str(self.output_path)+"//%05d.jpg"}"' + ffmpeg_vr180_command = f'ffmpeg -y -pattern_type glob -i "{str(left_eye_path.with_suffix("") / "*.jpg")}" -pattern_type glob -i "{str(right_eye_path.with_suffix("") / "*.jpg")}" -filter_complex hstack -start_number 0 "{str(self.output_path) + "//%05d.jpg"}"' run_command(ffmpeg_vr180_command, verbose=False) # remove the temp files directory diff --git a/nerfstudio/utils/comms.py b/nerfstudio/utils/comms.py index 0a3880cff..689e8b923 100644 --- a/nerfstudio/utils/comms.py +++ b/nerfstudio/utils/comms.py @@ -42,9 +42,9 @@ def get_local_rank() -> int: """The rank of the current process within the local (per-machine) process group.""" if not is_dist_avail_and_initialized(): return 0 - assert ( - LOCAL_PROCESS_GROUP is not None - ), "Local process group is not created! Please use launch() to spawn processes!" + assert LOCAL_PROCESS_GROUP is not None, ( + "Local process group is not created! Please use launch() to spawn processes!" + ) return dist.get_rank(group=LOCAL_PROCESS_GROUP) diff --git a/nerfstudio/utils/tensor_dataclass.py b/nerfstudio/utils/tensor_dataclass.py index fb3331a35..cd0066588 100644 --- a/nerfstudio/utils/tensor_dataclass.py +++ b/nerfstudio/utils/tensor_dataclass.py @@ -71,9 +71,9 @@ class TensorDataclass: set _shape to be the broadcasted shape. """ for k, v in self._field_custom_dimensions.items(): - assert ( - isinstance(v, int) and v > 1 - ), f"Custom dimensions must be an integer greater than 1, since 1 is the default, received {k}: {v}" + assert isinstance(v, int) and v > 1, ( + f"Custom dimensions must be an integer greater than 1, since 1 is the default, received {k}: {v}" + ) # Shim to prevent pyright from narrowing `self` to DataclassInstance. self_dc = self diff --git a/nerfstudio/utils/writer.py b/nerfstudio/utils/writer.py index 45b23c8fc..e2a8aad97 100644 --- a/nerfstudio/utils/writer.py +++ b/nerfstudio/utils/writer.py @@ -503,7 +503,7 @@ class LocalWriter: """ step = GLOBAL_BUFFER["step"] fraction_done = step / GLOBAL_BUFFER["max_iter"] - curr_mssg = f"{step} ({fraction_done*100:.02f}%)" + curr_mssg = f"{step} ({fraction_done * 100:.02f}%)" curr_mssg = f"{curr_mssg:<20}" for name, v in latest_map.items(): if name in self.stats_to_track: diff --git a/nerfstudio/viewer/viewer_elements.py b/nerfstudio/viewer/viewer_elements.py index 1ccfab3b4..0dc8d70d8 100644 --- a/nerfstudio/viewer/viewer_elements.py +++ b/nerfstudio/viewer/viewer_elements.py @@ -211,9 +211,9 @@ class ViewerControl: origin = scene_pointer_msg.ray_origin direction = scene_pointer_msg.ray_direction screen_pos = scene_pointer_msg.screen_pos[0] - assert (origin is not None) and ( - direction is not None - ), "Origin and direction should not be None for click event." + assert (origin is not None) and (direction is not None), ( + "Origin and direction should not be None for click event." + ) origin = tuple([x / VISER_NERFSTUDIO_SCALE_RATIO for x in origin]) assert len(origin) == 3 pointer_event = ViewerClick(origin, direction, screen_pos) diff --git a/nerfstudio/viewer_legacy/server/viewer_state.py b/nerfstudio/viewer_legacy/server/viewer_state.py index 990a7bbf1..36cef1340 100644 --- a/nerfstudio/viewer_legacy/server/viewer_state.py +++ b/nerfstudio/viewer_legacy/server/viewer_state.py @@ -394,7 +394,7 @@ class ViewerLegacyState: bgr[:, :t, :] = bc camera_json = eval_dataset.cameras.to_json(camera_idx=idx, image=bgr, max_size=100) - self.viser_server.add_dataset_image(idx=f"{idx+len(train_dataset):06d}", json=camera_json) + self.viser_server.add_dataset_image(idx=f"{idx + len(train_dataset):06d}", json=camera_json) # draw the scene box (i.e., the bounding box) self.viser_server.update_scene_box(train_dataset.scene_box)