lkubin commented on a change in pull request #16794: Random rotation
URL: https://github.com/apache/incubator-mxnet/pull/16794#discussion_r370520728
##########
File path: python/mxnet/gluon/data/vision/transforms.py
##########
@@ -197,6 +199,78 @@ def hybrid_forward(self, F, x):
return F.image.normalize(x, self._mean, self._std)
+class Rotate(Block):
+ """Rotate the input image by a given angle. Keeps the original image shape.
+
+ Parameters
+ ----------
+ rotation_degrees : float32
+ Desired rotation angle in degrees, in range (-90, 90).
+ zoom_in : bool
+ Zoom in image so that no padding is present in final output.
+ zoom_out : bool
+ Zoom out image so that the entire original image is present in final
output.
+
+
+ Inputs:
+ - **data**: input tensor with (C x H x W) or (N x C x H x W) shape.
+
+ Outputs:
+ - **out**: output tensor with (C x H x W) or (N x C x H x W) shape.
+ """
+ def __init__(self, rotation_degrees, zoom_in=False, zoom_out=False):
+ super(Rotate, self).__init__()
+ if (rotation_degrees < -90 or rotation_degrees > 90):
+ raise ValueError("Rotation angle should be between -90 and 90
degrees")
+ self._args = (rotation_degrees, zoom_in, zoom_out)
+
+ def forward(self, x):
+ if x.dtype is not np.float32:
+ raise TypeError("This transformation only supports float32. "
+ "Consider calling it after ToTensor")
+ return image.imrotate(x, *self._args)
+
+
+class RandomRotation(Block):
+ """Random rotate the input image by a random angle.
+ Keeps the original image shape and aspect ratio.
+
+ Parameters
+ ----------
+ angle_limits: tuple
+ Tuple of 2 elements containing the upper and lower limit
+ for rotation angles in degree.
+ zoom_in : bool
+ Zoom in image so that no padding is present in final output.
+ zoom_out : bool
+ Zoom out image so that the entire original image is present in final
output.
+ rotate_with_proba : float32
+
+
+ Inputs:
+ - **data**: input tensor with (C x H x W) or (N x C x H x W) shape.
+
+ Outputs:
+ - **out**: output tensor with (C x H x W) or (N x C x H x W) shape.
+ """
+ def __init__(self, angle_limits, zoom_in=False, zoom_out=False,
rotate_with_proba=1.0):
+ super(RandomRotation, self).__init__()
+ lower, upper = angle_limits
+ if any(i < -90 for i in angle_limits) or any(i > 90 for i in
angle_limits):
+ raise ValueError("rotation angles should be between -90 and 90
degrees")
Review comment:
Fixed it
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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