Skip to main content

python scripts to convert labelme-generated-jsons to voc/coco style datasets.

Project description

PyPI PythonVersion Pylint codebeat badge chinese
Contributors Forks Stargazers Issues MIT License


Logo

labelme2Datasets

用于将 LabelMe 标注的数据转换为 VOC 格式和 COCO 格式的数据集。
Report Bug · Request Feature

English README Available

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

仓库中的脚本用于将 labelme 标注的数据转换为 PASCAL VOC 格式和 MS COCO 格式的数据集,便于直接利用支持这两种格式的框架进行训练。

脚本都使用 Python 写的。

大部分的脚步都是参考的 labelme 项目中的 examples 内容。然后添加一些根据自己的数据集自定义的功能,比如标签转换、自定义图像名称等。

注意:这些脚本其实并不复杂,有 Python 基础的同学可以过一遍转换的流程,确保在你的数据集上是可以正常运行的。有一些地方我标注了 MARK,表示在这些地方需要留意,可以根据自己的需要进行修改。

拓展:这些脚本当时只是用来转换我自己的数据集。如果你需要转换其他领域的数据集,比如实例分割、语义分割或者视频标注等等。建议去 lebelme 的 examples 部分看看,作者提供了一些示例代码,可以参考。

(back to top)

Built With

(back to top)

Getting Started

Prerequisites

  1. 将 lebelme 标注得到的 JSON 文件放在一个文件夹内。举个例子,命名为 labelme_jsons_dir

  2. 准备好一份 text 文本,里面包含数据集的分类标签。举个例子,命名为 label_names.txt。可以参考下项目里的 test/label_names.txt

  3. 如果有转换标签的需求(比如中文标签转为英文),准备一个文本,包含转换的规则,举个例子,命名为label_dict.txt。可以参考下项目里的 test/label_dict.txt

Installation

develop mode 安装

  1. 建议使用 Python 3.10 或更高版本的虚拟环境安装 Python Package。

    conda create --name=labelme python=3.10
    conda activate labelme
    pip install -r requirements.txt
    
  2. 克隆仓库。

    git clone git@github.com:veraposeidon/labelme2Datasets.git
    
  3. 本地安装

     cd labelme2Datasets
     # (推荐)可编辑模式安装,即可以修改代码
     pip install -e .
     # 第二种安装方式,可以直接运行脚本,但是不能修改代码
     #python setup.py install
    

直接使用 PyPI

同时发布了一个 PyPI package,labelme2datasets

可以直接使用 pip3 install labelme2datasets 进行安装。

如果项目中的流程不适用于你的数据集,建议通过上述 develop mode 安装和修改代码。

(back to top)

Usage

  • 转换单个 JSON 文件。 (labelme_json2dataset.py)

    labelme_json2dataset --json_file=data/sample.json \
      --output_dir=output/test_single_output
    
  • 转换 JSON 文件夹labelme_jsons_dir 到 VOC 格式的数据集。 (labelme_bbox_json2voc.py)

    • 不需要标签转换
      labelme_bbox_json2voc --json_dir=data/sample_jsons \
        --output_dir=output/test_voc_output --labels data/label_names.txt
      
    • 需要标签转换
      labelme_bbox_json2voc --json_dir=data/sample_jsons \
        --output_dir=output/test_voc_output \
        --labels data/label_names.txt \
        --label_dict data/label_dict.txt
      
  • 分割 VOC 数据的训练集和测试集。 (split_voc_datasets.py)

      split_voc_datasets --voc_dir output/test_voc_output --test_ratio 0.3 --random_seed 42
    

    train.txttest.txt 会出现在 voc_dir/ImageSets/Main/ 文件夹下。

  • 将 VOC 数据集转换为 COCO 数据集 (voc2coco.py)

      voc2coco --voc_dir output/test_voc_output --coco_dir output/test_coco_output
    

(back to top)

Roadmap

  • 将所有的脚本都通过 Pylint
  • 中英文 README
  • 调整项目结构
  • 发布 Pypi 包

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

如果你有什么建议可以让这个项目变得更好,可以 Fork 项目并且提交 Pull Request。 也可以简单地在 issues 中开一个 issue。

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

veraposeidon - veraposeidon@gmail.com

Project Link: https://github.com/veraposeidon/labelme2Datasets

(back to top)

Acknowledgments

(back to top)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

labelme2datasets-0.0.4.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

labelme2datasets-0.0.4-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file labelme2datasets-0.0.4.tar.gz.

File metadata

  • Download URL: labelme2datasets-0.0.4.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for labelme2datasets-0.0.4.tar.gz
Algorithm Hash digest
SHA256 03a247632beeab1678e5ed55a9d22d86b6fd6c2fcd88bf5c8f865933388b9d3f
MD5 4ce2ea9ee2dfa73f37cde559af59a003
BLAKE2b-256 4ca48cbe033a048345788c771b97344e8b7eaee3f1b4ba49a3450628849d8d64

See more details on using hashes here.

File details

Details for the file labelme2datasets-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for labelme2datasets-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e54b5a90525073a4fbb831b8729fc18ab5b19979be9da2a6bd6c99219b1ce0b7
MD5 3142ad90a0f2bb891b05ab13a2721781
BLAKE2b-256 db2df31d6b8d3f689ba1918933fbba843657673f3686612724d378f3233340f2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page