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)
| 205 | |
| 206 | |
| 207 | def 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 | |
| 222 | def reverse_mask(mask, grid_map): |
| 223 | ''' |
nothing calls this directly
no outgoing calls
no test coverage detected