mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-01 21:39:06 +08:00
Update renderers
This commit is contained in:
1 parent
b6bbb15045
commit
cf7b5a7c63
1 file changed
+9
-11
@@ -128,8 +128,7 @@ class RGBRenderer(nn.Module):
|
|||||||
elif background_color == "last_sample":
|
elif background_color == "last_sample":
|
||||||
background_color = rgb[..., -1, :]
|
background_color = rgb[..., -1, :]
|
||||||
elif background_color == "random":
|
elif background_color == "random":
|
||||||
# background_color = torch.rand_like(rgb[..., -1, :]).to(rgb.device)
|
background_color = torch.rand_like(rgb[..., -1, :]).to(rgb.device)
|
||||||
raise RuntimeError("get_background_color should never be called with background_color='random'")
|
|
||||||
elif isinstance(background_color, str) and background_color in colors.COLORS_DICT:
|
elif isinstance(background_color, str) and background_color in colors.COLORS_DICT:
|
||||||
background_color = colors.COLORS_DICT[background_color].to(rgb.device)
|
background_color = colors.COLORS_DICT[background_color].to(rgb.device)
|
||||||
assert isinstance(background_color, Tensor)
|
assert isinstance(background_color, Tensor)
|
||||||
@@ -151,15 +150,16 @@ class RGBRenderer(nn.Module):
|
|||||||
Returns:
|
Returns:
|
||||||
Blended RGB.
|
Blended RGB.
|
||||||
"""
|
"""
|
||||||
|
if image.size(-1) < 4:
|
||||||
|
return image
|
||||||
|
|
||||||
if background_color is None:
|
if background_color is None:
|
||||||
background_color_name = self.background_color
|
background_color_name = self.background_color
|
||||||
if background_color_name == "last_sample" or background_color == "random":
|
if background_color_name == "last_sample" or background_color_name == "random":
|
||||||
background_color_name = "black"
|
background_color_name = "black"
|
||||||
background_color = self.get_background_color(
|
background_color = self.get_background_color(
|
||||||
rgb=image.unsqueeze(-1), background_color=background_color_name
|
rgb=image.unsqueeze(-1), background_color=background_color_name
|
||||||
)
|
)
|
||||||
if image.size(-1) < 4:
|
|
||||||
return image
|
|
||||||
rgb, opacity = image[..., :3], image[..., 3:]
|
rgb, opacity = image[..., :3], image[..., 3:]
|
||||||
blended_rgb = rgb * opacity + background_color.to(rgb.device) * (1 - opacity)
|
blended_rgb = rgb * opacity + background_color.to(rgb.device) * (1 - opacity)
|
||||||
return blended_rgb
|
return blended_rgb
|
||||||
@@ -181,13 +181,11 @@ class RGBRenderer(nn.Module):
|
|||||||
A tuple of the predicted and ground truth RGB values.
|
A tuple of the predicted and ground truth RGB values.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
background_color = self.get_background_color(
|
||||||
|
rgb=pred_image.unsqueeze(-1), background_color=self.background_color
|
||||||
|
).to(pred_image.device)
|
||||||
if self.background_color == "random":
|
if self.background_color == "random":
|
||||||
background_color = torch.rand_like(pred_image)
|
pred_image = pred_image + background_color * (1.0 - pred_accumulation)
|
||||||
else:
|
|
||||||
background_color = self.get_background_color(
|
|
||||||
rgb=pred_image.unsqueeze(-1), background_color=self.background_color
|
|
||||||
).to(pred_image.device)
|
|
||||||
pred_image = pred_image + background_color * (1.0 - pred_accumulation)
|
|
||||||
gt_image = self.blend_background(gt_image, background_color=background_color)
|
gt_image = self.blend_background(gt_image, background_color=background_color)
|
||||||
return pred_image, gt_image
|
return pred_image, gt_image
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user