mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-06 07:48:50 +08:00
remove visibility when rendering if not a target. also colors for train vs. eval images
This commit is contained in:
1 parent
411a8f1c0c
commit
310b177406
4 files changed
+36
-26
No files matched your search
@@ -61,7 +61,7 @@ class NerfstudioDataParserConfig(DataParserConfig):
|
|||||||
"""The method to use to center the poses."""
|
"""The method to use to center the poses."""
|
||||||
auto_scale_poses: bool = True
|
auto_scale_poses: bool = True
|
||||||
"""Whether to automatically scale the poses to fit in +/- 1 bounding box."""
|
"""Whether to automatically scale the poses to fit in +/- 1 bounding box."""
|
||||||
eval_mode: Literal["train-split-fraction", "eval-frame-index"] = "train-split-fraction"
|
eval_mode: Literal["train-split-fraction", "eval-frame-index", "eval-interval"] = "train-split-fraction"
|
||||||
"""The method to use for splitting the dataset into train and eval."""
|
"""The method to use for splitting the dataset into train and eval."""
|
||||||
train_split_fraction: float = 0.9
|
train_split_fraction: float = 0.9
|
||||||
"""The fraction of images to use for training. The remaining images are for eval."""
|
"""The fraction of images to use for training. The remaining images are for eval."""
|
||||||
@@ -69,6 +69,8 @@ class NerfstudioDataParserConfig(DataParserConfig):
|
|||||||
"""The index of the frames to use for train."""
|
"""The index of the frames to use for train."""
|
||||||
eval_frame_indices: Tuple[int, ...] = (1,)
|
eval_frame_indices: Tuple[int, ...] = (1,)
|
||||||
"""The index of the frames to use for eval."""
|
"""The index of the frames to use for eval."""
|
||||||
|
eval_interval: int = 8
|
||||||
|
"""The interval between frames to use for eval."""
|
||||||
depth_unit_scale_factor: float = 1e-3
|
depth_unit_scale_factor: float = 1e-3
|
||||||
"""Scales the depth values to meters. Default value is 0.001 for a millimeter to meter conversion."""
|
"""Scales the depth values to meters. Default value is 0.001 for a millimeter to meter conversion."""
|
||||||
|
|
||||||
@@ -213,6 +215,8 @@ class Nerfstudio(DataParser):
|
|||||||
indices = [i for i, path in enumerate(image_filenames) if path in split_filenames]
|
indices = [i for i, path in enumerate(image_filenames) if path in split_filenames]
|
||||||
CONSOLE.log(f"[yellow] Dataset is overriding {split}_indices to {indices}")
|
CONSOLE.log(f"[yellow] Dataset is overriding {split}_indices to {indices}")
|
||||||
indices = np.array(indices, dtype=np.int32)
|
indices = np.array(indices, dtype=np.int32)
|
||||||
|
i_train = indices
|
||||||
|
i_eval = indices
|
||||||
elif has_split_files_spec:
|
elif has_split_files_spec:
|
||||||
raise RuntimeError(f"The dataset's list of filenames for split {split} is missing.")
|
raise RuntimeError(f"The dataset's list of filenames for split {split} is missing.")
|
||||||
else:
|
else:
|
||||||
@@ -226,12 +230,6 @@ class Nerfstudio(DataParser):
|
|||||||
) # equally spaced training images starting and ending at 0 and num_images-1
|
) # equally spaced training images starting and ending at 0 and num_images-1
|
||||||
i_eval = np.setdiff1d(i_all, i_train) # eval images are the remaining images
|
i_eval = np.setdiff1d(i_all, i_train) # eval images are the remaining images
|
||||||
assert len(i_eval) == num_eval_images
|
assert len(i_eval) == num_eval_images
|
||||||
if split == "train":
|
|
||||||
indices = i_train
|
|
||||||
elif split in ["val", "test"]:
|
|
||||||
indices = i_eval
|
|
||||||
else:
|
|
||||||
raise ValueError(f"Unknown dataparser split {split}")
|
|
||||||
elif self.config.eval_mode == "eval-frame-index":
|
elif self.config.eval_mode == "eval-frame-index":
|
||||||
# keep around some metadata
|
# keep around some metadata
|
||||||
eval_frame_index_0_metadata = []
|
eval_frame_index_0_metadata = []
|
||||||
@@ -256,12 +254,24 @@ class Nerfstudio(DataParser):
|
|||||||
eval_frame_index_0_metadata.append(0)
|
eval_frame_index_0_metadata.append(0)
|
||||||
if frame_index in self.config.eval_frame_indices:
|
if frame_index in self.config.eval_frame_indices:
|
||||||
i_eval.append(idx)
|
i_eval.append(idx)
|
||||||
if split == "train":
|
elif self.config.eval_mode == "eval-interval":
|
||||||
indices = i_train
|
# filter image_filenames and poses based on a specified interval for eval
|
||||||
elif split in ["val", "test"]:
|
# this chunk of code is very similar to the mipnerf360 code
|
||||||
indices = i_eval
|
num_images = len(image_filenames)
|
||||||
else:
|
all_indices = np.arange(num_images)
|
||||||
raise ValueError(f"Unknown dataparser split {split}")
|
train_indices = all_indices[all_indices % self.config.eval_interval != 0]
|
||||||
|
eval_indices = all_indices[all_indices % self.config.eval_interval == 0]
|
||||||
|
i_train = train_indices
|
||||||
|
i_eval = eval_indices
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Unknown eval mode {self.config.eval_mode}")
|
||||||
|
|
||||||
|
if split == "train":
|
||||||
|
indices = i_train
|
||||||
|
elif split in ["val", "test"]:
|
||||||
|
indices = i_eval
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Unknown dataparser split {split}")
|
||||||
|
|
||||||
if "orientation_override" in meta:
|
if "orientation_override" in meta:
|
||||||
orientation_method = meta["orientation_override"]
|
orientation_method = meta["orientation_override"]
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ export function get_scene_tree() {
|
|||||||
if (!prev.has(key)) {
|
if (!prev.has(key)) {
|
||||||
// keys_valid.push(key);
|
// keys_valid.push(key);
|
||||||
const json = current[key];
|
const json = current[key];
|
||||||
const camera = drawCamera(json, key);
|
const camera = drawCamera(json, key, 0x000000, 0xffffff);
|
||||||
sceneTree.set_object_from_path([CAMERAS_NAME, key], camera);
|
sceneTree.set_object_from_path([CAMERAS_NAME, key], camera);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -308,7 +308,7 @@ export function get_scene_tree() {
|
|||||||
if (!prev.has(key)) {
|
if (!prev.has(key)) {
|
||||||
// keys_valid.push(key);
|
// keys_valid.push(key);
|
||||||
const json = current[key];
|
const json = current[key];
|
||||||
const camera = drawCamera(json, key);
|
const camera = drawCamera(json, key, 0xff0000, 0xff5555);
|
||||||
sceneTree.set_object_from_path([EVAL_CAMERAS_NAME, key], camera);
|
sceneTree.set_object_from_path([EVAL_CAMERAS_NAME, key], camera);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ export function getCameraWireframe(
|
|||||||
focalLength = 4,
|
focalLength = 4,
|
||||||
w = 1.5,
|
w = 1.5,
|
||||||
h = 2,
|
h = 2,
|
||||||
|
color = 0x000000,
|
||||||
) {
|
) {
|
||||||
// Returns a wireframe of a 3D line-plot of a camera symbol.
|
// Returns a wireframe of a 3D line-plot of a camera symbol.
|
||||||
// A wireframe is a frustum.
|
// A wireframe is a frustum.
|
||||||
@@ -93,17 +94,18 @@ export function getCameraWireframe(
|
|||||||
|
|
||||||
const geometry = new THREE.BufferGeometry().setFromPoints(points);
|
const geometry = new THREE.BufferGeometry().setFromPoints(points);
|
||||||
const material = new THREE.LineBasicMaterial({
|
const material = new THREE.LineBasicMaterial({
|
||||||
color: 0x000000,
|
color: color,
|
||||||
linewidth: 1,
|
linewidth: 1,
|
||||||
});
|
});
|
||||||
const lines = new THREE.LineSegments(geometry, material);
|
const lines = new THREE.LineSegments(geometry, material);
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function drawCameraImagePlane(width, height, imageString, name) {
|
export function drawCameraImagePlane(width, height, imageString, name, color = 0xffffff) {
|
||||||
// imageString is the texture as a base64 string
|
// imageString is the texture as a base64 string
|
||||||
const geometry = new THREE.PlaneGeometry(width, height);
|
const geometry = new THREE.PlaneGeometry(width, height);
|
||||||
const material = new THREE.MeshBasicMaterial({
|
const material = new THREE.MeshBasicMaterial({
|
||||||
|
color: color,
|
||||||
side: THREE.DoubleSide,
|
side: THREE.DoubleSide,
|
||||||
});
|
});
|
||||||
const texture = new THREE.TextureLoader().load(imageString);
|
const texture = new THREE.TextureLoader().load(imageString);
|
||||||
@@ -117,7 +119,7 @@ function transpose(matrix) {
|
|||||||
return matrix[0].map((col, i) => matrix.map((row) => row[i]));
|
return matrix[0].map((col, i) => matrix.map((row) => row[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function drawCamera(camera, name): THREE.Object3D {
|
export function drawCamera(camera, name, wireframe_color = 0x000000, image_plane_color = 0xffffff): THREE.Object3D {
|
||||||
const group = new THREE.Group();
|
const group = new THREE.Group();
|
||||||
|
|
||||||
console.assert(
|
console.assert(
|
||||||
@@ -133,6 +135,7 @@ export function drawCamera(camera, name): THREE.Object3D {
|
|||||||
displayedFocalLength,
|
displayedFocalLength,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
wireframe_color,
|
||||||
);
|
);
|
||||||
cameraWireframeObject.translateZ(displayedFocalLength); // move the wireframe frustum back
|
cameraWireframeObject.translateZ(displayedFocalLength); // move the wireframe frustum back
|
||||||
group.add(cameraWireframeObject);
|
group.add(cameraWireframeObject);
|
||||||
@@ -141,6 +144,7 @@ export function drawCamera(camera, name): THREE.Object3D {
|
|||||||
height * 2,
|
height * 2,
|
||||||
camera.image,
|
camera.image,
|
||||||
name,
|
name,
|
||||||
|
image_plane_color
|
||||||
);
|
);
|
||||||
group.add(cameraImagePlaneObject);
|
group.add(cameraImagePlaneObject);
|
||||||
|
|
||||||
@@ -156,11 +160,3 @@ export function drawCamera(camera, name): THREE.Object3D {
|
|||||||
|
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function drawCameras(cameras): Record<number, THREE.Object3D> {
|
|
||||||
const cameraObjects = {};
|
|
||||||
for (const [key, camera] of Object.entries(cameras)) {
|
|
||||||
cameraObjects[key] = drawCamera(camera);
|
|
||||||
}
|
|
||||||
return cameraObjects;
|
|
||||||
}
|
|
||||||
@@ -376,6 +376,10 @@ class RenderTrajectory:
|
|||||||
else:
|
else:
|
||||||
assert_never(self.traj)
|
assert_never(self.traj)
|
||||||
|
|
||||||
|
# check if visibility is a desired output. if not, disable it for fast rendering
|
||||||
|
if "visibility" not in self.rendered_output_names:
|
||||||
|
pipeline.model.visibility_field = None
|
||||||
|
|
||||||
_render_trajectory_video(
|
_render_trajectory_video(
|
||||||
pipeline,
|
pipeline,
|
||||||
camera_path,
|
camera_path,
|
||||||
|
|||||||
Reference in new issue
Block a user