Keras - How to use ImageDataGenerator without deformation aspect ratio

I have a folder with images of different sizes. I tried using ImageDataGenerator with flow_from_directory to batch load / expand data.

Is there a way to keep the proportions of my images? It seems that the images are stretched to target_size: I would like to โ€œoverlayโ€ my images without warping them (filling in the blanks with a constant value)

Here is 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 stretched to (256,256).

+4
source share
1 answer

I found the answer to my question.

ImageDataGenerator/flow_from_directory, Github pull request.

+2

Source: https://habr.com/ru/post/1670862/


All Articles