Function Differences with tf.keras.preprocessing.image.random_rotation

View Source On Gitee

tf.keras.preprocessing.image.random_rotation

tf.keras.preprocessing.image.random_rotation(
    x,
    rg,
    row_axis=1,
    col_axis=2,
    channel_axis=0,
    fill_mode='nearest',
    cval=0.0,
    interpolation_order=1
)

For more information, see tf.keras.preprocessing.image.random_rotation.

mindspore.dataset.vision.RandomRotation

class mindspore.dataset.vision.RandomRotation(
    degrees,
    resample=Inter.NEAREST,
    expand=False,
    center=None,
    fill_value=0
)

For more information, see mindspore.dataset.vision.RandomRotation.

Differences

TensorFlow: Rotate the image with a random degree. The index of axis for rows, columns and channels can be specified by input parameters.

MindSpore: Rotate the image with a random degree and pad the area outside the rotated image. The image needs to be arranged in the order of rows, columns, and channels.

Code Example

# The following implements RandomRotation with MindSpore.
import numpy as np
import mindspore.dataset as ds
from mindspore.dataset.vision import Inter

image = np.random.random((28, 28, 3))
result = ds.vision.RandomRotation(90, resample=Inter.NEAREST)(image)
print(result.shape)
# (28, 28, 3)

# The following implements random_rotation with TensorFlow.
import tensorflow as tf

image = np.random.random((28, 28, 3))
result = tf.keras.preprocessing.image.random_rotation(
    image, 90, row_axis=0, col_axis=1, channel_axis=2, fill_mode='nearest')
print(result.shape)
# (28, 28, 3)