Keras flow_from_directory限制示例数 [英] Keras flow_from_directory limiting number of examples
问题描述
在Keras中使用flow_from_directory
并将每个子目录中使用的示例数限制为一定数量N
时,最简单的方法是什么?
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
?
对于上下文,我希望能够使用全部图像的一小部分进行测试,而不必为较小的数据集创建单独的顶级目录,因为我是从AWS S3存储桶中提取此数据的在训练期间.
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.
推荐答案
使用参数validation_split
指定为float的方式创建keras.preprocessing.image.ImageDataGenerator
.在这种情况下,可以在flow_from_directory
中使用参数subset
从每个目录中仅获取一些样本.更多信息此处.
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.
如果要从每个文件夹中专门获取N
个图像,则必须计算每个目录中有多少个文件,并相应地设置训练验证拆分.
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.
这篇关于Keras flow_from_directory限制示例数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!