mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-28 12:00:02 +08:00
Merge branch 'main' into justin/opensfm
This commit is contained in:
commit
d8265b4b21
9 files changed
+83
-56
No files matched your search
@@ -175,6 +175,9 @@ class ViewerConfig(PrintableConfig):
|
||||
"""the ip address where the bridge server is running"""
|
||||
num_rays_per_chunk: int = 32768
|
||||
"""number of rays per chunk to render with viewer"""
|
||||
max_num_display_images: int = 512
|
||||
"""Maximum number of training images to display in the viewer, to avoid lag. This does not change which images are
|
||||
actually used in training/evaluation. If -1, display all."""
|
||||
|
||||
|
||||
from nerfstudio.engine.optimizers import OptimizerConfig
|
||||
|
||||
@@ -17,7 +17,7 @@ from __future__ import annotations
|
||||
|
||||
import math
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path, PureWindowsPath
|
||||
from pathlib import Path, PurePath
|
||||
from typing import Optional, Type
|
||||
|
||||
import numpy as np
|
||||
@@ -80,12 +80,9 @@ class Nerfstudio(DataParser):
|
||||
num_skipped_image_filenames = 0
|
||||
|
||||
for frame in meta["frames"]:
|
||||
if "\\" in frame["file_path"]:
|
||||
filepath = PureWindowsPath(frame["file_path"])
|
||||
else:
|
||||
filepath = Path(frame["file_path"])
|
||||
filepath = PurePath(frame["file_path"])
|
||||
fname = self._get_fname(filepath)
|
||||
if not fname:
|
||||
if not fname.exists():
|
||||
num_skipped_image_filenames += 1
|
||||
else:
|
||||
image_filenames.append(fname)
|
||||
@@ -177,7 +174,7 @@ class Nerfstudio(DataParser):
|
||||
)
|
||||
return dataparser_outputs
|
||||
|
||||
def _get_fname(self, filepath):
|
||||
def _get_fname(self, filepath: PurePath) -> Path:
|
||||
"""Get the filename of the image file."""
|
||||
|
||||
if self.downscale_factor is None:
|
||||
|
||||
@@ -234,6 +234,8 @@ class DepthRenderer(nn.Module):
|
||||
if ray_indices is not None and num_rays is not None:
|
||||
# Necessary for packed samples from volumetric ray sampler
|
||||
depth = nerfacc.accumulate_along_rays(weights, ray_indices, steps, num_rays)
|
||||
accumulation = nerfacc.accumulate_along_rays(weights, ray_indices, None, num_rays)
|
||||
depth = depth / (accumulation + eps)
|
||||
else:
|
||||
depth = torch.sum(weights * steps, dim=-2) / (torch.sum(weights, -2) + eps)
|
||||
|
||||
|
||||
@@ -102,9 +102,9 @@ class SemanticNerfWModel(Model):
|
||||
if self.config.use_same_proposal_network:
|
||||
network = HashMLPDensityField(self.scene_box.aabb, spatial_distortion=scene_contraction)
|
||||
self.proposal_networks.append(network)
|
||||
self.density_fns = [network.density_fn for _ in range(self.config.num_proposal_network_iterations)]
|
||||
self.density_fns = [network.density_fn for _ in range(self.config.num_proposal_iterations)]
|
||||
else:
|
||||
for _ in range(self.config.num_proposal_network_iterations):
|
||||
for _ in range(self.config.num_proposal_iterations):
|
||||
network = HashMLPDensityField(self.scene_box.aabb, spatial_distortion=scene_contraction)
|
||||
self.proposal_networks.append(network)
|
||||
self.density_fns = [network.density_fn for network in self.proposal_networks]
|
||||
@@ -116,7 +116,7 @@ class SemanticNerfWModel(Model):
|
||||
self.proposal_sampler = ProposalNetworkSampler(
|
||||
num_nerf_samples_per_ray=self.config.num_nerf_samples_per_ray,
|
||||
num_proposal_samples_per_ray=self.config.num_proposal_samples_per_ray,
|
||||
num_proposal_network_iterations=self.config.num_proposal_network_iterations,
|
||||
num_proposal_network_iterations=self.config.num_proposal_iterations,
|
||||
single_jitter=self.config.use_single_jitter,
|
||||
)
|
||||
|
||||
@@ -193,7 +193,7 @@ class SemanticNerfWModel(Model):
|
||||
outputs["weights_list"] = weights_list
|
||||
outputs["ray_samples_list"] = ray_samples_list
|
||||
|
||||
for i in range(self.config.num_proposal_network_iterations):
|
||||
for i in range(self.config.num_proposal_iterations):
|
||||
outputs[f"prop_depth_{i}"] = self.renderer_depth(weights=weights_list[i], ray_samples=ray_samples_list[i])
|
||||
|
||||
# transients
|
||||
@@ -286,7 +286,7 @@ class SemanticNerfWModel(Model):
|
||||
|
||||
images_dict = {"img": combined_rgb, "accumulation": combined_acc, "depth": combined_depth}
|
||||
|
||||
for i in range(self.config.num_proposal_network_iterations):
|
||||
for i in range(self.config.num_proposal_iterations):
|
||||
key = f"prop_depth_{i}"
|
||||
prop_depth_i = colormaps.apply_depth_colormap(
|
||||
outputs[key],
|
||||
|
||||
@@ -274,6 +274,22 @@ class ViewerState:
|
||||
self.webrtc_thread = None
|
||||
self.kill_webrtc_signal = False
|
||||
|
||||
def _pick_drawn_image_idxs(self, total_num: int) -> list[int]:
|
||||
"""Determine indicies of images to display in viewer.
|
||||
|
||||
Args:
|
||||
total_num: total number of training images.
|
||||
|
||||
Returns:
|
||||
List of indices from [0, total_num-1].
|
||||
"""
|
||||
if self.config.max_num_display_images < 0:
|
||||
num_display_images = total_num
|
||||
else:
|
||||
num_display_images = min(self.config.max_num_display_images, total_num)
|
||||
# draw indices, roughly evenly spaced
|
||||
return np.linspace(0, total_num - 1, num_display_images, dtype=np.int32).tolist()
|
||||
|
||||
def init_scene(self, dataset: InputDataset, start_train=True) -> None:
|
||||
"""Draw some images and the scene aabb in the viewer.
|
||||
|
||||
@@ -290,7 +306,7 @@ class ViewerState:
|
||||
self.vis["sceneState/cameras"].delete()
|
||||
|
||||
# draw the training cameras and images
|
||||
image_indices = range(len(dataset))
|
||||
image_indices = self._pick_drawn_image_idxs(len(dataset))
|
||||
for idx in image_indices:
|
||||
image = dataset[idx]["image"]
|
||||
bgr = image[..., [2, 1, 0]]
|
||||
|
||||
Reference in new issue
Block a user