MCPcopy Create free account
hub / github.com/drinkingcoder/FlowFormer-Official / InputPadder

Class InputPadder

evaluate_FlowFormer_tile.py:32–55  ·  view source on GitHub ↗

Pads images such that dimensions are divisible by 8

Source from the content-addressed store, hash-verified

30TRAIN_SIZE = [432, 960]
31
32class InputPadder:
33 """ Pads images such that dimensions are divisible by 8 """
34 def __init__(self, dims, mode='sintel'):
35 self.ht, self.wd = dims[-2:]
36 pad_ht = (((self.ht // 8) + 1) * 8 - self.ht) % 8
37 pad_wd = (((self.wd // 8) + 1) * 8 - self.wd) % 8
38 if mode == 'sintel':
39 self._pad = [pad_wd//2, pad_wd - pad_wd//2, pad_ht//2, pad_ht - pad_ht//2]
40 elif mode == 'kitti432':
41 self._pad = [0, 0, 0, 432 - self.ht]
42 elif mode == 'kitti400':
43 self._pad = [0, 0, 0, 400 - self.ht]
44 elif mode == 'kitti376':
45 self._pad = [0, 0, 0, 376 - self.ht]
46 else:
47 self._pad = [pad_wd//2, pad_wd - pad_wd//2, 0, pad_ht]
48
49 def pad(self, *inputs):
50 return [F.pad(x, self._pad, mode='constant', value=0.0) for x in inputs]
51
52 def unpad(self,x):
53 ht, wd = x.shape[-2:]
54 c = [self._pad[2], ht-self._pad[3], self._pad[0], wd-self._pad[1]]
55 return x[..., c[0]:c[1], c[2]:c[3]]
56
57def compute_grid_indices(image_shape, patch_size=TRAIN_SIZE, min_overlap=20):
58 if min_overlap >= patch_size[0] or min_overlap >= patch_size[1]:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected