anirudhacharya commented on a change in pull request #13679: add crop gluon
transform
URL: https://github.com/apache/incubator-mxnet/pull/13679#discussion_r247271491
##########
File path: python/mxnet/gluon/data/vision/transforms.py
##########
@@ -168,6 +168,57 @@ def hybrid_forward(self, F, x):
return F.image.normalize(x, self._mean, self._std)
+class Crop(HybridBlock):
+ """Crop the input image with and optionally resize it.
+
+ Makes a crop of the original image then optionally resize it to the
specified size.
+
+ Parameters
+ ----------
+ x0 : int
+ Left boundary of the cropping area
+ y0 : int
+ Top boundary of the cropping area
+ w : int
+ Width of the cropping area
+ h : int
+ Height of the cropping area
+ size : int or tuple of (w, h)
+ Optional, resize to new size after cropping
+ interp : int, optional
+ Optional, interpolation method. See opencv for details.
+
+ Inputs:
+ - **data**: input tensor with (H x W x C) or (N x H x W x C) shape.
+
+ Outputs:
+ - **out**: output tensor with (H x W x C) or (N x H x W x C) shape.
+
+ Examples
+ --------
+ >>> transformer = vision.transforms.Crop(0, 0, 100, 100)
+ >>> image = mx.nd.random.uniform(0, 255, (224, 224,
3)).astype(dtype=np.uint8)
+ >>> transformer(image)
+ <NDArray 500x1000x3 @cpu(0)>
+ >>> image = mx.nd.random.uniform(0, 255, (3, 224, 224,
3)).astype(dtype=np.uint8)
+ <NDArray 3x500x1000x3 @cpu(0)>
+ >>> transformer = vision.transforms.Crop(0, 0, 100, 100, (50, 50), 1)
+ >>> transformer(image)
+ <NDArray 3x50x50 @cpu(0)>
+ """
+ def __init__(self, x0, y0, width, height, size=None, interpolation=None):
+ super(Crop, self).__init__()
+ self._x0 = x0
+ self._y0 = y0
+ self._width = width
+ self._height = height
+ self._size = size
+ self._interpolation = interpolation
+
+ def hybrid_forward(self, F, x):
+ return F.image.crop(x, self._x0, self._y0, self._width, self._height,
self._size, self._interpolation)
Review comment:
instead of adding `image.crop` operator, why not call `image.fixed_crop`?
and optimize the `fixed_crop` implementation under the hood?
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services