CleanVision Documentation

repository·main·Indexed 22 days ago

https://github.com/cleanlab/cleanvision

A data-centric AI package for automatically detecting common quality issues in image datasets, such as blurriness, exposure problems, and duplicates. It features the Imagelab class for auditing image folders, Hugging Face datasets, and Torchvision datasets, providing tools to find issues and generate visual reports.

Tokens
11.6K
Snippets
43
Records
57
Agent score
76%

What's inside CleanVision

  1. Use Imagelab to find issues in image datasets

    main

    The Imagelab class is the primary interface for automatically detecting common visual issues in image datasets. It allows you to specify a directory of images, run a suite of predefined checks (such as blur, brightness, or aspect ratio issues), and generate reports on the findings.

    To use Imagelab, you typically follow these steps:

    1. Initialize Imagelab with the path to your image folder.
    2. Run the detection process (e.g., using Imagelab.find_issues()).
    3. Inspect the results via reports or dataframes.
  2. Quickstart: Audit an image dataset with Imagelab

    main

    To audit an image dataset, use the Imagelab class. You provide the path to your image folder, call find_issues() to detect problems, and report() to visualize the results.

    from cleanvision import Imagelab
    
    # Specify path to folder containing the image files in your dataset
    imagelab = Imagelab(data_path="FOLDER_WITH_IMAGES/")
    
    # Automatically check for a predefined list of issues within your dataset
    imagelab.find_issues()
    
    # Produce a neat report of the issues found in your dataset
    imagelab.report()
  3. Quickstart: Audit image data with Imagelab

    main

    The primary way to use CleanVision is through the Imagelab class. You can initialize it by providing a path to a folder containing your images, then call find_issues() to detect problems (like duplicates, blurriness, or exposure issues) and report() to visualize the results.

    from cleanvision import Imagelab
    
    # Initialize with a folder path
    imagelab = Imagelab(data_path="FOLDER_WITH_IMAGES/")
    
    # Automatically check for a predefined list of issues
    imagelab.find_issues()
    
    # Produce a neat report of the issues found
    imagelab.report()
    from cleanvision import Imagelab
    
    # Specify path to folder containing the image files in your dataset
    imagelab = Imagelab(data_path="FOLDER_WITH_IMAGES/")
    
    # Automatically check for a predefined list of issues within your dataset
    imagelab.find_issues()
    
    # Produce a neat report of the issues found in your dataset
    imagelab.report()
  4. Release a new version

    main

    The release process involves several manual and automated steps:

    1. Merge all release-related PRs and ensure all CI Checks pass.
    2. Verify the version number in pyproject.toml matches the intended release.
    3. In the GitHub repository, draft a new release.
    4. Create a tag in the format v{version} and click Generate release notes.
    5. Note on PyPI: While GitHub Actions attempts to push to TestPyPI and PyPI, it may error due to permissions. If this happens, push to PyPI manually.
    6. Increment the version in pyproject.toml for the next cycle.
  5. Run tests with pytest

    main

    CleanVision uses pytest for testing. Use the following commands to run different test scenarios:

    • Run all tests:
      pytest
    • Run a specific file or filter by expression:
      pytest -k <filename or filter expression>
    • Run with verbose output:
      pytest --verbose
    • Run with code coverage (generates an HTML report in coverage_html_report/index.html):
      pytest --cov=cleanvision --cov-config .coveragerc --cov-report=html
    pytest --cov=cleanvision --cov-config .coveragerc --cov-report=html
  6. Set up a development environment for CleanVision

    main

    To contribute to CleanVision, it is recommended to use a virtual environment. You can use venv (built into Python 3) to isolate your development dependencies.

    1. Create the virtual environment in a directory named ENV:
      python3 -m venv ./ENV
    2. Activate the environment:
      source ./ENV/bin/activate

    Note: You must activate the environment every time you start a new shell session.

    python3 -m venv ./ENV
    source ./ENV/bin/activate
  7. Integrate with Torchvision Datasets

    main

    CleanVision works with Torchvision datasets by passing the dataset instance to the torchvision_dataset argument in Imagelab.

    from torchvision.datasets import CIFAR10
    from torch.utils.data import ConcatDataset
    
    # Prepare the Torchvision dataset
    train_set = CIFAR10(root="./", download=True)
    test_set = CIFAR10(root="./", train=False, download=True)
    dataset = ConcatDataset([train_set, test_set])
    
    # Initialize Imagelab with the Torchvision dataset
    imagelab = Imagelab(torchvision_dataset=dataset)
    
    imagelab.find_issues()
    imagelab.report()
    from torchvision.datasets import CIFAR10
    from torch.utils.data import ConcatDataset
    
    # Download and concatenate train set and test set
    train_set = CIFAR10(root="./", download=True)
    test_set = CIFAR10(root="./", train=False, download=True)
    dataset = ConcatDataset([train_set, test_set])
    
    
    imagelab = Imagelab(torchvision_dataset=dataset)
    
    imagelab.find_issues()
    
    imagelab.report()
  8. Perform type checking with mypy

    main

    CleanVision uses mypy for type checking. You can run it locally on the src directory using strict mode:

    mypy --strict --install-types --non-interactive --python-version 3.11  src
    mypy --strict --install-types --non-interactive --python-version 3.11  src
  9. Install CleanVision

    main

    You can install CleanVision via pip. To include all optional dependencies, use the [all] extra.

    Standard installation:

    pip install cleanvision

    Installation with all optional dependencies:

    pip install "cleanvision[all]"

    Install from source:

    pip install git+https://github.com/cleanlab/cleanvision.git

    Install from source with all optional dependencies:

    pip install "git+https://github.com/cleanlab/cleanvision.git#egg=cleanvision[all]"
    pip install cleanvision
  10. Integrate with Hugging Face Datasets

    main

    CleanVision supports Hugging Face datasets. When initializing Imagelab, pass the dataset to the hf_dataset argument and specify the key used for the image feature using the image_key argument.

    from datasets import load_dataset, concatenate_datasets
    
    # Prepare the dataset (e.g., combining splits)
    dataset_dict = load_dataset("cifar10")
    dataset = concatenate_datasets([d for d in dataset_dict.values()])
    
    # Initialize Imagelab with the HF dataset
    # Use image_key to point to the image feature name
    imagelab = Imagelab(hf_dataset=dataset, image_key="img")
    
    imagelab.find_issues()
    imagelab.report()
    from datasets import load_dataset, concatenate_datasets
    
    # Download and concatenate different splits
    dataset_dict = load_dataset("cifar10")
    dataset = concatenate_datasets([d for d in dataset_dict.values()])
    
    # Specify the key for Image feature in dataset.features in `image_key` argument
    imagelab = Imagelab(hf_dataset=dataset, image_key="img")
    
    imagelab.find_issues()
    
    imagelab.report()
  11. Format and lint code contributions

    main

    To maintain code quality, follow these styling steps before submitting a pull request:

    1. Format code with Black:
      python -m black src
    2. Check for style errors with flake8:
      flake8 --ignore=E203,E501,E722,E401,W503 src tests --count --show-source --statistics

    Best Practices:

    • Follow PEP-8 coding style.
    • Avoid wildcard imports (import *). Always import specific functions or classes.
    • Use the pre-commit framework to automate these checks. Install hooks with:
      pre-commit install
    python -m black src
    flake8 --ignore=E203,E501,E722,E401,W503 src tests --count --show-source --statistics
    pre-commit install