Skip to main content

A computer vision dataset processing library

Project description

DataFlow-CV

๐ŸŒŠ Where Vibe Coding meets CV data. Convert, visualize & evaluate datasets โ€” built with the flow of Claude Code.

PyPI Python 3.8+ CI License
Linux Windows macOS YOLO LabelMe COCO

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/

Segmentation visualization demo 1 Segmentation visualization demo 2

๐Ÿ“Š 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

โš ๏ธ --prediction is required for YOLO prediction files โ€” they have an extra confidence token per line. The flag outputs a plain JSON list (not a full COCO dict), which is the standard DT format for loadRes(). Only yolo2coco supports --prediction; labelme2coco does 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 requires score.
  • Instance Segmentation โ€” mask IoU. GT and DT require bbox, segmentation (polygon or RLE), and area; DT additionally requires score.

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.format to interpret coordinate semantics.
  • Strict Mode (default): Validation errors raise exceptions immediately. Disable with --no-strict (CLI) or strict_mode=False (API) to skip invalid annotations and continue.
  • Verbose Logging: --verbose enables per-module file logging via LogManager โ€” console shows INFO-level progress, log files capture DEBUG details. All logging is owned by modules; the CLI uses click.echo() for terminal output.
  • Headless Support: Use --no-display for servers/Docker โ€” pair with --save to render visualization images without a GUI window.
  • Keyboard Shortcuts (visualization): q / ESC to exit, Enter / Space to advance, any other key to continue.
  • Evaluation: --prf1 computes 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 --prf1 for 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 --prediction with yolo2coco โ€” outputs a plain JSON list of annotation dicts compatible with pycocotools loadRes().

๐Ÿ”ง Development

For detailed developer guidance including advanced test commands, debugging, and architecture overview, see CLAUDE.md.

๐Ÿงช Testing

418 tests, 76% code coverage (3986 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/ 68% models (87%), coco_handler (75%), labelme_handler (70%), yolo_handler (58%)
dataflow/convert/ 87% yolo_and_coco (90%), labelme_and_yolo (86%), coco_and_labelme (87%), rle (80%), base (83%), utils (92%)
dataflow/visualize/ 81% yolo_vis (100%), labelme_vis (100%), coco_vis (97%), base (74%)
dataflow/evaluate/ 87% evaluator (100%), metrics (93%), result (99%), base (91%), utils (68%)
dataflow/cli/ 59% main (96%), convert cmd (48%), evaluate cmd (24%), visualize cmd (84%), utils (86%)
dataflow/util/ 93% logging (98%)

๐ŸŽจ 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 (418 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.

  1. ๐Ÿด Fork the repository
  2. ๐ŸŒฟ Create a feature branch
  3. โœ๏ธ Make your changes
  4. ๐Ÿงช Add or update tests as needed
  5. โœ… Ensure code passes formatting and linting checks
  6. ๐Ÿ“ฌ 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


Download files

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

Source Distribution

dataflow_cv-1.5.0.tar.gz (83.3 kB view details)

Uploaded Source

Built Distribution

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

dataflow_cv-1.5.0-py3-none-any.whl (99.0 kB view details)

Uploaded Python 3

File details

Details for the file dataflow_cv-1.5.0.tar.gz.

File metadata

  • Download URL: dataflow_cv-1.5.0.tar.gz
  • Upload date:
  • Size: 83.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dataflow_cv-1.5.0.tar.gz
Algorithm Hash digest
SHA256 b5590a17f0136be8f87e640255b378a6441bbd28049bcf77fb55b6287762a8f8
MD5 ca86ca5872e675128c43b9f8694bf904
BLAKE2b-256 885a7bcc6e80720a30d5ff9d8d26ca82f1b62751cc920b885f24978e682b52c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for dataflow_cv-1.5.0.tar.gz:

Publisher: python-publish.yml on zjykzj/DataFlow-CV

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dataflow_cv-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: dataflow_cv-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 99.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dataflow_cv-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad3e0c1bb37e0312a20445f9e04a6ed0c4300a3a7de3696abb729611ac7bb16e
MD5 ac1bc4d3d401988c55293cca7c6f7f33
BLAKE2b-256 dadff9a496f86bdf6c6598d2b62fee4ddf97e3627c95c6cc23c4516d45da9872

See more details on using hashes here.

Provenance

The following attestation bundles were made for dataflow_cv-1.5.0-py3-none-any.whl:

Publisher: python-publish.yml on zjykzj/DataFlow-CV

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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