I have a folder with images of different sizes. I tried to use ImageDataGenerator with flow_from_directory for batch loading / data augmentation.
Is there a way to keep the aspect ratios of my images ? It seems like the images are being stretched to target_size : I would like to "pad" my images without deforming them (filling the gaps with a constant value)
Here's my code :
datagen = ImageDataGenerator(
rescale = 1./255,
fill_mode='constant')
generator = datagen.flow_from_directory(
'data/images',
target_size=(256,256),
color_mode = 'grayscale',
batch_size=99,
class_mode=None,
shuffle=False)
Images are being stretched to (256,256).
I found an answer to my question.
There's currently no way to keep aspect ratio when using ImageDataGenerator / flow_from_directory, but a pull request is opened on Github to add this feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With