Name | yolococo JSON |
Version |
0.2.0
JSON |
| download |
home_page | None |
Summary | YOLO <-> COCO conversion tools with COCO dataset merging |
upload_time | 2025-08-27 23:08:21 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT License
Copyright (c) 2025 Scott
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
|
keywords |
yolo
coco
detection
dataset
conversion
merge
annotation
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# YOLO-COCO-Converter
YOLO <-> COCO conversion tools with an extra COCO dataset merger. Use the unified
CLI for conversions and merging, or import functions in notebooks.
## Features
- YOLO -> COCO: Build COCO JSON from YOLO labels and image sizes
- COCO -> YOLO: Write YOLO .txt labels and `classes.txt` from COCO
- Merge COCO: Merge multiple COCO datasets with id remapping and options
- Optional Pillow for image size detection; or provide a sizes CSV
## Install (optional)
For a global CLI (Pillow is included by default):
```bash
pip install -e .
```
This installs `yolococo` (primary) and `coco-merge` (alias for merge-only).
## CLI Usage
Run as a module (no install required):
```bash
python -m yolococo ...
```
Or after installing:
```bash
yolococo ...
```
Subcommands
- YOLO -> COCO:
```bash
yolococo yolo2coco \
--images ./images \
--labels ./labels \
--classes ./classes.txt \ # optional
--sizes ./sizes.csv \ # optional; overrides Pillow sizes
--bbox-round 2 \ # decimals for bbox/area (use <0 to disable)
--file-name-mode name \ # name | relative
--out ./coco.json
```
sizes.csv format (no header): `filename,width,height`.
- COCO -> YOLO:
```bash
yolococo coco2yolo \
--coco ./instances.json \
--out-labels ./yolo_labels \
--out-classes ./classes.txt \
[--keep-category-ids]
[--skip-empty-labels]
```
- Merge COCO:
```bash
yolococo merge \
--inputs path/to/ds1.json path/to/ds2.json \
--out merged.json \
[--prefix-mode none|basename|custom] \
[--custom-prefixes A_ B_] \
[--align-by-name] \
[--drop-duplicate-filenames]
```
## Programmatic Use (incl. Jupyter)
```python
from pathlib import Path
import json
from yolococo import yolo_to_coco, coco_to_yolo_files, merge_datasets
# YOLO -> COCO
coco = yolo_to_coco(
images_dir=Path("./images"),
labels_dir=Path("./labels"),
classes_path=Path("./classes.txt"), # or None
sizes_csv=None, # or Path("./sizes.csv")
)
with open("coco.json", "w", encoding="utf-8") as f:
json.dump(coco, f, ensure_ascii=False, indent=2)
# COCO -> YOLO (writes files)
coco_to_yolo_files(Path("./instances.json"), Path("./yolo_labels"), Path("./classes.txt"))
# Merge COCO
merged = merge_datasets([Path("a.json"), Path("b.json")], prefix_mode="basename")
```
Tip for notebooks: run from the repo root (so `import yolococo` works), or add the repo path to `sys.path`.
## Notes & Assumptions
- YOLO labels follow the common format: `<cls> <xc> <yc> <w> <h>` normalized to [0,1].
- COCO expects absolute pixel `bbox` as `[x_min, y_min, width, height]`.
- Pillow is installed by default and used to read image sizes; `--sizes` CSV (if provided) takes precedence per matching filename.
- Bounding boxes and area are rounded to `--bbox-round` decimals (default 2). Set a negative value to disable rounding.
- Merge assumes consistent semantic classes across inputs; use `--align-by-name` if ids differ but names match.
- `--file-name-mode` controls whether COCO `images[].file_name` stores just the basename (`name`) or the path relative to `--images` (`relative`). When using `relative`, directory separators are `/`.
## License
MIT - see [LICENSE](LICENSE).
## Testing & Visualization
- Install dev deps: `pip install -e .[test]`
- Run tests: `pytest -q`
- Artifacts (COCO JSON and annotated images) are written to `tests/_artifacts/` for manual inspection.
Manual visualization script:
```bash
python scripts/visualize_labels.py
```
It converts the sample in `test/` to COCO and saves overlays: `sample_annotated_from_yolo.jpg`, `sample_annotated_from_coco.jpg`, and the original image in `tests/_artifacts/`.
Raw data
{
"_id": null,
"home_page": null,
"name": "yolococo",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "yolo, coco, detection, dataset, conversion, merge, annotation",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/72/c1/ad05795a776bbbb8e690db4f0693e34079050c31110ce25c01c5b04664af/yolococo-0.2.0.tar.gz",
"platform": null,
"description": "# YOLO-COCO-Converter\r\n\r\nYOLO <-> COCO conversion tools with an extra COCO dataset merger. Use the unified\r\nCLI for conversions and merging, or import functions in notebooks.\r\n\r\n## Features\r\n- YOLO -> COCO: Build COCO JSON from YOLO labels and image sizes\r\n- COCO -> YOLO: Write YOLO .txt labels and `classes.txt` from COCO\r\n- Merge COCO: Merge multiple COCO datasets with id remapping and options\r\n- Optional Pillow for image size detection; or provide a sizes CSV\r\n\r\n## Install (optional)\r\nFor a global CLI (Pillow is included by default):\r\n```bash\r\npip install -e .\r\n```\r\nThis installs `yolococo` (primary) and `coco-merge` (alias for merge-only).\r\n\r\n## CLI Usage\r\nRun as a module (no install required):\r\n```bash\r\npython -m yolococo ...\r\n```\r\n\r\nOr after installing:\r\n```bash\r\nyolococo ...\r\n```\r\n\r\nSubcommands\r\n- YOLO -> COCO:\r\n ```bash\r\n yolococo yolo2coco \\\r\n --images ./images \\\r\n --labels ./labels \\\r\n --classes ./classes.txt \\ # optional\r\n --sizes ./sizes.csv \\ # optional; overrides Pillow sizes\r\n --bbox-round 2 \\ # decimals for bbox/area (use <0 to disable)\r\n --file-name-mode name \\ # name | relative\r\n --out ./coco.json\r\n ```\r\n sizes.csv format (no header): `filename,width,height`.\r\n\r\n- COCO -> YOLO:\r\n ```bash\r\n yolococo coco2yolo \\\r\n --coco ./instances.json \\\r\n --out-labels ./yolo_labels \\\r\n --out-classes ./classes.txt \\\r\n [--keep-category-ids]\r\n [--skip-empty-labels]\r\n ```\r\n\r\n- Merge COCO:\r\n ```bash\r\n yolococo merge \\\r\n --inputs path/to/ds1.json path/to/ds2.json \\\r\n --out merged.json \\\r\n [--prefix-mode none|basename|custom] \\\r\n [--custom-prefixes A_ B_] \\\r\n [--align-by-name] \\\r\n [--drop-duplicate-filenames]\r\n ```\r\n\r\n## Programmatic Use (incl. Jupyter)\r\n```python\r\nfrom pathlib import Path\r\nimport json\r\nfrom yolococo import yolo_to_coco, coco_to_yolo_files, merge_datasets\r\n\r\n# YOLO -> COCO\r\ncoco = yolo_to_coco(\r\n images_dir=Path(\"./images\"),\r\n labels_dir=Path(\"./labels\"),\r\n classes_path=Path(\"./classes.txt\"), # or None\r\n sizes_csv=None, # or Path(\"./sizes.csv\")\r\n)\r\nwith open(\"coco.json\", \"w\", encoding=\"utf-8\") as f:\r\n json.dump(coco, f, ensure_ascii=False, indent=2)\r\n\r\n# COCO -> YOLO (writes files)\r\ncoco_to_yolo_files(Path(\"./instances.json\"), Path(\"./yolo_labels\"), Path(\"./classes.txt\"))\r\n\r\n# Merge COCO\r\nmerged = merge_datasets([Path(\"a.json\"), Path(\"b.json\")], prefix_mode=\"basename\")\r\n```\r\nTip for notebooks: run from the repo root (so `import yolococo` works), or add the repo path to `sys.path`.\r\n\r\n## Notes & Assumptions\r\n- YOLO labels follow the common format: `<cls> <xc> <yc> <w> <h>` normalized to [0,1].\r\n- COCO expects absolute pixel `bbox` as `[x_min, y_min, width, height]`.\r\n- Pillow is installed by default and used to read image sizes; `--sizes` CSV (if provided) takes precedence per matching filename.\r\n- Bounding boxes and area are rounded to `--bbox-round` decimals (default 2). Set a negative value to disable rounding.\r\n- Merge assumes consistent semantic classes across inputs; use `--align-by-name` if ids differ but names match.\r\n- `--file-name-mode` controls whether COCO `images[].file_name` stores just the basename (`name`) or the path relative to `--images` (`relative`). When using `relative`, directory separators are `/`.\r\n\r\n## License\r\nMIT - see [LICENSE](LICENSE).\r\n\r\n## Testing & Visualization\r\n- Install dev deps: `pip install -e .[test]`\r\n- Run tests: `pytest -q`\r\n- Artifacts (COCO JSON and annotated images) are written to `tests/_artifacts/` for manual inspection.\r\n\r\nManual visualization script:\r\n```bash\r\npython scripts/visualize_labels.py\r\n```\r\nIt converts the sample in `test/` to COCO and saves overlays: `sample_annotated_from_yolo.jpg`, `sample_annotated_from_coco.jpg`, and the original image in `tests/_artifacts/`.\r\n\r\n",
"bugtrack_url": null,
"license": "MIT License\r\n \r\n Copyright (c) 2025 Scott\r\n \r\n Permission is hereby granted, free of charge, to any person obtaining a copy\r\n of this software and associated documentation files (the \"Software\"), to deal\r\n in the Software without restriction, including without limitation the rights\r\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n copies of the Software, and to permit persons to whom the Software is\r\n furnished to do so, subject to the following conditions:\r\n \r\n The above copyright notice and this permission notice shall be included in all\r\n copies or substantial portions of the Software.\r\n \r\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n SOFTWARE.\r\n ",
"summary": "YOLO <-> COCO conversion tools with COCO dataset merging",
"version": "0.2.0",
"project_urls": null,
"split_keywords": [
"yolo",
" coco",
" detection",
" dataset",
" conversion",
" merge",
" annotation"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "8d41f8c25484f3222847a95cf8dedd917b176ab506acf41dfa68f2ee835fe636",
"md5": "f28c042976ed71d07ff90668899fe168",
"sha256": "32146841d39b2e14fe1c81ede3555bc32b9ae02e23f8e43590af03bcc0e0d75e"
},
"downloads": -1,
"filename": "yolococo-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f28c042976ed71d07ff90668899fe168",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 15306,
"upload_time": "2025-08-27T23:08:20",
"upload_time_iso_8601": "2025-08-27T23:08:20.404383Z",
"url": "https://files.pythonhosted.org/packages/8d/41/f8c25484f3222847a95cf8dedd917b176ab506acf41dfa68f2ee835fe636/yolococo-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "72c1ad05795a776bbbb8e690db4f0693e34079050c31110ce25c01c5b04664af",
"md5": "1c5dd010a1f55b9791adfa0d2b8b3843",
"sha256": "1f9cc202b138f86f1887006637498975dd2ff01bbb2432940807e0a2d2a23e2d"
},
"downloads": -1,
"filename": "yolococo-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "1c5dd010a1f55b9791adfa0d2b8b3843",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 15934,
"upload_time": "2025-08-27T23:08:21",
"upload_time_iso_8601": "2025-08-27T23:08:21.529861Z",
"url": "https://files.pythonhosted.org/packages/72/c1/ad05795a776bbbb8e690db4f0693e34079050c31110ce25c01c5b04664af/yolococo-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-27 23:08:21",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "yolococo"
}