Fix benchmarking: apply get_background_color in renderer and set profiler to none (#2397)

* apply get_background_color and set profiler to none

* Apply override first

---------

Co-authored-by: Brent Yi <yibrenth@gmail.com>
This commit is contained in:
Maxim BonnaerensandBrent Yi authored and GitHub committed 2023-09-11 18:07:52 +00:00
1 parent 570ccf3c0a
commit cc98fb6bd4
2 files changed
+10 -13

No files matched your search

+7 -10
View File
@@ -102,21 +102,18 @@ class RGBRenderer(nn.Module):
comp_rgb = torch.sum(weights * rgb, dim=-2)
accumulated_weight = torch.sum(weights, dim=-2)
if BACKGROUND_COLOR_OVERRIDE is not None:
# This case must be before the others or the override is not properly applied
background_color = cls.get_background_color(
BACKGROUND_COLOR_OVERRIDE, shape=comp_rgb.shape, device=comp_rgb.device
)
elif background_color == "random":
background_color = BACKGROUND_COLOR_OVERRIDE
if background_color == "random":
# If background color is random, the predicted color is returned without blending,
# as if the background color was black.
return comp_rgb
elif background_color == "last_sample":
# Note, this is only supported for non-packed samples.
background_color = rgb[..., -1, :]
background_color = cls.get_background_color(background_color, shape=comp_rgb.shape, device=comp_rgb.device)
assert isinstance(background_color, torch.Tensor)
comp_rgb = comp_rgb + background_color.to(comp_rgb.device) * (1.0 - accumulated_weight)
comp_rgb = comp_rgb + background_color * (1.0 - accumulated_weight)
return comp_rgb
@classmethod
@@ -124,13 +121,13 @@ class RGBRenderer(nn.Module):
cls, background_color: BackgroundColor, shape: Tuple[int, ...], device: torch.device
) -> Union[Float[Tensor, "3"], Float[Tensor, "*bs 3"]]:
"""Returns the RGB background color for a specified background color.
Note:
This function CANNOT be called for background_color being either "last_sample" or "random".
Args:
rgb: RGB for each sample.
background_color: The background color specification.
background_color: The background color specification. If a string is provided, it must be a valid color name.
shape: Shape of the output tensor.
device: Device on which to create the tensor.
Returns:
Background color as RGB.