Keras flow_from_directory限制示例数 [英] Keras flow_from_directory limiting number of examples

查看:80
本文介绍了Keras flow_from_directory限制示例数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆