Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade pyright #2526

Merged
merged 4 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nerfstudio/exporter/marching_cubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def evaluate(points: torch.Tensor) -> torch.Tensor:
)
verts = verts + np.array([x_min, y_min, z_min])

meshcrop = trimesh.Trimesh(verts, faces, normals)
meshcrop = trimesh.Trimesh(verts, faces, normals) # type: ignore
meshes.append(meshcrop)

combined_mesh: trimesh.Trimesh = trimesh.util.concatenate(meshes) # type: ignore
Expand Down
29 changes: 15 additions & 14 deletions nerfstudio/process_data/hloc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
try:
# TODO(1480) un-hide pycolmap import
import pycolmap
from hloc import (
from hloc import ( # type: ignore
extract_features,
match_features,
pairs_from_exhaustive,
Expand All @@ -38,6 +38,7 @@
)
except ImportError:
_HAS_HLOC = False

else:
_HAS_HLOC = True

Expand Down Expand Up @@ -95,24 +96,24 @@ def run_hloc(
features = outputs / "features.h5"
matches = outputs / "matches.h5"

retrieval_conf = extract_features.confs["netvlad"]
feature_conf = extract_features.confs[feature_type]
matcher_conf = match_features.confs[matcher_type]
retrieval_conf = extract_features.confs["netvlad"] # type: ignore
feature_conf = extract_features.confs[feature_type] # type: ignore
matcher_conf = match_features.confs[matcher_type] # type: ignore

references = [p.relative_to(image_dir).as_posix() for p in image_dir.iterdir()]
extract_features.main(feature_conf, image_dir, image_list=references, feature_path=features)
extract_features.main(feature_conf, image_dir, image_list=references, feature_path=features) # type: ignore
if matching_method == "exhaustive":
pairs_from_exhaustive.main(sfm_pairs, image_list=references)
pairs_from_exhaustive.main(sfm_pairs, image_list=references) # type: ignore
else:
retrieval_path = extract_features.main(retrieval_conf, image_dir, outputs)
retrieval_path = extract_features.main(retrieval_conf, image_dir, outputs) # type: ignore
if num_matched >= len(references):
num_matched = len(references)
pairs_from_retrieval.main(retrieval_path, sfm_pairs, num_matched=num_matched)
match_features.main(matcher_conf, sfm_pairs, features=features, matches=matches)
pairs_from_retrieval.main(retrieval_path, sfm_pairs, num_matched=num_matched) # type: ignore
match_features.main(matcher_conf, sfm_pairs, features=features, matches=matches) # type: ignore

image_options = pycolmap.ImageReaderOptions(camera_model=camera_model.value)
image_options = pycolmap.ImageReaderOptions(camera_model=camera_model.value) # type: ignore
if refine_pixsfm:
sfm = PixSfM(
sfm = PixSfM( # type: ignore
conf={
"dense_features": {"use_cache": True},
"KA": {"dense_features": {"use_cache": True}, "max_kps_per_problem": 1000},
Expand All @@ -126,20 +127,20 @@ def run_hloc(
features,
matches,
image_list=references,
camera_mode=pycolmap.CameraMode.SINGLE,
camera_mode=pycolmap.CameraMode.SINGLE, # type: ignore
image_options=image_options,
verbose=verbose,
)
print("Refined", refined.summary())

else:
reconstruction.main(
reconstruction.main( # type: ignore
sfm_dir,
image_dir,
sfm_pairs,
features,
matches,
camera_mode=pycolmap.CameraMode.SINGLE,
camera_mode=pycolmap.CameraMode.SINGLE, # type: ignore
image_options=image_options,
verbose=verbose,
)
14 changes: 10 additions & 4 deletions nerfstudio/scripts/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"""
from __future__ import annotations

import gzip
import json
import os
import struct
import shutil
import struct
import sys
import gzip
from contextlib import ExitStack, contextmanager
from dataclasses import dataclass, field
from pathlib import Path
Expand Down Expand Up @@ -54,11 +54,14 @@
get_spiral_path,
)
from nerfstudio.cameras.cameras import Cameras, CameraType, RayBundle
from nerfstudio.data.datamanagers.base_datamanager import (
VanillaDataManager,
VanillaDataManagerConfig,
)
from nerfstudio.data.datasets.base_dataset import Dataset
from nerfstudio.data.datamanagers.base_datamanager import VanillaDataManager, VanillaDataManagerConfig
from nerfstudio.data.scene_box import OrientedBox
from nerfstudio.data.utils.dataloaders import FixedIndicesEvalDataloader
from nerfstudio.engine.trainer import TrainerConfig
from nerfstudio.data.scene_box import OrientedBox
from nerfstudio.model_components import renderers
from nerfstudio.pipelines.base_pipeline import Pipeline
from nerfstudio.utils import colormaps, install_checks
Expand Down Expand Up @@ -318,6 +321,9 @@ def get_crop_from_json(camera_json: Dict[str, Any]) -> Optional[CropData]:
center = camera_json["crop"]["crop_center"]
scale = camera_json["crop"]["crop_scale"]
rot = (0.0, 0.0, 0.0) if "crop_rot" not in camera_json["crop"] else tuple(camera_json["crop"]["crop_rot"])
assert len(center) == 3
assert len(scale) == 3
assert len(rot) == 3
return CropData(
background_color=torch.Tensor([bg_color["r"] / 255.0, bg_color["g"] / 255.0, bg_color["b"] / 255.0]),
obb=OrientedBox.from_params(center, rot, scale),
Expand Down
1 change: 1 addition & 0 deletions nerfstudio/utils/plotly_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ def get_cube(
if isinstance(side_length, float):
pts *= side_length / 2.0
else:
assert isinstance(side_length, torch.Tensor)
pts[0] *= side_length[0].item() / 2.0
pts[1] *= side_length[1].item() / 2.0
pts[2] *= side_length[2].item() / 2.0
Expand Down
2 changes: 1 addition & 1 deletion nerfstudio/viewer/server/control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def update_output_options(self, new_options: List[str]):
self._split_output_render.set_options(new_options)
self._split_output_render.value = new_options[-1]

def add_element(self, e: ViewerElement, additional_tags: Tuple[str] = tuple()) -> None:
def add_element(self, e: ViewerElement, additional_tags: Tuple[str, ...] = tuple()) -> None:
"""Adds an element to the control panel

Args:
Expand Down
8 changes: 4 additions & 4 deletions nerfstudio/viewer/server/viewer_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ def _crop_params_update(self, _) -> None:
self.viser_server.send_crop_params(
crop_enabled=self.control_panel.crop_viewport,
crop_bg_color=self.control_panel.background_color,
crop_scale=tuple(crop_scale.tolist()),
crop_center=tuple(crop_center.tolist()),
crop_scale=tuple(crop_scale.tolist()), # type: ignore
crop_center=tuple(crop_center.tolist()), # type: ignore
)
if self.camera_message is not None:
self.render_statemachine.action(RenderAction("rerender", self.camera_message))
Expand Down Expand Up @@ -258,8 +258,8 @@ def _handle_crop_params_message(self, message: NerfstudioMessage) -> None:
scale = np.array(message.crop_scale)
crop_min = center - scale / 2.0
crop_max = center + scale / 2.0
self.control_panel.crop_min = tuple(crop_min.tolist())
self.control_panel.crop_max = tuple(crop_max.tolist())
self.control_panel.crop_min = tuple(crop_min.tolist()) # type: ignore
self.control_panel.crop_max = tuple(crop_max.tolist()) # type: ignore

def _handle_click_message(self, message: NerfstudioMessage) -> None:
"""Handle click message from viewer."""
Expand Down
4 changes: 2 additions & 2 deletions nerfstudio/viewer/viser/message_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,8 @@ def update_scene_box(self, scene_box: SceneBox) -> None:
"""
self._queue(
messages.SceneBoxMessage(
min=tuple(scene_box.aabb[0].tolist()),
max=tuple(scene_box.aabb[1].tolist()),
min=tuple(scene_box.aabb[0].tolist()), # type: ignore
max=tuple(scene_box.aabb[1].tolist()), # type: ignore
)
)

Expand Down
9 changes: 5 additions & 4 deletions nerfstudio/viewer_beta/control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import numpy as np
import torch
import viser.transforms as vtf
from viser import ViserServer

from nerfstudio.data.scene_box import OrientedBox
from nerfstudio.utils.colormaps import ColormapOptions, Colormaps
from nerfstudio.viewer_beta.viewer_elements import ( # ViewerButtonGroup,
Expand All @@ -32,7 +34,6 @@
ViewerSlider,
ViewerVec3,
)
from viser import ViserServer


class ControlPanel:
Expand Down Expand Up @@ -147,7 +148,7 @@ def __init__(
self._crop_handle = self.viser_server.add_transform_controls("Crop", depth_test=False, line_width=4.0)

def update_center(han):
self._crop_handle.position = tuple(p * self.viser_scale_ratio for p in han.value)
self._crop_handle.position = tuple(p * self.viser_scale_ratio for p in han.value) # type: ignore

self._crop_center = ViewerVec3(
"Crop Center",
Expand Down Expand Up @@ -175,7 +176,7 @@ def update_rot(han):
@self._crop_handle.on_update
def _update_crop_handle(han):
pos = self._crop_handle.position
self._crop_center.value = tuple(p / self.viser_scale_ratio for p in pos)
self._crop_center.value = tuple(p / self.viser_scale_ratio for p in pos) # type: ignore
rpy = vtf.SO3(self._crop_handle.wxyz).as_rpy_radians()
self._crop_rot.value = (float(rpy.roll), float(rpy.pitch), float(rpy.yaw))

Expand Down Expand Up @@ -280,7 +281,7 @@ def update_output_options(self, new_options: List[str]):
self._split_output_render.set_options(new_options)
self._split_output_render.value = new_options[-1]

def add_element(self, e: ViewerElement, additional_tags: Tuple[str] = tuple()) -> None:
def add_element(self, e: ViewerElement, additional_tags: Tuple[str, ...] = tuple()) -> None:
"""Adds an element to the control panel

Args:
Expand Down
2 changes: 1 addition & 1 deletion nerfstudio/viewer_beta/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def init_scene(
)

@camera_handle.on_click
def _(event: viser.ClickEvent[viser.CameraFrustumHandle]) -> None:
def _(event: viser.SceneNodePointerEvent[viser.CameraFrustumHandle]) -> None:
assert self.client is not None
with self.client.atomic():
self.client.camera.position = event.target.position
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies = [
"torchvision>=0.14.1",
"torchmetrics[image]>=1.0.1",
"typing_extensions>=4.4.0",
"viser==0.1.6",
"viser==0.1.7",
"nuscenes-devkit>=1.1.1",
"wandb>=0.13.3",
"xatlas",
Expand Down Expand Up @@ -90,7 +90,7 @@ dev = [
"diffusers==0.16.1",
"opencv-stubs==0.0.7",
"transformers==4.29.2",
"pyright==1.1.308",
"pyright==1.1.331",
]

# Documentation related packages
Expand Down