Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly the shear do in ImageDataGenerator of Keras?

I cant understand what is the effect of shear parameter in ImageDataGenerator of keras

I had tried to use an image to apply the shear by apply_transform member function in ImageDataGenerator. I can see the image seems to be rotated and stretched out after apply this function. But I cant understand what exactly it did.

from keras.preprocessing.image import ImageDataGenerator
import matplotlib.pyplot as plt
import numpy as np

(train_x, train_y) , (test_x,test_Y) = cifar10.load_data()
img = train_x[0]
img_gen = ImageDataGenerator()


shear_intensity = np.arange(0,110,10, dtype = int)

nrow = 4
ncol = 3


plt.figure(figsize = (14,14))
for i,shear in enumerate(shear_intensity):
  plt.title(f'shear intensity : {shear}')
  plt.subplot(nrow, ncol, i+1)
  plt.imshow(img_gen.apply_transform(img, {'shear' : shear}))
plt.show()

The image does have some change, but I cant understand the effect.

like image 770
Ray Xie Avatar asked Aug 01 '19 03:08

Ray Xie


People also ask

How does keras ImageDataGenerator work?

Keras ImageDataGenerator is a gem! It lets you augment your images in real-time while your model is still training! You can apply any random transformations on each training image as it is passed to the model. This will not only make your model robust but will also save up on the overhead memory!

What is shear data augmentation?

The shear augmentation is a part of the suite of data augmentation options in the Roboflow platform. Data augmentation in computer vision is a technique to generate more training data from a base training set, by tweaking the base images programmatically.

What is the shear range?

shear_range specifies the angle of the slant in degrees.

How many images does ImageDataGenerator generate?

Then the "ImageDataGenerator" will produce 10 images in each iteration of the training. An iteration is defined as steps per epoch i.e. the total number of samples / batch_size. In above case, in each epoch of training there will be 100 iterations.


1 Answers

'Shear' means that the image will be distorted along an axis, mostly to create or rectify the perception angles. It's usually used to augment images so that computers can see how humans see things from different angles. Shear example

  • Source: https://www.tutorialspoint.com/javafx/shearing_transformation
like image 136
LazyCoder Avatar answered Sep 27 '22 19:09

LazyCoder