megengine.functional.nn.remap

remap(inp, map_xy, border_mode='replicate', scalar=0.0, interp_mode='linear')[源代码]

Applies remap transformation to batched 2D images.

The input images are transformed to the output images by the tensor map_xy. The output’s H and W are same as map_xy’s H and W.

参数
  • inp (Tensor) – input image

  • map_xy (Tensor) – batch, oh, ow, 2) transformation matrix

  • border_mode (str) – pixel extrapolation method. Default: “replicate”. Currently also support “constant”, “reflect”, “reflect_101”, “wrap”.

  • scalar (float) – value used in case of a constant border. Default: 0

  • interp_mode (str) – interpolation methods. Default: “linear”. Currently only support “linear” mode.

返回类型

Tensor

返回

output tensor.

实际案例

import numpy as np
from megengine import tensor
import megengine.functional as F
inp_shape = (1, 1, 4, 4)
inp = tensor(np.arange(16, dtype=np.float32).reshape(inp_shape))
map_xy_shape = (1, 2, 2, 2)
map_xy = tensor(np.array([[[1., 0.],[0., 1.]],
                    [[0., 1.],[0., 1.]]],
                    dtype=np.float32).reshape(map_xy_shape))
out = F.vision.remap(inp, map_xy)
print(out.numpy())

Outputs:

[[[[1. 4.]
   [4. 4.]]]]