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/01/31 19:33:20 UTC

[GitHub] piiswrong commented on a change in pull request #7938: instance norm and reflection padding

piiswrong commented on a change in pull request #7938: instance norm and reflection padding
URL: https://github.com/apache/incubator-mxnet/pull/7938#discussion_r165162581
 
 

 ##########
 File path: python/mxnet/gluon/nn/conv_layers.py
 ##########
 @@ -1007,3 +1008,32 @@ def __init__(self, layout='NCDHW', **kwargs):
         assert layout == 'NCDHW', "Only supports NCDHW layout for now"
         super(GlobalAvgPool3D, self).__init__(
             (1, 1, 1), None, 0, True, True, 'avg', **kwargs)
+
+
+class ReflectionPad2D(HybridBlock):
+    """Pads the input tensor using the reflection of the input boundary.
+
+    Parameters
+    ----------
+        `padding` is a tuple of integer padding widths for each axis of the format
+``(before_1, after_1, ... , before_N, after_N)``. The `padding` should be of length ``2*N``
+where ``N`` is the number of dimensions of the array.
+
+    Shape:
+        - Input: :math:`(N, C, H_{in}, W_{in})`
+        - Output: :math:`(N, C, H_{out}, W_{out})` where
+          :math:`H_{out} = H_{in} + paddingTop + paddingBottom`
+          :math:`W_{out} = W_{in} + paddingLeft + paddingRight`
+
+    Examples
+    --------
+    >>> m = nn.ReflectionPad2D(3)
+    >>> input = mx.nd.random.normal(shape=(16, 3, 224, 224))
+    >>> output = m(input)
+    """
+    def __init__(self, padding=0, **kwargs):
+        super(ReflectionPad2D, self).__init__(**kwargs)
+        self._padding = padding
+
+    def hybrid_forward(self, F, x):
+        return F.pad(x, mode='reflect', padding=self._padding)
 
 Review comment:
   I think we should have this.

----------------------------------------------------------------
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