jfilter / split-folders

🗂 Split folders with files (i.e. images) into training, validation and test (dataset) folders
MIT License
414 stars 72 forks source link

Splitting all numbers of files of a folder into train val test using fixed will throw an error #34

Closed nicholastzx closed 2 years ago

nicholastzx commented 2 years ago

If my folder has 4567 files and I want to split all of them into train, val and test folders with desired numbers: splitfolders.fixed(input, output=output, seed=1337, fixed(3000, 1000, 567))

it will show an error message:

if not len(files) > sum(fixed):
        raise ValueError(
            f'The number of samples in class "{class_dir.stem}" are too few. There are only {len(files)} samples available but your fixed parameter {fixed} requires at least {sum(fixed)} files. You may want to split your classes by ratio.'
        )``

Suggestion to fix the bug by using >= instead of >, so that if all the fixed numbers sum up equals to the length of files, it can proceed without error:

if not len(files) >= sum(fixed):
        raise ValueError(
            f'The number of samples in class "{class_dir.stem}" are too few. There are only {len(files)} samples available but your fixed parameter {fixed} requires at least {sum(fixed)} files. You may want to split your classes by ratio.'
        )``
jfilter commented 2 years ago

Thanks for reporting and your PR. Fixed in https://github.com/jfilter/split-folders/pull/35.