Pads images such that dimensions are divisible by 8
| 5 | |
| 6 | |
| 7 | class InputPadder: |
| 8 | """ Pads images such that dimensions are divisible by 8 """ |
| 9 | def __init__(self, dims, mode='sintel'): |
| 10 | self.ht, self.wd = dims[-2:] |
| 11 | pad_ht = (((self.ht // 8) + 1) * 8 - self.ht) % 8 |
| 12 | pad_wd = (((self.wd // 8) + 1) * 8 - self.wd) % 8 |
| 13 | if mode == 'sintel': |
| 14 | self._pad = [pad_wd//2, pad_wd - pad_wd//2, pad_ht//2, pad_ht - pad_ht//2] |
| 15 | elif mode == 'kitti400': |
| 16 | self._pad = [0, 0, 0, 400 - self.ht] |
| 17 | else: |
| 18 | self._pad = [pad_wd//2, pad_wd - pad_wd//2, 0, pad_ht] |
| 19 | |
| 20 | def pad(self, *inputs): |
| 21 | return [F.pad(x, self._pad, mode='replicate') for x in inputs] |
| 22 | |
| 23 | def unpad(self,x): |
| 24 | ht, wd = x.shape[-2:] |
| 25 | c = [self._pad[2], ht-self._pad[3], self._pad[0], wd-self._pad[1]] |
| 26 | return x[..., c[0]:c[1], c[2]:c[3]] |
| 27 | |
| 28 | def forward_interpolate(flow): |
| 29 | flow = flow.detach().cpu().numpy() |
no outgoing calls
no test coverage detected