Issue
I have a directory named TRAIN, and it has 37 subdirectoris which contains images of different size, I wanted to load those images with TensorFlow's ImageDataGenerator, but it needs images of same size. I want to add padding to those images to resize them.
tf.image.resize_with_crop_or_pad(
image, target_height, target_width
)
I found this above code on internet but I don't know how to use it.
Solution
Resize the images from the directories using tf.keras.preprocessing.image_dataset_from_directory
.
Mention the required image size in image_size=(img_height, img_width)
. Default image_size will be (256,256)
Find the below sample code
import tensorflow as tf
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
data_dir,
validation_split=0.2,
subset="training",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
Answered By - TFer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.