You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by jx...@apache.org on 2017/08/03 20:03:53 UTC
[incubator-mxnet] branch master updated: Add document for
BilinearSampler Op (#7203)
This is an automated email from the ASF dual-hosted git repository.
jxie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/master by this push:
new 4939dc2 Add document for BilinearSampler Op (#7203)
4939dc2 is described below
commit 4939dc25ff89607b8e0584f9b30a804f7183e07d
Author: Xu Dong <ds...@gmail.com>
AuthorDate: Fri Aug 4 04:03:50 2017 +0800
Add document for BilinearSampler Op (#7203)
* Update document for BilinearSamplerOp
* fix lint
* remove space
---
src/operator/bilinear_sampler.cc | 84 ++++++++++++++++++++++++++++++++++------
1 file changed, 72 insertions(+), 12 deletions(-)
diff --git a/src/operator/bilinear_sampler.cc b/src/operator/bilinear_sampler.cc
index f76e987..ca83a43 100644
--- a/src/operator/bilinear_sampler.cc
+++ b/src/operator/bilinear_sampler.cc
@@ -152,17 +152,77 @@ MXNET_REGISTER_OP_PROPERTY(BilinearSampler, BilinearSamplerProp)
.add_argument("grid", "NDArray-or-Symbol", "Input grid to the BilinearsamplerOp."
"grid has two channels: x_src, y_src")
.add_arguments(BilinearSamplerParam::__FIELDS__())
-.describe("Applies bilinear sampling to input feature map,"
-" which is the key of \"[NIPS2015] Spatial Transformer Networks\"\n "
-"output[batch, channel, y_dst, x_dst] = G(data[batch, channel, y_src, x_src)\n "
-"x_dst, y_dst enumerate all spatial locations in output\n "
-"x_src = grid[batch, 0, y_dst, x_dst]\n "
-"y_src = grid[batch, 1, y_dst, x_dst]\n "
-"G() denotes the bilinear interpolation kernel\n"
-"The out-boundary points will be padded as zeros. (The boundary is defined to be [-1, 1])\n"
-"The shape of output will be (data.shape[0], data.shape[1], grid.shape[2], grid.shape[3])\n"
-"The operator assumes that grid has been nomalized. "
-"If you want to design a CustomOp to manipulate grid, "
-"please refer to GridGeneratorOp.");
+.describe(R"code(Applies bilinear sampling to input feature map.
+
+Bilinear Sampling is the key of [NIPS2015] \"Spatial Transformer Networks\". The usage of the operator is very similar to remap function in OpenCV,
+except that the operator has the backward pass.
+
+Given :math:`data` and :math:`grid`, then the output is computed by
+
+.. math::
+ x_{src} = grid[batch, 0, y_{dst}, x_{dst}] \\
+ y_{src} = grid[batch, 1, y_{dst}, x_{dst}] \\
+ output[batch, channel, y_{dst}, x_{dst}] = G(data[batch, channel, y_{src}, x_{src})
+
+:math:`x_{dst}`, :math:`y_{dst}` enumerate all spatial locations in :math:`output`, and :math:`G()` denotes the bilinear interpolation kernel.
+The out-boundary points will be padded with zeros.The shape of the output will be (data.shape[0], data.shape[1], grid.shape[2], grid.shape[3]).
+
+The operator assumes that :math:`data` has 'NCHW' layout and :math:`grid` has been normalized to [-1, 1].
+
+BilinearSampler often cooperates with GridGenerator which generates sampling grids for BilinearSampler.
+GridGenerator supports two kinds of transformation: ``affine`` and ``warp``.
+If users want to design a CustomOp to manipulate :math:`grid`, please firstly refer to the code of GridGenerator.
+
+Example 1::
+
+ ## Zoom out data two times
+ data = array([[[[1, 4, 3, 6],
+ [1, 8, 8, 9],
+ [0, 4, 1, 5],
+ [1, 0, 1, 3]]]])
+
+ affine_matrix = array([[2, 0, 0],
+ [0, 2, 0]])
+
+ affine_matrix = reshape(affine_matrix, shape=(1, 6))
+
+ grid = GridGenerator(data=affine_matrix, transform_type='affine', target_shape=(4, 4))
+
+ out = BilinearSampler(data, grid)
+
+ out
+ [[[[ 0, 0, 0, 0],
+ [ 0, 3.5, 6.5, 0],
+ [ 0, 1.25, 2.5, 0],
+ [ 0, 0, 0, 0]]]
+
+
+Example 2::
+
+ ## shift data horizontally by -1 pixel
+
+ data = array([[[[1, 4, 3, 6],
+ [1, 8, 8, 9],
+ [0, 4, 1, 5],
+ [1, 0, 1, 3]]]])
+
+ warp_maxtrix = array([[[[1, 1, 1, 1],
+ [1, 1, 1, 1],
+ [1, 1, 1, 1],
+ [1, 1, 1, 1]],
+ [[0, 0, 0, 0],
+ [0, 0, 0, 0],
+ [0, 0, 0, 0],
+ [0, 0, 0, 0]]]])
+
+ grid = GridGenerator(data=warp_matrix, transform_type='warp')
+ out = BilinearSampler(data, grid)
+
+ out
+ [[[[ 4, 3, 6, 0],
+ [ 8, 8, 9, 0],
+ [ 4, 1, 5, 0],
+ [ 0, 1, 3, 0]]]
+)code" ADD_FILELINE);
} // namespace op
} // namespace mxnet
--
To stop receiving notification emails like this one, please contact
['"commits@mxnet.apache.org" <co...@mxnet.apache.org>'].