在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
发布评论