mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-01 05:20:32 +08:00
merge
This commit is contained in:
commit
e8118f0569
57 files changed
+1222
-841
No files matched your search
Whitespace-only changes.
@@ -1,21 +0,0 @@
|
||||
# dataset options
|
||||
dataset:
|
||||
data_directory: data/lego
|
||||
dataset_format: blender
|
||||
downscale_factor: 1.0
|
||||
|
||||
# dataloader options
|
||||
dataloader:
|
||||
num_workers: 1
|
||||
shuffle: true
|
||||
num_images_to_sample_from: 8
|
||||
num_rays_per_batch: 1024
|
||||
|
||||
# ray generation module and its option
|
||||
network:
|
||||
ray_generator:
|
||||
class_name: RayGenerator
|
||||
inputs: ["cxy"] # camera, x, and y indices
|
||||
meta_data:
|
||||
in_dim: 0
|
||||
learning_rate: 0.0
|
||||
@@ -1,88 +0,0 @@
|
||||
"""
|
||||
Code to test ray generation.
|
||||
"""
|
||||
|
||||
import imageio
|
||||
import torch
|
||||
from torch.utils.data import DataLoader
|
||||
from tqdm import tqdm
|
||||
|
||||
from pyrad.nerf.dataset.collate import CollateIterDataset, collate_batch_size_one
|
||||
from pyrad.nerf.dataset.image_dataset import ImageDataset, collate_batch
|
||||
from pyrad.nerf.dataset.utils import get_dataset_inputs
|
||||
from pyrad.nerf.ray_generator import RayGenerator
|
||||
from pyrad.utils.io import get_absolute_path
|
||||
from pyrad.viewer.plotly import visualize_dataset
|
||||
|
||||
|
||||
def visualize_batch(batch):
|
||||
"""Returns an image from a batch."""
|
||||
assert "image" in batch, "You must call collate_batch with keep_full_image=True for this to work."
|
||||
# set the color of the sampled rays
|
||||
c, y, x = [i.flatten() for i in torch.split(batch["local_indices"], 1, dim=-1)]
|
||||
batch["image"][c, y, x] = 1.0
|
||||
|
||||
# batch["image"] is num_images, h, w, 3
|
||||
images = torch.split(batch["image"], 1, dim=0)
|
||||
image_list = [image[0] for image in images]
|
||||
image = torch.cat(image_list, dim=1) # cat along the width dimension
|
||||
image = (image * 255.0).to(torch.uint8)
|
||||
return image
|
||||
|
||||
|
||||
def test_dataloader(visualize=False):
|
||||
"""Testing for the dataloader from input dataset parameters to rays."""
|
||||
|
||||
data_directory = "tests/data/lego_test"
|
||||
dataset_format = "blender"
|
||||
downscale_factor = 1
|
||||
num_images_to_sample_from = 1
|
||||
num_times_to_repeat_images = 40
|
||||
num_rays_per_batch = 1024
|
||||
num_workers = 0
|
||||
|
||||
data_directory = get_absolute_path(data_directory)
|
||||
dataset_inputs = get_dataset_inputs(
|
||||
data_directory=data_directory, dataset_format=dataset_format, downscale_factor=downscale_factor, split="train"
|
||||
)
|
||||
image_dataset = ImageDataset(
|
||||
image_filenames=dataset_inputs.image_filenames, downscale_factor=dataset_inputs.downscale_factor
|
||||
)
|
||||
iter_dataset = CollateIterDataset(
|
||||
image_dataset,
|
||||
collate_fn=lambda batch_list: collate_batch(batch_list, num_rays_per_batch, keep_full_image=True),
|
||||
num_samples_to_collate=num_images_to_sample_from,
|
||||
num_times_to_repeat_images=num_times_to_repeat_images,
|
||||
)
|
||||
dataloader = DataLoader(
|
||||
iter_dataset,
|
||||
batch_size=1,
|
||||
num_workers=num_workers,
|
||||
collate_fn=collate_batch_size_one,
|
||||
pin_memory=True,
|
||||
)
|
||||
dataloader_iter = iter(dataloader)
|
||||
|
||||
ray_generator = RayGenerator(dataset_inputs.intrinsics, dataset_inputs.camera_to_world)
|
||||
|
||||
num_batches = 10
|
||||
for _ in tqdm(range(num_batches)):
|
||||
batch = next(dataloader_iter)
|
||||
ray_bundle = ray_generator.forward(batch["indices"])
|
||||
|
||||
# visualize the batch
|
||||
image = visualize_batch(batch)
|
||||
if visualize:
|
||||
imageio.imwrite("temp0.png", image)
|
||||
|
||||
# visualize the RayBundle
|
||||
small_ray_bundle = ray_bundle.sample(100)
|
||||
fig = visualize_dataset(camera_origins=dataset_inputs.camera_to_world[:, :3, 3], ray_bundle=small_ray_bundle)
|
||||
if visualize:
|
||||
fig.write_image("temp1.png")
|
||||
fig.write_html("temp1.html")
|
||||
assert True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_dataloader(visualize=True)
|
||||
@@ -2,7 +2,7 @@
|
||||
Test samplers
|
||||
"""
|
||||
import torch
|
||||
from pyrad.nerf.sampler import PDFSampler, UniformSampler
|
||||
from pyrad.nerf.ray_sampler import PDFSampler, UniformSampler
|
||||
|
||||
from pyrad.structures.rays import RayBundle
|
||||
from pyrad.nerf.colliders import NearFarCollider
|
||||
|
||||
@@ -13,3 +13,6 @@ def test_run_train():
|
||||
initialize(config_path="../configs/tests/")
|
||||
conf = compose("test_dryrun.yaml")
|
||||
main(conf)
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_run_train()
|
||||
Reference in new issue
Block a user