keras模型的分割图像数据集.fit_generator [英] Split Image dataset for keras model.fit_generator

查看:513
本文介绍了keras模型的分割图像数据集.fit_generator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有单个目录,数据集,其中包含图像的子文件夹(标签/类).
这是数据集中动物图像的子文件夹:

我想将数据集分为model.fit_generotar()的训练集和测试集.

我该怎么做?

解决方案

使用glob获取文件路径迭代器.

然后,您可以使用scikit-learn的train-test拆分来获取火车和测试数据路径(使用stratify参数来获得与整个数据集中的测试/火车相同的类分布).

结果将是两个路径列表,您可以将其写入适当的测试/培训文件夹,然后可以应用生成器的flow_from_directory方法.

第二种方法是不使用flow_from_directory,而是加载训练/测试集(加载所有内容并使用scikit-learn方法或使用我之前描述的方法),然后使用生成器的flow方法. /p>

还请注意,您可能不希望将生成器用于测试/验证数据,因为由于您没有固定的验证/测试集,这会使比较准确性变得困难.

>

I have single directory, dataset, which contains sub-folders(labels/classes) of images.
Here's the Sub-folders of animal images in dataset:

I want to split the dataset into train and test set for model.fit_generotar().

How can I do that?

解决方案

Use glob to get file paths iterator.

You can then use scikit-learn's train-test split to get train and test data paths (use stratify parameter to get the same class distribution in test/train as in whole dataset).

The result would be two lists of paths, which you can write to appropriate test/train folders, and then you can apply generator's flow_from_directory method.

EDIT:

The second way would be to not use flow_from_directory, but load train/test sets (either load everything and use scikit-learn method or use what I've described before) and then use generator's flow method.

Also note that you might not want to use generators for test/validation data, since it would make comparing accuracy hard, since you won't have a fixed valid/test set.

这篇关于keras模型的分割图像数据集.fit_generator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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