Input: mask: B x 1 x H x W torch.Tensor.cuda, represent the mask of A 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
(mask, grid_map)
| 220 | return reverse_map |
| 221 | |
| 222 | def reverse_mask(mask, grid_map): |
| 223 | ''' |
| 224 | Input: |
| 225 | mask: B x 1 x H x W torch.Tensor.cuda, represent the mask of A |
| 226 | grid_map: B x H x W x 2 torch.Tensor.cuda, grid mapping from B to A |
| 227 | Output: |
| 228 | reverse_map: B x H x W x 2 torch.Tensor.cuda, grid mapping from A to B |
| 229 | ''' |
| 230 | _, H, W, _ = grid_map.shape |
| 231 | grid_norm = grid_map.clone() |
| 232 | grid_norm[:, :, :, 0] = (grid_norm[:, :, :, 0] * 2 - W + 1) / (W - 1) |
| 233 | grid_norm[:, :, :, 1] = (grid_norm[:, :, :, 1] * 2 - H + 1) / (H - 1) |
| 234 | reverse_mask = F.grid_sample(mask, grid_norm, align_corners=True).permute([0, 2, 3, 1]) |
| 235 | return reverse_mask |
| 236 | |
| 237 | def refine_grid(grid): |
| 238 | H, W, _ = grid.shape |
nothing calls this directly
no outgoing calls
no test coverage detected