Function Differences with tf.image.central_crop

View Source On Gitee

tf.image.central_crop

tf.image.central_crop(
    image,
    central_fraction
)

For more information, see tf.image.central_crop.

mindspore.dataset.vision.CenterCrop

class mindspore.dataset.vision.CenterCrop(
    size
)

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

Differences

TensorFlow: Crop the central region of the image with desired crop ratio.

MindSpore: Crop the central region of the image with desired output size.

Code Example

# The following implements CenterCrop with MindSpore.
import numpy as np
import mindspore.dataset as ds

image = np.random.random((28, 28, 3))
result = ds.vision.CenterCrop((14, 14))(image)
print(result.shape)
# (14, 14, 3)

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

image = tf.random.normal((28, 28, 3))
result = tf.image.central_crop(image, 0.5)
print(result.shape)
# (14, 14, 3)