Intelligent Projects Using Python
上QQ阅读APP看书,第一时间看更新

Additional image generation through affine transformation

The keras image generator would work for our task using the following class:

datagen = ImageDataGenerator(
horizontal_flip = True,
vertical_flip = True,
width_shift_range = 0.1,
height_shift_range = 0.1,
channel_shift_range=0,
zoom_range = 0.2,
rotation_range = 20)

As you can see from the defined generator, we have enabled horizontal and vertical flipping, which is nothing but a reflection of the images along the horizontal and vertical axes, respectively. Similarly, we have defined the image translations along the width and the height to be within 10% of the pixel locations along those directions. The range of rotation is confined to an angle of 20 degrees, whereas the scale factor is defined to be within 0.8 to 1.2 of the original image.