From a2f1a07912ca0dff8c0cf97ab4a6ebf15ee011f1 Mon Sep 17 00:00:00 2001 From: Indhu Bharathi Date: Wed, 24 May 2017 13:55:17 -0700 Subject: [PATCH 1/4] Update documentation for mxnet.ndarray.GridGenerator. Thanks @Lyken17 for https://github.com/dmlc/mxnet/issues/6147 --- python/mxnet/ndarray_doc.py | 34 +++++++++++++++++++++++++++++++ src/operator/grid_generator-inl.h | 11 +++++----- src/operator/grid_generator.cc | 6 ++---- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/python/mxnet/ndarray_doc.py b/python/mxnet/ndarray_doc.py index 9cc4545b9fe3..fb7f949a173e 100644 --- a/python/mxnet/ndarray_doc.py +++ b/python/mxnet/ndarray_doc.py @@ -97,6 +97,40 @@ class CustomDoc(NDArrayDoc): >>> output = mx.symbol.Custom(op_type='my_custom_operator', data=input) """ +class GridGeneratorDoc(NDArrayDoc): + """ + Examples + -------- + >>> data = mx.nd.array(np.ones((1,2,4,4)) * 1) + >>> res = mx.ndarray.GridGenerator(data, "warp") + >>> print(res.asnumpy()) + [[[[-0.33333331 0.33333337 1. 1.66666675] + [-0.33333331 0.33333337 1. 1.66666675] + [-0.33333331 0.33333337 1. 1.66666675] + [-0.33333331 0.33333337 1. 1.66666675]] + [[-0.33333331 -0.33333331 -0.33333331 -0.33333331] + [ 0.33333337 0.33333337 0.33333337 0.33333337] + [ 1. 1. 1. 1. ] + [ 1.66666675 1.66666675 1.66666675 1.66666675]]]] + >>> + >>> data = mx.nd.array(np.ones((1,2,4,4)) * 2) + >>> res = mx.ndarray.GridGenerator(data, "warp") + >>> print(res.asnumpy()) + [[[[ 0.33333337 1. 1.66666675 2.33333325] + [ 0.33333337 1. 1.66666675 2.33333325] + [ 0.33333337 1. 1.66666675 2.33333325] + [ 0.33333337 1. 1.66666675 2.33333325]] + [[ 0.33333337 0.33333337 0.33333337 0.33333337] + [ 1. 1. 1. 1. ] + [ 1.66666675 1.66666675 1.66666675 1.66666675] + [ 2.33333325 2.33333325 2.33333325 2.33333325]]]] + >>> + >>> x = mx.nd.array(np.ones((32, 6))) + >>> res = mx.ndarray.GridGenerator(x, "affine", target_shape=(6,6)) + >>> print(res.asnumpy().shape) + (32, 2, 6, 6) + """ + def _build_doc(func_name, desc, arg_names, diff --git a/src/operator/grid_generator-inl.h b/src/operator/grid_generator-inl.h index 1f88cf4935da..5475bd394608 100644 --- a/src/operator/grid_generator-inl.h +++ b/src/operator/grid_generator-inl.h @@ -36,12 +36,13 @@ struct GridGeneratorParam : public dmlc::Parameter { DMLC_DECLARE_FIELD(transform_type) .add_enum("affine", grid::kAffine) .add_enum("warp", grid::kWarp) - .describe("transformation type\n " - "if transformation type is affine, data is affine matrix : (batch, 6)\n " - "if transformation type is warp, data is optical flow : (batch, 2, h, w)"); + .describe("The type of transformation. For `affine`, input data should be an affine matrix " + "of size (batch, 6). For `warp`, input data should be an optical flow of size " + "(batch, 2, h, w)."); DMLC_DECLARE_FIELD(target_shape).set_default(TShape(shape, shape + 2)) - .describe("if transformation type is affine, the operator need a target_shape : (H, W)\n " - "if transofrmation type is warp, the operator will ignore target_shape"); + .describe("Specifies the output shape. This is required when " + "transformation type is `affine`." + ); } }; diff --git a/src/operator/grid_generator.cc b/src/operator/grid_generator.cc index 831e8a359493..8625d1ba971a 100644 --- a/src/operator/grid_generator.cc +++ b/src/operator/grid_generator.cc @@ -32,11 +32,9 @@ Operator *GridGeneratorProp::CreateOperatorEx(Context ctx, std::vector * DMLC_REGISTER_PARAMETER(GridGeneratorParam); MXNET_REGISTER_OP_PROPERTY(GridGenerator, GridGeneratorProp) -.add_argument("data", "NDArray-or-Symbol", "Input data to the GridGeneratorOp.") -.describe("if transformation type is affine, data is affine matrix : (batch, 6)") -.describe("if transformation type is warp, data is optical flow : (batch, 2, h, w)") +.add_argument("data", "NDArray-or-Symbol", "Input data to the function.") .add_arguments(GridGeneratorParam::__FIELDS__()) -.describe("Generates sampling grid for bilinear sampling."); +.describe("Generates 2D sampling grid for bilinear sampling."); } // namespace op } // namespace mxnet From c5e1acd28c391acdf54c894ae8112b2400a6cf5c Mon Sep 17 00:00:00 2001 From: Indhu Bharathi Date: Wed, 24 May 2017 15:33:44 -0700 Subject: [PATCH 2/4] Fix lint error. --- src/operator/grid_generator-inl.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/operator/grid_generator-inl.h b/src/operator/grid_generator-inl.h index 5475bd394608..d39b46640a69 100644 --- a/src/operator/grid_generator-inl.h +++ b/src/operator/grid_generator-inl.h @@ -41,8 +41,7 @@ struct GridGeneratorParam : public dmlc::Parameter { "(batch, 2, h, w)."); DMLC_DECLARE_FIELD(target_shape).set_default(TShape(shape, shape + 2)) .describe("Specifies the output shape. This is required when " - "transformation type is `affine`." - ); + "transformation type is `affine`."); } }; From 1c5e7386e0c0ca89ee68e141a43e68bef141b84f Mon Sep 17 00:00:00 2001 From: Indhu Bharathi Date: Thu, 25 May 2017 13:09:52 -0700 Subject: [PATCH 3/4] Minor fix. --- src/operator/grid_generator-inl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/operator/grid_generator-inl.h b/src/operator/grid_generator-inl.h index d39b46640a69..04fe7ec1c5fd 100644 --- a/src/operator/grid_generator-inl.h +++ b/src/operator/grid_generator-inl.h @@ -40,8 +40,8 @@ struct GridGeneratorParam : public dmlc::Parameter { "of size (batch, 6). For `warp`, input data should be an optical flow of size " "(batch, 2, h, w)."); DMLC_DECLARE_FIELD(target_shape).set_default(TShape(shape, shape + 2)) - .describe("Specifies the output shape. This is required when " - "transformation type is `affine`."); + .describe("Specifies the output shape (H, W). This is required if transformation type is " + "`affine`. If transformation type is `warp`, this parameter is ignored."); } }; From 32eba0aa5b9f5df4537c034c279ace4917c23a84 Mon Sep 17 00:00:00 2001 From: Indhu Bharathi Date: Thu, 25 May 2017 14:11:04 -0700 Subject: [PATCH 4/4] Remove the example. --- python/mxnet/ndarray_doc.py | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/python/mxnet/ndarray_doc.py b/python/mxnet/ndarray_doc.py index fb7f949a173e..9cc4545b9fe3 100644 --- a/python/mxnet/ndarray_doc.py +++ b/python/mxnet/ndarray_doc.py @@ -97,40 +97,6 @@ class CustomDoc(NDArrayDoc): >>> output = mx.symbol.Custom(op_type='my_custom_operator', data=input) """ -class GridGeneratorDoc(NDArrayDoc): - """ - Examples - -------- - >>> data = mx.nd.array(np.ones((1,2,4,4)) * 1) - >>> res = mx.ndarray.GridGenerator(data, "warp") - >>> print(res.asnumpy()) - [[[[-0.33333331 0.33333337 1. 1.66666675] - [-0.33333331 0.33333337 1. 1.66666675] - [-0.33333331 0.33333337 1. 1.66666675] - [-0.33333331 0.33333337 1. 1.66666675]] - [[-0.33333331 -0.33333331 -0.33333331 -0.33333331] - [ 0.33333337 0.33333337 0.33333337 0.33333337] - [ 1. 1. 1. 1. ] - [ 1.66666675 1.66666675 1.66666675 1.66666675]]]] - >>> - >>> data = mx.nd.array(np.ones((1,2,4,4)) * 2) - >>> res = mx.ndarray.GridGenerator(data, "warp") - >>> print(res.asnumpy()) - [[[[ 0.33333337 1. 1.66666675 2.33333325] - [ 0.33333337 1. 1.66666675 2.33333325] - [ 0.33333337 1. 1.66666675 2.33333325] - [ 0.33333337 1. 1.66666675 2.33333325]] - [[ 0.33333337 0.33333337 0.33333337 0.33333337] - [ 1. 1. 1. 1. ] - [ 1.66666675 1.66666675 1.66666675 1.66666675] - [ 2.33333325 2.33333325 2.33333325 2.33333325]]]] - >>> - >>> x = mx.nd.array(np.ones((32, 6))) - >>> res = mx.ndarray.GridGenerator(x, "affine", target_shape=(6,6)) - >>> print(res.asnumpy().shape) - (32, 2, 6, 6) - """ - def _build_doc(func_name, desc, arg_names,