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

Function reverse_mask

core/utils/utils.py:222–235  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

220 return reverse_map
221
222def 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
237def refine_grid(grid):
238 H, W, _ = grid.shape

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected