将包含文件(如图像)的文件夹拆分为培训、验证和测试(数据集)文件夹。
split-folders的Python项目详细描述
拆分文件夹
将包含文件(如图像)的文件夹拆分为Train、Validation和Test(数据集)文件夹。
输入文件夹的格式如下:
input/
class1/
img1.jpg
img2.jpg
...
class2/
imgWhatever.jpg
...
...
为了给你这个:
output/
train/
class1/
img1.jpg
...
class2/
imga.jpg
...
val/
class1/
img2.jpg
...
class2/
imgb.jpg
...
test/
class1/
img3.jpg
...
class2/
imgc.jpg
...
这会让你开始认真地深入学习你的数据。Read here为什么将数据简介分成三组是个好主意。
- 您只能分为培训和验证集。
- 数据在被洗牌之前被分割。
- 使用seed可以重新生成拆分。
- 适用于任何文件类型。
- 允许对不平衡数据集进行随机oversampling。
- (应该)在所有操作系统上工作。
安装
pip install split-folders
如果正在处理大量文件,则可能需要一个进度条。安装tqdm,以便在将文件复制到新文件夹时获得更新。
pip install split-folders tqdm
用法
可以将split_folders
用作python模块或命令行界面(cli)。
如果您的数据集是平衡的(每个类都有相同数量的样本),请选择ratio
,否则选择fixed
。注意:默认情况下,“过采样”处于禁用状态。
模块
importsplit_folders# Split with a ratio.# To only split into training and validation set, set a tuple to `ratio`, i.e, `(.8, .2)`.split_folders.ratio('input_folder',output="output",seed=1337,ratio=(.8,.1,.1))# default values# Split val/test with a fixed number of items e.g. 100 for each set.# To only split into training and validation set, use a single number to `fixed`, i.e., `10`.split_folders.fixed('input_folder',output="output",seed=1337,fixed=(100,100),oversample=False)# default values
cli
Usage:
split_folders folder_with_images [--output] [--ratio] [--fixed] [--seed] [--oversample]
Options:
--output path to the output folder. defaults to `output`. Get created if non-existent.
--ratio the ratio to split. e.g. for train/val/test `.8 .1 .1` or for train/val `.8 .2`.
--fixed set the absolute number of items per validation/test set. The remaining items constitute
the training set. e.g. for train/val/test `100 100` or for train/val `100`.
--seed set seed value for shuffling the items. defaults to 1337.
--oversample enable oversampling of imbalanced datasets, works only with --fixed.
Example:
split_folders imgs --ratio .8 .1 .1
许可证
麻省理工学院。