Skip to main content

A tool to numerically analyze the health of a YOLO dataset.

Project description

yolo-health-checker

A Python tool to perform an in-depth analysis of YOLO-format datasets, providing both multidimensional and unidimensional metrics of dataset “health.” This package helps you quantify class distribution, spatial distribution, and other properties in a systematic and reproducible way.

Features

  • Class Distribution Analysis:

    • Calculate entropy, Gini index, and standard deviation of instance counts per class.
    • Inspect the number of instances per class and identify imbalances quickly.
  • Spatial Distribution Analysis:

    • Compute spatial entropy of bounding boxes to see how they are spread across images.
    • Measure standard deviation of bounding box centers, detecting if objects cluster in certain image regions.
    • Calculate average distance from image center, unveiling potential “center bias” in your dataset.
  • Rich Visual Outputs:

    • Automatically generates heatmaps of bounding box footprints and centers.
    • Visual bar charts showing the number of instances per class.
  • Comprehensive Logging:

    • Each analysis is logged into a log file, capturing potential warnings (e.g., missing annotations) and key statistics.
  • Modular:

    • Integrate directly into Python code, or run as a command-line script.
    • Produces CSV reports of class distribution and overall health metrics.

Installation

Install yolo-health-checker via pip:

pip install yolo-health-checker

Usage

There are two main ways to use this tool: as a command-line script or via Python import.

Command-Line

python -m yolo_health_checker.analyze_dataset /path/to/yolo_dataset --output_dir results --save_images --save_csv

  • dataset_path: The path to your YOLO-format dataset (containing data.yaml, train/, val/ folders).
  • --output_dir: Optional path to store the output artifacts (CSV, images, etc.).
  • --save_images: Save class distribution bar charts and heatmaps.
  • --save_csv: Save CSV files with class distributions and health metrics.
  • --log_file: Specify the log file name (default: main.log).
  • --log_level: Logging verbosity (default: INFO).

Python Import

You can also integrate yolo-health-checker within your Python code:

from yolo_health_checker import analyze_dataset

health_checker = analyze_dataset(
    dataset_path='/path/to/yolo_dataset',
    output_dir='results',
    save_images=True,
    save_csv=True,
    log_level='INFO',
    log_file='analysis.log'
)

# Once analysis is done, inspect the results
health_checker.show_health_metrics()

Motivations & Numeric Measurements

Why numeric measurements?
Numeric metrics allow us to systematically compare how well different YOLO versions handle dataset variations. By converting each characteristic into a measurable number, we make the research both reproducible and statistically testable.

Below we list the main “dataset health” metrics we measure. Each is numeric with a clear interpretation, making them suitable for statistical analyses. The overarching principle: if it cannot be expressed numerically, we cannot reliably correlate it with YOLO performance.

1. Class Distribution Metrics

1.1. Entropy of Class Distribution

  • Reason: Measures the uniformity of the distribution of objects across classes. A high entropy indicates a more balanced dataset.
  • Formula:
    H = - Σ pᵢ log(pᵢ)
    (where pᵢ is the proportion of class i)

1.2. Gini Index

  • Reason: Captures how unevenly instances are distributed among classes.
  • Formula:
    G = 1 - Σ (pᵢ)²
    (where pᵢ is the proportion of class i)

1.3. Standard Deviation of Instances per Class

  • Reason: Indicates the spread of counts across different classes.

2. Spatial Distribution Metrics

2.1. Entropy of Object Locations

  • Reason: Checks if bounding boxes are clustered in a few regions or spread evenly.
  • Procedure: A 10×10 grid is created, and bounding box counts per cell are transformed into probabilities for entropy calculation.

2.2. Standard Deviation of Object Centers

  • Reason: Measures how widely scattered the center points of bounding boxes are across the image.

2.3. Distance from Center of Mass

  • Reason: Quantifies how far bounding box centers lie from the image center, highlighting potential “center bias.”

Example

To run a sample analysis (outputting both CSV and images):

python -m yolo_health_checker.analyze_dataset /path/to/yolo_dataset --output_dir results --save_images --save_csv --log_file my_log.log

  • This will log the process in my_log.log, generate bar charts for class distribution, produce bounding box heatmaps, and create CSV reports with class counts and dataset health metrics in the results/health folder.

Contributing

Feel free to open an issue or a pull request if you spot bugs or want to contribute improvements. We welcome new ideas on metrics or enhancements to support more YOLO-format variations.

License

This project is licensed under an open-source license (e.g., MIT, Apache 2.0, etc.). Check the repository for more details.

Happy analyzing with yolo-health-checker!

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

yolo_health_checker-0.1.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

yolo_health_checker-0.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file yolo_health_checker-0.1.0.tar.gz.

File metadata

  • Download URL: yolo_health_checker-0.1.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.0

File hashes

Hashes for yolo_health_checker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 614d69c14c93780569f0ef09584afa259397db0c40017f6c21e4f0ef825560dd
MD5 7a9a98582d7eadd25a9064ef7e60049b
BLAKE2b-256 e7443789b34b0121a08a1a95968e9b40024757e60896b53cc862d58e7bf87c3f

See more details on using hashes here.

File details

Details for the file yolo_health_checker-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for yolo_health_checker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7599a1bcc81e7b3fa49a442a588fd0cfb896793b866c145726c98d2abdbf8df5
MD5 79edc605df9f0e99e230a0dd7a0aa535
BLAKE2b-256 98ac366f079c19aacca814300d492b62da3f734ea65f96d1951231a5eb500de1

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