Temporal Gaussian smoothing for motion representation.
(motion_rep, kernel_size: int, sigma: float)
| 142 | |
| 143 | |
| 144 | def smooth_motion_rep(motion_rep, kernel_size: int, sigma: float): |
| 145 | """Temporal Gaussian smoothing for motion representation.""" |
| 146 | assert kernel_size % 2 == 1, 'kernel_size must be odd' |
| 147 | data_dim = motion_rep.shape[-1] |
| 148 | padding = (kernel_size - 1) // 2 |
| 149 | kernel = gaussian_kernel(kernel_size, |
| 150 | sigma).to(motion_rep.device)[None, None, |
| 151 | :].repeat( |
| 152 | data_dim, 1, 1) |
| 153 | motion_rep_smoothed = torch.nn.functional.conv1d( |
| 154 | motion_rep.transpose(0, 1).unsqueeze(0), |
| 155 | kernel, |
| 156 | padding=padding, |
| 157 | groups=data_dim) |
| 158 | motion_rep_smoothed = motion_rep_smoothed.squeeze(0).transpose(0, 1) |
| 159 | motion_rep_smoothed[:padding] = motion_rep[:padding] |
| 160 | motion_rep_smoothed[-padding:] = motion_rep[-padding:] |
| 161 | return motion_rep_smoothed |
| 162 | |
| 163 | |
| 164 | def maybe_corrupt_ref_motion(ref_motion: torch.Tensor, |
no test coverage detected