(x, p=0.95)
| 19 | |
| 20 | |
| 21 | def 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 | |
| 33 | def dynamic_thresholding2(x0): |
nothing calls this directly
no outgoing calls
no test coverage detected