项目已停止更新,新项目应改用 ultralytics 包里的 convert_coco();--save-dir 每次运行都会被删除重建,别指向已有数据目录;Labelbox 仅转换边界框对象,纯 mask 对象会被跳过并告警

JSON2YOLO
ultralyticsAGPL-3.0活跃维护把 COCO、LabelMe、Labelbox、VoTT 等格式的 JSON 标注转成 YOLO 训练格式,适合做目标检测数据集迁移;官方已建议改用 Ultralytics 包里的 convert_coco()。
Legacy JSON-to-YOLO dataset converter for COCO, LabelMe, Labelbox, VoTT, INFOLKS, and ATH annotations. Superseded by convert_coco() in the Ultralytics package.
pip install -r requirements.txt
python general_json2yolo.py --source COCO --json-dir path/to/annotations --save-dir yolo_outREADME 未说明,仅要求 Python 3.8 及以上,可在 Linux、macOS、Windows 上运行
把 COCO 等 JSON 标注转成 YOLO 格式的旧版脚本,现已被 ultralytics 的 convert_coco() 取代
把 COCO、LabelMe、Labelbox、VoTT 等格式的 JSON 标注转成 YOLO 训练格式,适合做目标检测数据集迁移;官方已建议改用 Ultralytics 包里的 convert_coco()。
核心能力
- 将 COCO 的 images/annotations/categories 转成 YOLO 标签
- 支持 LabelMe 多边形、矩形、圆、线带与 mask 标注
- 可选用 --use-segments 输出分割标签
- 可选用 --use-keypoints 输出关键点姿态标签
- 按 images/labels 目录加 yaml 的 YOLO 数据集布局输出
容易踩的坑
- v1Improvements最新正式版2019-05-11 · 2019-05-11 13:22 UTC
- Minor corrections and improvements
- Supports dataset division into train, test and validate groups now
- v0Initial Release2019-05-11 · 2019-05-11 11:12 UTC
这个版本没有写更新说明。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
🚀 Introduction
Welcome to the JSON2YOLO repository! This toolkit is designed to help you convert datasets in JSON format, particularly those following the COCO (Common Objects in Context) standards, into the YOLO format. The YOLO format is widely recognized for its efficiency in real-time object detection tasks.
This conversion process is essential for machine learning practitioners looking to train object detection models using frameworks compatible with the YOLO format, such as Ultralytics YOLO. Our code is flexible and designed to run across various platforms including Linux, macOS, and Windows.
📢 Important Update: The JSON2YOLO project is now integrated into the main Ultralytics package at https://github.com/ultralytics/ultralytics. The standalone scripts in this repository are no longer being actively updated. For the latest functionality, please use the new
convert_coco()method described in our updated data converter documentation.
⚙️ Requirements
To get started with JSON2YOLO, you'll need a Python environment running version 3.8 or later. Additionally, you'll need to install all the necessary dependencies listed in the requirements.txt file. You can install these dependencies using the following pip command in your terminal:
pip install -r requirements.txt # Installs all the required packages
💡 Usage
JSON2YOLO functionality is now part of the main ultralytics Python package. For new projects, install ultralytics and use the maintained converter:
pip install ultralytics
from ultralytics.data.converter import convert_coco
convert_coco(
labels_dir="path/to/annotations",
save_dir="path/to/output_dir",
use_segments=False,
use_keypoints=True,
)
This method processes COCO detection, segmentation, and keypoint annotations and saves YOLO labels in the specified directory. For more details, refer to the dataset format documentation.
Legacy standalone script usage is still available for existing workflows:
python general_json2yolo.py --source COCO --json-dir path/to/annotations --save-dir yolo_out
python general_json2yolo.py --source COCO --json-dir path/to/annotations --use-segments --save-dir yolo_seg
python general_json2yolo.py --source COCO --json-dir path/to/annotations --use-keypoints --save-dir yolo_pose
The standalone converter also supports LabelMe polygon, rectangle, circle, linestrip, and mask annotations:
python general_json2yolo.py --source LabelMe --json-dir path/to/labelme_jsons --use-segments --save-dir yolo_labelme
Notes:
- COCO input should be a directory containing
*.jsonfiles with standardimages,annotations, andcategorieskeys. - LabelMe input should be a directory containing one JSON file per image.
--save-dircontrols the output directory and is deleted/recreated on each run.- Image files are copied for LabelMe when
imagePathpoints to an existing local file next to the JSON. - Labelbox exports can be JSON lists or newline-delimited JSON. Bounding-box objects are converted; mask-only objects are skipped with a warning.
The output follows the Ultralytics YOLO dataset layout:
yolo_out/
├── data.yaml # LabelMe only; COCO writes one <json-stem>.yaml of class names per input file
├── images/
└── labels/
📚 Citation
If you find our tool useful for your research or development, please consider citing it:
🤝 Contribute
We welcome contributions from the community! Whether you're fixing bugs, adding new features, or improving documentation, your input is invaluable. Take a look at our Contributing Guide to get started. Also, we'd love to hear about your experience with Ultralytics products. Please consider filling out our Survey. A huge 🙏 and thank you to all of our contributors!
©️ License
Ultralytics offers two licensing options to accommodate diverse needs:
- AGPL-3.0 License: Ideal for students and enthusiasts, this OSI-approved open-source license promotes collaboration and knowledge sharing. See the LICENSE file for details.
- Enterprise License: Designed for commercial use, this license permits seamless integration of Ultralytics software and AI models into commercial products and services, bypassing the open-source requirements of AGPL-3.0. For commercial inquiries, please contact us through Ultralytics Licensing.
📬 Contact Us
For bug reports, feature requests, and contributions, please visit GitHub Issues. For broader questions and discussions about this project and other Ultralytics initiatives, join our vibrant community on Discord!
