Reputation: 1
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?
Upvotes: -1
Views: 949
Reputation: 2378
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.
Upvotes: 1