MCPcopy Create free account
hub / github.com/apple/ml-sharp / _rescale_depth

Function _rescale_depth

src/sharp/models/initializer.py:281–297  ·  view source on GitHub ↗

Rescale a depth image tensor. Args: depth: The depth tensor to transform. depth_min: The min depth to scale depth to. depth_max: The max clamp depth after scaling. Returns: The rescaled depth and rescale factor.

(
    depth: torch.Tensor, depth_min: float = 1.0, depth_max: float = 1e2
)

Source from the content-addressed store, hash-verified

279
280
281def _rescale_depth(
282 depth: torch.Tensor, depth_min: float = 1.0, depth_max: float = 1e2
283) -> tuple[torch.Tensor, torch.Tensor]:
284 """Rescale a depth image tensor.
285
286 Args:
287 depth: The depth tensor to transform.
288 depth_min: The min depth to scale depth to.
289 depth_max: The max clamp depth after scaling.
290
291 Returns:
292 The rescaled depth and rescale factor.
293 """
294 current_depth_min = depth.flatten(depth.ndim - 3).min(dim=-1).values
295 depth_factor = depth_min / (current_depth_min + 1e-6)
296 depth = (depth * depth_factor[..., None, None, None]).clamp(max=depth_max)
297 return depth, depth_factor

Callers 1

forwardMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected