将包含文件(如图像)的文件夹拆分为培训、验证和测试(数据集)文件夹。

split-folders的Python项目详细描述


拆分文件夹Build StatusPyPIPyPI - Python Version

将包含文件(如图像)的文件夹拆分为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

许可证

麻省理工学院。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaPax考试:从非标准Maven存储库解析Karaf特性存储库(XML文件)   java Spring启动Bean创建异常   java中将ArrayList转换为数组的方法   Android Studio的java Unity插件。   java在CheckStyle中从方法计数中排除getter和setter   HibernateJava。sql。SQLSyntaxErrorException:表/视图“序列”不存在   与命令行程序Java vs C通信   java WebView膨胀异常   java在O(n)java8流中寻找两个列表的交集   java使用Gradle运行单元测试时,最大堆大小在哪里设置?   ssl加载java应用程序(CXF)内的jks文件   CI:Jenkins Git:Simple Java项目:希望在特定时间在脚本上发送消息   java根据位置更改数字   java按数值排序字符串数组   macos java版本“1.6.0_65”是否与java 6模棱两可?   Cassandra中的java时间戳