I noticed that ImageDataGenerator, when setting the parameter zoom_range, uses a different random transformation for the horizontal and vertical axis, which produces images with a random aspect ratio.

I checked the source code (here) and the zoom transformation is indeed random for the horizontal and vertical axis. I think this is counterintuitive because I'm expecting a "zoom" transformation to simply magnify (or unmagnify) the input image. Instead, the output of zoom_range are images which are randomly stretched horizontally or vertically.

I suggest introducing an additional parameter like a boolean "zoom_keep_ar" (aspect ratio) which if True, keeps the aspect ratio constant (simple magnification, zx=zy=random), if False it also randomly change the aspect ratio (zx=rand, zy=rand).

Comment From: rsnitsch

I agree. I just had the same problem. I expected the images to be only zoomed-in/zoomed-out versions of the original images, but instead the aspect ratio is manipulated.

Comment From: waylonflinn

Just a note, for people looking for the code. It has been moved here.

Comment From: allaedding

the problem still not fix ? I was shocked when I saw the result 06/17/2019

Comment From: szetakyu

Still not fixed in keras-gpu 2.3.1. My sample image of a circle is changed into a oval.

Comment From: tobidelbruck

Yes, the offending lines are 801-807:

        if self.zoom_range[0] == 1 and self.zoom_range[1] == 1:
            zx, zy = 1, 1
        else:
            zx, zy = np.random.uniform(
                self.zoom_range[0],
                self.zoom_range[1],
                2)

Any easy suggestion to work around this?

Comment From: tobidelbruck

Also the documentation is a bit misleading, a zoom >1 minifies the resulted image, not magnifies it as I assumed. It can matter a lot when the zoom cuts off part of your images needed for classification. Same for shift ops, I suppose.