tf.image.resize_with_crop_or_pad(image, desired_height, desired_width)
Images smaller than desired_height
and desired_width
will be padded, and those larger will be centrally cropped.
import tensorflow as tf
import matplotlib.pyplot as plt
_, ((first, *rest), _) = tf.keras.datasets.cifar10.load_data()
modified = tf.image.resize_with_crop_or_pad(first[None, ...]/255, 48, 48)
plt.imshow(tf.squeeze(modified))
plt.show()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…