MCPcopy Create free account
hub / github.com/drinkingcoder/NeuralMarker / reverse_mapping

Function reverse_mapping

core/utils/utils.py:207–220  ·  view source on GitHub ↗

Input: flow: B x 2 x H x W torch.Tensor.cuda, represent the flow from A to B grid_map: B x H x W x 2 torch.Tensor.cuda, grid mapping from B to A Output: reverse_map: B x H x W x 2 torch.Tensor.cuda, grid mapping from A to B

(flow, grid_map)

Source from the content-addressed store, hash-verified

205
206
207def reverse_mapping(flow, grid_map):
208 '''
209 Input:
210 flow: B x 2 x H x W torch.Tensor.cuda, represent the flow from A to B
211 grid_map: B x H x W x 2 torch.Tensor.cuda, grid mapping from B to A
212 Output:
213 reverse_map: B x H x W x 2 torch.Tensor.cuda, grid mapping from A to B
214 '''
215 _, H, W, _ = grid_map.shape
216 grid_norm = grid_map.clone()
217 grid_norm[:, :, :, 0] = (grid_norm[:, :, :, 0] * 2 - W + 1) / (W - 1)
218 grid_norm[:, :, :, 1] = (grid_norm[:, :, :, 1] * 2 - H + 1) / (H - 1)
219 reverse_map = F.grid_sample(flow, grid_norm, align_corners=True).permute([0, 2, 3, 1]) + grid_map
220 return reverse_map
221
222def reverse_mask(mask, grid_map):
223 '''

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected