A computer vision dataset processing library
Project description
DataFlow-CV
๐ Everything your model doesn't do. Convert, visualize, evaluate, and more โ a single CLI for all CV data.
A computer vision dataset processing library โ convert, visualize, and evaluate annotations across YOLO, LabelMe, and COCO formats.
| ๐ Convert | 6 directions: YOLO โ LabelMe โ COCO, plus model predictions | dataflow-cv convert yolo2coco ... |
| ๐จ Visualize | OpenCV rendering with color-coded classes, display & save modes | dataflow-cv visualize yolo ... |
| ๐ Evaluate | COCO mAP via pycocotools, single-threshold P/R/F1 per class | dataflow-cv evaluate detection ... |
| ๐ป CLI + API | Click-based CLI with rich --help; Python API for pipelines |
from dataflow.convert import ... |
๐ฆ Installation
pip install dataflow-cv # from PyPI
pip install pycocotools # optional: COCO RLE + evaluation
Or from source:
git clone https://github.com/zjykzj/DataFlow-CV.git
cd DataFlow-CV && pip install .
๐ Quick Start
Command-line Interface
All required parameters (image directories, label directories, class files, output paths) are positional arguments for better usability. Use --help on any subcommand for detailed usage.
๐ Format Conversion
# YOLO โ COCO
dataflow-cv convert yolo2coco images/ yolo_labels/ classes.txt output.json
# YOLO โ COCO (with RLE encoding)
dataflow-cv convert yolo2coco images/ yolo_labels/ classes.txt output.json --do-rle
# YOLO โ LabelMe
dataflow-cv convert yolo2labelme images/ yolo_labels/ classes.txt labelme_json/
# LabelMe โ YOLO
dataflow-cv convert labelme2yolo labelme_json/ classes.txt yolo_labels/
# LabelMe โ COCO
dataflow-cv convert labelme2coco labelme_json/ classes.txt output.json
# COCO โ YOLO
dataflow-cv convert coco2yolo input.json yolo_labels/
# COCO โ LabelMe
dataflow-cv convert coco2labelme input.json labelme_json/
# YOLO predictions โ COCO (output: plain JSON list โ prediction format)
dataflow-cv convert yolo2coco --prediction images/ yolo_preds/ classes.txt pred.json
# Options
dataflow-cv convert yolo2coco --verbose images/ labels/ classes.txt output.json
dataflow-cv convert yolo2coco --no-strict images/ labels/ classes.txt output.json
๐จ Visualization
# Visualize YOLO annotations
dataflow-cv visualize yolo images/ yolo_labels/ classes.txt --save visualized/
# Visualize LabelMe annotations
dataflow-cv visualize labelme images/ labelme_json/ --save visualized/
# Visualize COCO annotations
dataflow-cv visualize coco images/ coco_annotations.json --save visualized/
# Verbose logging + headless mode
dataflow-cv visualize yolo --verbose --no-display images/ yolo_labels/ classes.txt --save visualized/
๐ Evaluation
Evaluate object detection and instance segmentation models with COCO-standard metrics. Two COCO-format JSON files are required:
| File | Role | Format | How to create |
|---|---|---|---|
anno.json |
Ground Truth (GT) | Full COCO dict (images, annotations, categories) |
yolo2coco (label mode) |
pred.json |
Detection (DT) | Plain JSON list (with score) |
yolo2coco --prediction |
โ Prepare Data
# GT: YOLO labels โ COCO
dataflow-cv convert yolo2coco images/ yolo_labels/ classes.txt anno.json
# DT: YOLO predictions โ COCO (add --prediction for model output)
dataflow-cv convert yolo2coco --prediction images/ yolo_preds/ classes.txt pred.json
โ ๏ธ
--predictionis required for YOLO prediction files โ they have an extraconfidencetoken per line. The flag outputs a plain JSON list (not a full COCO dict), which is the standard DT format forloadRes(). Onlyyolo2cocosupports--prediction;labelme2cocodoes not need it (LabelMe has no label vs prediction distinction).
โก Run Evaluation
# Object detection (bbox IoU)
dataflow-cv evaluate detection anno.json pred.json
dataflow-cv evaluate detection --verbose anno.json pred.json # per-class breakdown
dataflow-cv evaluate detection --prf1 anno.json pred.json # P/R/F1 only (skip mAP)
dataflow-cv evaluate detection --prf1 --prf1-iou 0.75 --prf1-method micro anno.json pred.json
# Instance segmentation (mask IoU)
dataflow-cv evaluate segmentation anno.json pred.json
dataflow-cv evaluate segmentation --verbose anno.json pred.json
# Save results as JSON
dataflow-cv evaluate detection --output results.json anno.json pred.json
โข Detection vs Segmentation
Two evaluation modes, distinguished by how overlap is measured:
- Object Detection โ bounding box IoU. GT and DT require
bbox; DT additionally requiresscore. - Instance Segmentation โ mask IoU. GT and DT require
bbox,segmentation(polygon or RLE), andarea; DT additionally requiresscore.
yolo2coco (label mode) and yolo2coco --prediction (prediction mode) automatically populate all required fields for both modes โ no manual editing needed.
๐ Python API
from dataflow.util.logging import LogConfig
from dataflow.convert import YoloAndCocoConverter
from dataflow.visualize import YOLOVisualizer
from dataflow.evaluate import DetectionEvaluator, compute_pr_f1
# โโ Convert โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# YOLO labels โ COCO (label mode)
log_cfg = LogConfig(name="convert", verbose=True)
converter = YoloAndCocoConverter(source_to_target=True, log_config=log_cfg, strict_mode=True)
result = converter.convert(
source_path="yolo_labels/", target_path="anno.json",
class_file="classes.txt", image_dir="images/",
)
# YOLO predictions โ COCO (prediction mode)
converter = YoloAndCocoConverter(source_to_target=True, prediction=True)
result = converter.convert(
source_path="yolo_preds/", target_path="pred.json",
class_file="classes.txt", image_dir="images/",
)
# โโ Visualize โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
visualizer = YOLOVisualizer(
label_dir="yolo_labels/", image_dir="images/",
class_file="classes.txt", is_show=True, is_save=True,
output_dir="visualized/", log_config=log_cfg,
)
result = visualizer.visualize()
# โโ Evaluate โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
evaluator = DetectionEvaluator(log_config=LogConfig(name="eval", verbose=True))
result = evaluator.evaluate("anno.json", "pred.json")
print(f"AP: {result.metrics.ap:.3f}, AP50: {result.metrics.ap50:.3f}")
# Quick P/R/F1 at IoU=0.5 (default: macro averaging, bbox IoU)
prf1 = compute_pr_f1("anno.json", "pred.json", iou_threshold=0.5)
print(f"Macro F1: {prf1.overall.f1_score:.3f}")
# Micro averaging P/R/F1 (samples weighted equally)
prf1 = compute_pr_f1("anno.json", "pred.json", method="micro")
print(f"Micro F1: {prf1.overall.f1_score:.3f}")
# Segmentation P/R/F1 (mask IoU)
prf1 = compute_pr_f1("anno_segm.json", "pred_segm.json", iou_type="segm")
print(f"Segm F1: {prf1.overall.f1_score:.3f}")
๐ See the
samples/directory for complete examples:samples/convert/(6 conversion directions),samples/visualize/(YOLO, LabelMe, COCO),samples/evaluate/(detection & segmentation),samples/cli/(CLI workflows).
๐ Documentation
| Resource | Description |
|---|---|
| CLAUDE.md | Architecture overview, development guide, and known gotchas |
| CHANGELOG.md | Version history and breaking changes |
| specs/evaluate/ | Evaluation metric contracts โ IoU, matching, AP/mAP/AR |
| specs/formats/ | External format contracts โ YOLO, LabelMe, COCO, conversion rules |
| specs/modules/ | Internal module architecture, interface contracts, dependency constraints |
๐ก Key Concepts
- Format-Native Coordinates: YOLO uses normalized [0,1] center-based coordinates; LabelMe and COCO use absolute pixel top-left. There is no hidden internal normalization โ check
DatasetAnnotations.formatto interpret coordinate semantics. - Strict Mode (default): Validation errors raise exceptions immediately. Disable with
--no-strict(CLI) orstrict_mode=False(API) to skip invalid annotations and continue. - Verbose Logging:
--verboseenables per-module file logging viaLogManagerโ console shows INFO-level progress, log files capture DEBUG details. All logging is owned by modules; the CLI usesclick.echo()for terminal output. - Headless Support: Use
--no-displayfor servers/Docker โ pair with--saveto render visualization images without a GUI window. - Keyboard Shortcuts (visualization):
q/ESCto exit,Enter/Spaceto advance, any other key to continue. - Evaluation:
--prf1computes P/R/F1 only (single-threshold, per-class TP/FP/FN) โ skips the full COCOeval mAP pipeline for speed. Supports macro/micro averaging and bbox/mask IoU. Run without--prf1for standard COCO mAP. For both metrics, run twice. - Prediction Files: YOLO predictions use 6 tokens (detection) or even tokens (segmentation) vs 5/odd for labels. Use
--predictionwithyolo2cocoโ outputs a plain JSON list of annotation dicts compatible with pycocotoolsloadRes().
๐ง Development
For detailed developer guidance including advanced test commands, debugging, and architecture overview, see CLAUDE.md.
๐งช Testing
440 tests, 77% code coverage (3957 statements).
pytest # All tests
pytest --cov=dataflow --cov-report=term # With coverage
pytest tests/convert/test_yolo_and_coco.py # Single module
pytest tests/evaluate/test_evaluator.py # Single module
๐ Coverage by module
| Module | Coverage | Highlights |
|---|---|---|
dataflow/label/ |
70% | models (87%), coco_handler (75%), labelme_handler (70%), yolo_handler (61%) |
dataflow/convert/ |
83% | yolo_and_coco (90%), labelme_and_yolo (86%), coco_and_labelme (87%), rle (80%), base (82%), utils (91%) |
dataflow/visualize/ |
76% | yolo_vis (100%), labelme_vis (100%), coco_vis (88%), base (74%) |
dataflow/evaluate/ |
87% | evaluator (100%), metrics (92%), result (99%), base (91%), utils (67%) |
dataflow/cli/ |
76% | main (96%), convert cmd (49%), evaluate cmd (82%), visualize cmd (87%), utils (88%) |
dataflow/util/ |
100% | logging (100%) |
๐จ Code Quality
pip install -e .[dev] # Install dev dependencies
black dataflow tests samples # Format
isort dataflow tests samples # Sort imports
mypy dataflow # Type check
flake8 dataflow tests samples # Lint
๐ Pre-commit Hooks (Optional)
pip install pre-commit
pre-commit install # Install git hooks (run once)
# After this, every `git commit` auto-runs:
# black โ isort โ flake8 โ whitespace checks
pre-commit run --all-files # Manual run against all files
๐ Project Structure
dataflow/
โโโ label/ # Annotation handlers + data models
โโโ convert/ # Format converters, RLE utility, log templates
โโโ visualize/ # OpenCV-based rendering, log templates
โโโ evaluate/ # pycocotools-based metrics, log templates
โโโ util/ # Unified logging (LogManager + format helpers)
โโโ cli/ # CLI entry point, commands, validation
tests/ # Unit & integration tests (440 tests, conftest fixtures)
samples/ # Python API usage examples
assets/ # Test data (det/seg by format)
specs/ # Canonical specifications (evaluate/ + formats/ + modules/)
๐ค Contributing
Contributions are welcome! Please review CLAUDE.md for architecture and development patterns before contributing.
- ๐ด Fork the repository
- ๐ฟ Create a feature branch
- โ๏ธ Make your changes
- ๐งช Add or update tests as needed
- โ Ensure code passes formatting and linting checks
- ๐ฌ Submit a pull request
๐ License
This project is licensed under the MIT License โ see LICENSE for details.
๐ Acknowledgments
- Thanks to the creators of YOLO, LabelMe, and COCO formats for establishing these annotation standards
- Built with OpenCV, NumPy, Click, and pycocotools
- Inspired by the need for seamless format conversion in multi-tool CV pipelines
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dataflow_cv-1.6.0.tar.gz.
File metadata
- Download URL: dataflow_cv-1.6.0.tar.gz
- Upload date:
- Size: 85.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d9fa2d3f4e543d238805fcccf30e6834dcac9635dd12648b6052ec65fc8bc78
|
|
| MD5 |
e02823963b3d3aa2ae3b400912a02a5f
|
|
| BLAKE2b-256 |
dcac52398c7e802a6f57d40ea7ac153da9795190412782ec44e7a763c3bf2276
|
Provenance
The following attestation bundles were made for dataflow_cv-1.6.0.tar.gz:
Publisher:
python-publish.yml on zjykzj/DataFlow-CV
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dataflow_cv-1.6.0.tar.gz -
Subject digest:
1d9fa2d3f4e543d238805fcccf30e6834dcac9635dd12648b6052ec65fc8bc78 - Sigstore transparency entry: 1978974761
- Sigstore integration time:
-
Permalink:
zjykzj/DataFlow-CV@563bdf3a018f54bc13441108b645691ea5ad205e -
Branch / Tag:
refs/tags/v1.6.0 - Owner: https://github.com/zjykzj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@563bdf3a018f54bc13441108b645691ea5ad205e -
Trigger Event:
release
-
Statement type:
File details
Details for the file dataflow_cv-1.6.0-py3-none-any.whl.
File metadata
- Download URL: dataflow_cv-1.6.0-py3-none-any.whl
- Upload date:
- Size: 100.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7bdb375c2083246ed5449a58ba13db7ca727919ac2d16a19cb44d685782ea9d
|
|
| MD5 |
a6f998df1f20ef45e9c0d9955f13a331
|
|
| BLAKE2b-256 |
196e51c66fcc68a2bc4b67d7be7a9f688088cff038be7d55dcce3b302d9deffa
|
Provenance
The following attestation bundles were made for dataflow_cv-1.6.0-py3-none-any.whl:
Publisher:
python-publish.yml on zjykzj/DataFlow-CV
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dataflow_cv-1.6.0-py3-none-any.whl -
Subject digest:
b7bdb375c2083246ed5449a58ba13db7ca727919ac2d16a19cb44d685782ea9d - Sigstore transparency entry: 1978974827
- Sigstore integration time:
-
Permalink:
zjykzj/DataFlow-CV@563bdf3a018f54bc13441108b645691ea5ad205e -
Branch / Tag:
refs/tags/v1.6.0 - Owner: https://github.com/zjykzj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@563bdf3a018f54bc13441108b645691ea5ad205e -
Trigger Event:
release
-
Statement type: