Split Image dataset for keras model.fit_generator

烈酒焚心 提交于 2019-12-01 14:24:33

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.

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