You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/05/05 00:40:28 UTC

[GitHub] hetong007 opened a new issue #10818: Feature Request: Improve ndarray.pad to be an numpy.pad equivalent

hetong007 opened a new issue #10818: Feature Request: Improve ndarray.pad to be an numpy.pad equivalent
URL: https://github.com/apache/incubator-mxnet/issues/10818
 
 
   ## Current Limitations
   
   Comparing to `numpy.pad`, the current (https://github.com/apache/incubator-mxnet/commit/3bba4c8f6362df8b3355404002eab6a6c88123d6) `mxnet.ndarray.pad` has the following limitations:
   
   1. It only works with real data type (being fixed in https://github.com/apache/incubator-mxnet/pull/10815)
   2. It only works with 4-D or 5-D ndarray: https://github.com/apache/incubator-mxnet/blob/master/src/operator/pad-inl.h#L205
   2. It doesn't allow padding on the first two dimensions: https://github.com/apache/incubator-mxnet/blob/master/src/operator/pad-inl.h#L208
   
   ## A Scenario with Difficulties
   
   In resnet training on CIFAR10, the standard data augmentation includes:
   1. Pad the input 32x32 image to 40x40 with zeros.
   2. Randomly crop a 32x32 area from the padded array.
   
   In the current `mxnet.image` implementations, the image at the crop stage is of shape `Height x Width x Channel`. To make use of our `nd.pad`, one needs to 
   1. Cast the image from `int` to `float32`.
   2. Expand the dimension of the image to be `Null x Null x Height x Width x Channel`
   3. Apply `nd.pad` on the 2nd and 3rd (Height, Width) dimensions
   4. Squeeze the array back to `Height x Width x Channel`
   
   The above combination of operations introduces unacceptable overhead for CIFAR10 training. A slightly faster workaround is to cast the array to `numpy.array` and apply `np.pad`, but it still introduces unnecessary costs.
   
   Without the limitations, one can simply apply `nd.pad` on the 0th and 1st dimension, i.e. Height and Width in the image array, at no extra cost.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services