问题
What's the simplest way I can use flow_from_directory in Keras while limiting the number of examples used in each subdirectory by some number N?
For context, I'd like to be able to use a small subset of the total images for testing purposes without having to create a separate top level directory for the smaller dataset, since I'm pulling this data from AWS S3 buckets during training.
回答1:
Create keras.preprocessing.image.ImageDataGenerator with argument validation_split specified as float. In such case you can use argument subset in flow_from_directory to get only some samples from each directory. More info here.
If you want N images from each folder specifically, you would have to calculate how many files are there in each directory, and set train-validation split accordingly.
来源:https://stackoverflow.com/questions/54152216/keras-flow-from-directory-limiting-number-of-examples