Reputation: 111
I have please two questions concerning the ImageDataGenerator:
1) Are the same augmentations used on the whole batch or each image gets its own random transformation? e.g. for rotation, does the module rotates all the images in the batch with same angle or each image get a random rotation angle ?
2) The data in ImageDataGenerator.flow is looped over (in batches) indefinitely. Is there a way to stop this infinite loop, i.e. doing the augmentation only for n number of time. Because I need to modify the batch_size in each step (not each epoch). Thanks
Upvotes: 2
Views: 2401
Reputation: 111
@Neal: Thank you for the prompt answer! You were right, I probably need to better explain my task. My work is somehow similar to classifying video sequences, but my data is saved in a database. I want my code to follow this steps for one epoch:
For i in (number_of_sequences):
datagen = ImageDataGenerator()
and datagen.flow())
My first thought was using model.fit_generator(generator = ImageDataGenerator().flow()) but this way, I can not modify my batch_size, and honestly I did not understand your solution. Sorry for the long post, but I’m still a novice in both python and NN, but I’m really a big fan of Keras ;) Thnx!
Upvotes: 0
Reputation: 942
Answer from Francois Chollet:
1) Are the same augmentations used on the whole batch or each image gets its own random transformation? e.g. for rotation, does the module rotates all the images in the batch with same angle or each image get a random rotation angle ?
Every single sample has a different unique transformation (e.g. a random rotation within a certain range).
2) The data in ImageDataGenerator.flow is looped over (in batches) indefinitely. Is there a way to stop this infinite loop, i.e. doing the augmentation only for n number of time. Because I need to modify the batch_size in each step (not each epoch). Thanks
Unclear what is meant here. But if you are using model.fit_generator(ImageDataGenerator.flow())
then you can specify samples_per_epoch=...
to only yield a specific number of samples from the generator. If you want batch-level granularity, you could do:
for x, y in model.fit_generator(ImageDataGenerator.flow()):
model.train_on_batch(x, y)
In that case you can just break
(it's a loop) after any number of batches that you want.
Upvotes: 1