zhreshold commented on a change in pull request #13802: Image normalize 
operator - GPU support, 3D/4D inputs
URL: https://github.com/apache/incubator-mxnet/pull/13802#discussion_r251106855
 
 

 ##########
 File path: src/operator/image/image_random.cc
 ##########
 @@ -49,21 +49,64 @@ NNVM_REGISTER_OP(_image_to_tensor)
 .add_argument("data", "NDArray-or-Symbol", "The input.");
 
 NNVM_REGISTER_OP(_image_normalize)
-.describe(R"code()code" ADD_FILELINE)
+.describe(R"code(Normalize an tensor of shape (C x H x W) or (N x C x H x W) 
with mean and
+    standard deviation.
+
+    Given mean `(m1, ..., mn)` and std `(s\ :sub:`1`\ , ..., s\ :sub:`n`)` for 
`n` channels,
+    this transform normalizes each channel of the input tensor with:
+
+.. math::
+
+        output[i] = (input[i] - m\ :sub:`i`\ ) / s\ :sub:`i`
+
+    If mean or std is scalar, the same value will be applied to all channels.
+
+    Default value for mean is 0.0 and stand deviation is 1.0.
+
+Example:
+
+    .. code-block:: python
+        image = mx.nd.random.uniform(0, 1, (3, 4, 2))
+        normalize(image, mean=(0, 1, 2), std=(3, 2, 1))
+            [[[ 0.18293785  0.19761486]
+              [ 0.23839645  0.28142193]
+              [ 0.20092112  0.28598186]
+              [ 0.18162774  0.28241724]]
+             [[-0.2881726  -0.18821815]
+              [-0.17705294 -0.30780914]
+              [-0.2812064  -0.3512327 ]
+              [-0.05411351 -0.4716435 ]]
+             [[-1.0363373  -1.7273437 ]
+              [-1.6165586  -1.5223348 ]
+              [-1.208275   -1.1878313 ]
+              [-1.4711051  -1.5200229 ]]]
+            <NDArray 3x4x2 @cpu(0)>
+)code" ADD_FILELINE)
+.set_attr_parser(ParamParser<NormalizeParam>)
 .set_num_inputs(1)
 .set_num_outputs(1)
-.set_attr_parser(ParamParser<NormalizeParam>)
-.set_attr<nnvm::FInferShape>("FInferShape", NormalizeShape)
-.set_attr<nnvm::FInferType>("FInferType", ElemwiseType<1, 1>)
+.set_attr<nnvm::FListInputNames>("FListInputNames",
+  [](const NodeAttrs& attrs) {
+    return std::vector<std::string>{"data"};
+  })
+.set_attr<nnvm::FInferShape>("FInferShape", NormalizeOpShape)
+.set_attr<nnvm::FInferType>("FInferType", NormalizeOpType)
+.set_attr<FCompute>("FCompute<cpu>", NormalizeOpForward<cpu>)
 .set_attr<nnvm::FInplaceOption>("FInplaceOption",
-  [](const NodeAttrs& attrs){
+  [](const NodeAttrs& attrs) {
     return std::vector<std::pair<int, int> >{{0, 0}};
   })
-.set_attr<FCompute>("FCompute<cpu>", Normalize)
-.set_attr<nnvm::FGradient>("FGradient", ElemwiseGradUseNone{ "_copy" })
-.add_argument("data", "NDArray-or-Symbol", "The input.")
+.set_attr<nnvm::FGradient>("FGradient", ElemwiseGradUseIn{ 
"_backward_image_normalize"})
+.add_argument("data", "NDArray-or-Symbol", "Input ndarray")
 .add_arguments(NormalizeParam::__FIELDS__());
 
+NNVM_REGISTER_OP(_backward_image_normalize)
+.set_attr_parser(ParamParser<NormalizeParam>)
+.set_num_inputs(2)
 
 Review comment:
   why 2 here?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to