mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-05 23:38:42 +08:00
Merge branch 'brent/fix_undistort_progress_bar' of github.com:nerfstudio-project/nerfstudio into brent/splat_export_world_frame
This commit is contained in:
commit
55639bebe1
3 files changed
+57
-25
No files matched your search
@@ -180,26 +180,30 @@ class FullImageDatamanager(DataManager, Generic[TDataset]):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
CONSOLE.log("Caching / undistorting train images")
|
CONSOLE.log("Caching / undistorting train images")
|
||||||
with ThreadPoolExecutor() as executor:
|
with ThreadPoolExecutor(max_workers=2) as executor:
|
||||||
cached_train = list(
|
cached_train = list(
|
||||||
executor.map(
|
track(
|
||||||
process_train_data,
|
executor.map(
|
||||||
track(
|
process_train_data,
|
||||||
range(len(self.train_dataset)),
|
range(len(self.train_dataset)),
|
||||||
description="Caching / undistorting train images",
|
|
||||||
transient=True,
|
|
||||||
),
|
),
|
||||||
|
description="Caching / undistorting train images",
|
||||||
|
transient=True,
|
||||||
|
total=len(self.train_dataset),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
CONSOLE.log("Caching / undistorting eval images")
|
CONSOLE.log("Caching / undistorting eval images")
|
||||||
with ThreadPoolExecutor() as executor:
|
with ThreadPoolExecutor(max_workers=2) as executor:
|
||||||
cached_eval = list(
|
cached_eval = list(
|
||||||
executor.map(
|
track(
|
||||||
process_eval_data,
|
executor.map(
|
||||||
track(
|
process_eval_data,
|
||||||
range(len(self.eval_dataset)), description="Caching / undistorting eval images", transient=True
|
range(len(self.eval_dataset)),
|
||||||
),
|
),
|
||||||
|
description="Caching / undistorting eval images",
|
||||||
|
transient=True,
|
||||||
|
total=len(self.eval_dataset),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -178,22 +178,50 @@ class PixelSampler:
|
|||||||
if isinstance(mask, torch.Tensor) and not self.config.ignore_mask:
|
if isinstance(mask, torch.Tensor) and not self.config.ignore_mask:
|
||||||
indices = self.sample_method(batch_size, num_images, image_height, image_width, mask=mask, device=device)
|
indices = self.sample_method(batch_size, num_images, image_height, image_width, mask=mask, device=device)
|
||||||
else:
|
else:
|
||||||
rand_samples = torch.rand((batch_size, 3), device=device)
|
# Rejection sampling.
|
||||||
# convert random samples tto radius and theta
|
valid: Optional[torch.Tensor] = None
|
||||||
radii = self.config.fisheye_crop_radius * torch.sqrt(rand_samples[:, 1])
|
indices = None
|
||||||
theta = 2.0 * torch.pi * rand_samples[:, 2]
|
while True:
|
||||||
|
samples_needed = batch_size if valid is None else int(batch_size - torch.sum(valid).item())
|
||||||
|
|
||||||
# convert radius and theta to x and y between -radii and radii
|
# Check if done!
|
||||||
x = radii * torch.cos(theta)
|
if samples_needed == 0:
|
||||||
y = radii * torch.sin(theta)
|
break
|
||||||
|
|
||||||
# Multiply by the batch size and height/width to get pixel indices.
|
rand_samples = torch.rand((samples_needed, 2), device=device)
|
||||||
indices = torch.floor(
|
# Convert random samples to radius and theta.
|
||||||
torch.stack([rand_samples[:, 0], y, x], dim=1)
|
radii = self.config.fisheye_crop_radius * torch.sqrt(rand_samples[:, 0])
|
||||||
* torch.tensor([num_images, image_height // 2, image_width // 2], device=device)
|
theta = 2.0 * torch.pi * rand_samples[:, 1]
|
||||||
+ torch.tensor([0, image_height // 2, image_width // 2], device=device)
|
|
||||||
).long()
|
|
||||||
|
|
||||||
|
# Convert radius and theta to x and y.
|
||||||
|
x = (radii * torch.cos(theta) + image_width // 2).long()
|
||||||
|
y = (radii * torch.sin(theta) + image_height // 2).long()
|
||||||
|
sampled_indices = torch.stack(
|
||||||
|
[torch.randint(0, num_images, size=(samples_needed,), device=device), y, x], dim=-1
|
||||||
|
)
|
||||||
|
|
||||||
|
# Update indices.
|
||||||
|
if valid is None:
|
||||||
|
indices = sampled_indices
|
||||||
|
valid = (
|
||||||
|
(sampled_indices[:, 1] >= 0)
|
||||||
|
& (sampled_indices[:, 1] < image_height)
|
||||||
|
& (sampled_indices[:, 2] >= 0)
|
||||||
|
& (sampled_indices[:, 2] < image_width)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
assert indices is not None
|
||||||
|
not_valid = ~valid
|
||||||
|
indices[not_valid, :] = sampled_indices
|
||||||
|
valid[not_valid] = (
|
||||||
|
(sampled_indices[:, 1] >= 0)
|
||||||
|
& (sampled_indices[:, 1] < image_height)
|
||||||
|
& (sampled_indices[:, 2] >= 0)
|
||||||
|
& (sampled_indices[:, 2] < image_width)
|
||||||
|
)
|
||||||
|
assert indices is not None
|
||||||
|
|
||||||
|
assert indices.shape == (batch_size, 3)
|
||||||
return indices
|
return indices
|
||||||
|
|
||||||
def collate_image_dataset_batch(self, batch: Dict, num_rays_per_batch: int, keep_full_image: bool = False):
|
def collate_image_dataset_batch(self, batch: Dict, num_rays_per_batch: int, keep_full_image: bool = False):
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ class RenderStateMachine(threading.Thread):
|
|||||||
jpeg_quality=jpg_quality,
|
jpeg_quality=jpg_quality,
|
||||||
depth=depth,
|
depth=depth,
|
||||||
)
|
)
|
||||||
res = f"{selected_output.shape[0]}x{selected_output.shape[1]}px"
|
res = f"{selected_output.shape[1]}x{selected_output.shape[0]}px"
|
||||||
self.viewer.stats_markdown.content = self.viewer.make_stats_markdown(None, res)
|
self.viewer.stats_markdown.content = self.viewer.make_stats_markdown(None, res)
|
||||||
|
|
||||||
def _calculate_image_res(self, aspect_ratio: float) -> Tuple[int, int]:
|
def _calculate_image_res(self, aspect_ratio: float) -> Tuple[int, int]:
|
||||||
|
|||||||
Reference in new issue
Block a user