Keras flow_from_directory limiting number of examples

柔情痞子 提交于 2020-04-16 03:56:49

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!