(window_size: int, sigma)
| 301 | |
| 302 | |
| 303 | def _gaussian(window_size: int, sigma): |
| 304 | if isinstance(sigma, float): |
| 305 | sigma = torch.tensor([[sigma]]) |
| 306 | |
| 307 | batch_size = sigma.shape[0] |
| 308 | |
| 309 | x = (torch.arange(window_size, device=sigma.device, |
| 310 | dtype=sigma.dtype) - window_size // 2).expand(batch_size, -1) |
| 311 | |
| 312 | if window_size % 2 == 0: |
| 313 | x = x + 0.5 |
| 314 | |
| 315 | gauss = torch.exp(-x.pow(2.0) / (2 * sigma.pow(2.0))) |
| 316 | |
| 317 | return gauss / gauss.sum(-1, keepdim=True) |
| 318 | |
| 319 | |
| 320 | def _gaussian_blur2d(input, kernel_size, sigma): |