Reputation: 899
In Keras there is an option to set the size of the validation set batches to one:
valid_batches = ImageDataGenerator().flow_from_directory(valid_path, ... batch_size=1)
Is it correct that the model then just uses one object from the validation data to validate the model after each training data epoch? If that is the case then my model should not get a very good validation score. But when I run the model it runs without any problems, keeps improving and seems to be using many validation objects for evaluation. Can someone explain this please? Thank you.
Upvotes: 1
Views: 3368
Reputation: 11543
You really give us little information there so I'll try to give you the information that you need in order to understand and maybe fix it by yourself.
valid_batches = ImageDataGenerator().flow_from_directory(valid_path, ... batch_size=1)
This gives you a generator. It'll do what python generators do : yield batches of validation data, those batches will be of size 1 in your case.
However, when you do :
model.fit_generator(train_batches, validation_data=valid_batches, ... )
What keras does is to use your generator to get some validation data. But it will not stop after one call to valid_batches, it will make several setps. A batch isn't your whole validation set, keras assumes that you will give it its validation data set by batches. So it iterates on your validation_data generator as many times as asked.
The way to specify how many times you want to generate batches in one validation step is to use the validation_steps
argument like this :
model.fit_generator(train_batches, validation_data=valid_batches, validation_steps=10... )
That way, your validation will be using validation_steps * batch_size = 10 * 1 = 10
samples for each validation executed.
I hope it helps a bit :-) If not, please be more specific about your code. A good stack overflow question should contain a minimal reproducible code for your error.
Upvotes: 4