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/06/08 18:04:22 UTC

[GitHub] piiswrong commented on a change in pull request #11183: Improve data transform for gluon data loader

piiswrong commented on a change in pull request #11183: Improve data transform for gluon data loader
URL: https://github.com/apache/incubator-mxnet/pull/11183#discussion_r193869194
 
 

 ##########
 File path: python/mxnet/gluon/data/vision/transforms.py
 ##########
 @@ -268,14 +271,29 @@ class Resize(Block):
     >>> transformer(image)
     <NDArray 500x1000x3 @cpu(0)>
     """
-    def __init__(self, size, interpolation=2):
+    def __init__(self, size, keep_aspect_ratio=True, interpolation=1):
         super(Resize, self).__init__()
-        if isinstance(size, numeric_types):
-            size = (size, size)
-        self._args = tuple(size) + (interpolation,)
+        self._keep = keep_aspect_ratio
+        self._size = size
+        self._interpolation = interpolation
 
     def forward(self, x):
-        return image.imresize(x, *self._args)
+        if isinstance(self._size, numeric_types):
+            if not self._keep:
+                wsize = self._size
+                hsize = self._size
+            else:
+                h, w, _ = x.shape
+                if h > w:
+                    wsize = self._size
+                    hsize = int(h * wsize / w)
+                else:
+                    hsize = self._size
+                    wsize = int(w * hsize / h)
+        else:
+            wsize, hsize = self._size
+        _args = tuple((wsize, hsize)) + (self._interpolation,)
 
 Review comment:
   image.imresize(x, wsize, hsize, self._interpolation)

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