I'm working on CNN(Convolution Neural Network) for image classification problem. I have a data set of 1000 images, this images are not enough to fit the model I have designed and I want to increase the number of images before training the CNN. How to augment my data set by using python.
Asked
Active
Viewed 1,829 times
2 Answers
1
You can use keras's ImageDataGenerator
class. This class has many interesting features to generate augmented image dataset. This class can be used to augment the dataset from folder also.
E.g.
generator = ImageDataGenerator(
rotation_range=20,
width_shift_range=0.2,
height_shift_range=0.2,
horizontal_flip=True)
More information on the ImageDataGenerator
class is found here.
Now you can use this generator with your keras model as follows
model.fit_generator(generator.flow(x_train, y_train, batch_size= ... ),
steps_per_epoch= .... , epochs= ... )
To generate augmented dataset from folder use flow_from_directory
method of the class.
model.fit_generator(generator.flow_from_directory(directory, target_size=(64, 64), batch_size= ...),steps_per_epoch= .... , epochs= ... )

Mitiku
- 5,337
- 3
- 18
- 35
-
hey @Mitiku thanks a lot to your comment and how could I know how many images are generated ? – Yidne May 21 '19 at 06:04
-
Number of images generated for all `epochs == batch_size * steps_per_epoch * epochs`, Number of image generated for epoch is `batch_size * steps_per_epoch` and Number of images generated for batch is `batch_size`. But why you need the information any way? – Mitiku May 21 '19 at 07:48