MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / dynamic_threshold

Function dynamic_threshold

sat/sgm/modules/diffusionmodules/sampling_utils.py:21–30  ·  view source on GitHub ↗
(x, p=0.95)

Source from the content-addressed store, hash-verified

19
20
21def dynamic_threshold(x, p=0.95):
22 N, T, C, H, W = x.shape
23 x = rearrange(x, "n t c h w -> n c (t h w)")
24 l, r = x.quantile(q=torch.tensor([1 - p, p], device=x.device), dim=-1, keepdim=True)
25 s = torch.maximum(-l, r)
26 threshold_mask = (s > 1).expand(-1, -1, H * W * T)
27 if threshold_mask.any():
28 x = torch.where(threshold_mask, x.clamp(min=-1 * s, max=s), x)
29 x = rearrange(x, "n c (t h w) -> n t c h w", t=T, h=H, w=W)
30 return x
31
32
33def dynamic_thresholding2(x0):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected