mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-06 07:48:50 +08:00
allow to save per frame results with gt
This commit is contained in:
1 parent
f549d11de4
commit
2c4fd33cc7
1 file changed
+51
-35
@@ -20,8 +20,8 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import struct
|
|
||||||
import shutil
|
import shutil
|
||||||
|
import struct
|
||||||
import sys
|
import sys
|
||||||
from contextlib import ExitStack
|
from contextlib import ExitStack
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
@@ -35,23 +35,12 @@ import tyro
|
|||||||
from jaxtyping import Float
|
from jaxtyping import Float
|
||||||
from rich import box, style
|
from rich import box, style
|
||||||
from rich.panel import Panel
|
from rich.panel import Panel
|
||||||
from rich.progress import (
|
from rich.progress import BarColumn, Progress, TaskProgressColumn, TextColumn, TimeElapsedColumn, TimeRemainingColumn
|
||||||
BarColumn,
|
|
||||||
Progress,
|
|
||||||
TaskProgressColumn,
|
|
||||||
TextColumn,
|
|
||||||
TimeElapsedColumn,
|
|
||||||
TimeRemainingColumn,
|
|
||||||
)
|
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
from torch import Tensor
|
from torch import Tensor
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
||||||
from nerfstudio.cameras.camera_paths import (
|
from nerfstudio.cameras.camera_paths import get_interpolated_camera_path, get_path_from_json, get_spiral_path
|
||||||
get_interpolated_camera_path,
|
|
||||||
get_path_from_json,
|
|
||||||
get_spiral_path,
|
|
||||||
)
|
|
||||||
from nerfstudio.cameras.cameras import Cameras, CameraType
|
from nerfstudio.cameras.cameras import Cameras, CameraType
|
||||||
from nerfstudio.data.datamanagers.base_datamanager import VanillaDataManager
|
from nerfstudio.data.datamanagers.base_datamanager import VanillaDataManager
|
||||||
from nerfstudio.data.scene_box import SceneBox
|
from nerfstudio.data.scene_box import SceneBox
|
||||||
@@ -74,6 +63,7 @@ def _render_trajectory_video(
|
|||||||
output_format: Literal["images", "video"] = "video",
|
output_format: Literal["images", "video"] = "video",
|
||||||
image_format: Literal["jpeg", "png"] = "jpeg",
|
image_format: Literal["jpeg", "png"] = "jpeg",
|
||||||
jpeg_quality: int = 100,
|
jpeg_quality: int = 100,
|
||||||
|
concatenate_outputs: bool = False,
|
||||||
colormap_options: colormaps.ColormapOptions = colormaps.ColormapOptions(),
|
colormap_options: colormaps.ColormapOptions = colormaps.ColormapOptions(),
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Helper function to create a video of the spiral trajectory.
|
"""Helper function to create a video of the spiral trajectory.
|
||||||
@@ -87,6 +77,7 @@ def _render_trajectory_video(
|
|||||||
rendered_resolution_scaling_factor: Scaling factor to apply to the camera image resolution.
|
rendered_resolution_scaling_factor: Scaling factor to apply to the camera image resolution.
|
||||||
seconds: Length of output video.
|
seconds: Length of output video.
|
||||||
output_format: How to save output data.
|
output_format: How to save output data.
|
||||||
|
concatenate_outputs: Whether to concatenate the outputs images.
|
||||||
colormap_options: Options for colormap.
|
colormap_options: Options for colormap.
|
||||||
"""
|
"""
|
||||||
CONSOLE.print("[bold green]Creating trajectory " + output_format)
|
CONSOLE.print("[bold green]Creating trajectory " + output_format)
|
||||||
@@ -139,7 +130,12 @@ def _render_trajectory_video(
|
|||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
outputs = pipeline.model.get_outputs_for_camera_ray_bundle(camera_ray_bundle)
|
outputs = pipeline.model.get_outputs_for_camera_ray_bundle(camera_ray_bundle)
|
||||||
|
|
||||||
render_image = []
|
# also save ground truth if specified
|
||||||
|
if "rgb_gt" in rendered_output_names:
|
||||||
|
assert pipeline.datamanager.eval_dataset is not None
|
||||||
|
outputs["rgb_gt"] = pipeline.datamanager.eval_dataset.get_image(camera_idx).to(pipeline.device)
|
||||||
|
|
||||||
|
render_images = []
|
||||||
for rendered_output_name in rendered_output_names:
|
for rendered_output_name in rendered_output_names:
|
||||||
if rendered_output_name not in outputs:
|
if rendered_output_name not in outputs:
|
||||||
CONSOLE.rule("Error", style="red")
|
CONSOLE.rule("Error", style="red")
|
||||||
@@ -157,27 +153,41 @@ def _render_trajectory_video(
|
|||||||
.cpu()
|
.cpu()
|
||||||
.numpy()
|
.numpy()
|
||||||
)
|
)
|
||||||
render_image.append(output_image)
|
render_images.append(output_image)
|
||||||
render_image = np.concatenate(render_image, axis=1)
|
|
||||||
if output_format == "images":
|
if concatenate_outputs:
|
||||||
if image_format == "png":
|
render_images = [np.concatenate(render_images, axis=1)]
|
||||||
media.write_image(output_image_dir / f"{camera_idx:05d}.png", render_image, fmt="png")
|
render_names = ["composite"]
|
||||||
if image_format == "jpeg":
|
else:
|
||||||
media.write_image(
|
render_names = rendered_output_names
|
||||||
output_image_dir / f"{camera_idx:05d}.jpg", render_image, fmt="jpeg", quality=jpeg_quality
|
|
||||||
)
|
for render_name, render_image in zip(render_names, render_images):
|
||||||
if output_format == "video":
|
if output_format == "images":
|
||||||
if writer is None:
|
os.makedirs(output_image_dir / render_name, exist_ok=True)
|
||||||
render_width = int(render_image.shape[1])
|
if image_format == "png":
|
||||||
render_height = int(render_image.shape[0])
|
media.write_image(
|
||||||
writer = stack.enter_context(
|
output_image_dir / render_name / f"{camera_idx:05d}.png", render_image, fmt="png"
|
||||||
media.VideoWriter(
|
|
||||||
path=output_filename,
|
|
||||||
shape=(render_height, render_width),
|
|
||||||
fps=fps,
|
|
||||||
)
|
)
|
||||||
)
|
if image_format == "jpeg":
|
||||||
writer.add_image(render_image)
|
media.write_image(
|
||||||
|
output_image_dir / render_name / f"{camera_idx:05d}.jpg",
|
||||||
|
render_image,
|
||||||
|
fmt="jpeg",
|
||||||
|
quality=jpeg_quality,
|
||||||
|
)
|
||||||
|
if output_format == "video":
|
||||||
|
if writer is None:
|
||||||
|
render_width = int(render_image.shape[1])
|
||||||
|
render_height = int(render_image.shape[0])
|
||||||
|
|
||||||
|
writer = stack.enter_context(
|
||||||
|
media.VideoWriter(
|
||||||
|
path=output_image_dir / f"{render_name}.mp4",
|
||||||
|
shape=(render_height, render_width),
|
||||||
|
fps=fps,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
writer.add_image(render_image)
|
||||||
|
|
||||||
table = Table(
|
table = Table(
|
||||||
title=None,
|
title=None,
|
||||||
@@ -315,6 +325,8 @@ class BaseRender:
|
|||||||
"""Specifies number of rays per chunk during eval. If None, use the value in the config file."""
|
"""Specifies number of rays per chunk during eval. If None, use the value in the config file."""
|
||||||
colormap_options: colormaps.ColormapOptions = colormaps.ColormapOptions()
|
colormap_options: colormaps.ColormapOptions = colormaps.ColormapOptions()
|
||||||
"""Colormap options."""
|
"""Colormap options."""
|
||||||
|
concatenate_outputs: bool = True
|
||||||
|
"""Whether to concatenate the outputs images."""
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -372,6 +384,7 @@ class RenderCameraPath(BaseRender):
|
|||||||
image_format=self.image_format,
|
image_format=self.image_format,
|
||||||
jpeg_quality=self.jpeg_quality,
|
jpeg_quality=self.jpeg_quality,
|
||||||
colormap_options=self.colormap_options,
|
colormap_options=self.colormap_options,
|
||||||
|
concatenate_outputs=self.concatenate_outputs,
|
||||||
)
|
)
|
||||||
|
|
||||||
if camera_path.camera_type[0] == CameraType.OMNIDIRECTIONALSTEREO_L.value:
|
if camera_path.camera_type[0] == CameraType.OMNIDIRECTIONALSTEREO_L.value:
|
||||||
@@ -396,6 +409,7 @@ class RenderCameraPath(BaseRender):
|
|||||||
image_format=self.image_format,
|
image_format=self.image_format,
|
||||||
jpeg_quality=self.jpeg_quality,
|
jpeg_quality=self.jpeg_quality,
|
||||||
colormap_options=self.colormap_options,
|
colormap_options=self.colormap_options,
|
||||||
|
concatenate_outputs=self.concatenate_outputs,
|
||||||
)
|
)
|
||||||
|
|
||||||
# stack the left and right eye renders for final output
|
# stack the left and right eye renders for final output
|
||||||
@@ -471,6 +485,7 @@ class RenderInterpolated(BaseRender):
|
|||||||
output_format=self.output_format,
|
output_format=self.output_format,
|
||||||
image_format=self.image_format,
|
image_format=self.image_format,
|
||||||
colormap_options=self.colormap_options,
|
colormap_options=self.colormap_options,
|
||||||
|
concatenate_outputs=self.concatenate_outputs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -514,6 +529,7 @@ class SpiralRender(BaseRender):
|
|||||||
output_format=self.output_format,
|
output_format=self.output_format,
|
||||||
image_format=self.image_format,
|
image_format=self.image_format,
|
||||||
colormap_options=self.colormap_options,
|
colormap_options=self.colormap_options,
|
||||||
|
concatenate_outputs=self.concatenate_outputs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user