How to visualize cleaning issues

Problem statement

Exploratory data analysis (EDA) can be overwhelming. There are so many things to check. Duplicates in your dataset, bad/corrupted images in the set, blurred or bright/dark images, the list goes on.

DataEval created a data cleaning class to assist you with your EDA so you can start training your models on high quality data.

When to use

The cleaning class should be used during the initial EDA process or if you are trying to verify that you have the right data in your dataset.

What you will need

  1. A dataset to analyze

  2. A Python environment with the following packages installed:

    • dataeval

    • maite-datasets

Getting started

Let’s import the required libraries needed to set up a minimal working example

import polars as pl
from maite_datasets.image_classification import CIFAR10

from dataeval import Metadata
from dataeval.config import set_max_processes
from dataeval.quality import Outliers

set_max_processes(4)
_ = pl.Config.set_tbl_rows(-1)

Loading in the data

We are going to start by loading in the CIFAR-10 dataset.

The CIFAR-10 dataset contains 60,000 images - 50,000 in the train set and 10,000 in the test set. For the purposes of this demonstration, we are just going to use the test set.

# Load in the CIFAR10 dataset
testing_dataset = CIFAR10("./data", image_set="test", download=True)

# Create the metadata for the dataset
metadata = Metadata(testing_dataset)

Cleaning the dataset

Now we can begin finding those images which are significantly different from the rest of the data.

# Initialize the Outliers class
outliers = Outliers()

# Evaluate the data
results = outliers.evaluate(testing_dataset)

# Also evaluate the data classwise
results_classwise = results.classwise(metadata)

The results are a dictionary with the keys being the image that has an issue in one of the listed properties below:

  • Brightness

  • Blurriness

  • Missing

  • Zero

  • Width

  • Height

  • Size

  • Aspect Ratio

  • Channels

  • Depth

print(f"Total number of images with an issue: {len(results.aggregate_by_item())}")
Total number of images with an issue: 319
print(f"Total number of images with an issue (classwise): {len(results_classwise.aggregate_by_item())}")
Total number of images with an issue (classwise): 322
# View issues by metric
results.aggregate_by_metric()
shape: (7, 2)
metric_nameTotal
catu32
"zeros"197
"kurtosis"94
"entropy"60
"skew"29
"contrast"15
"brightness"8
"var"1
# View issues by metric (classwise)
results_classwise.aggregate_by_metric()
shape: (8, 2)
metric_nameTotal
catu32
"zeros"199
"kurtosis"83
"entropy"61
"contrast"15
"skew"13
"brightness"5
"var"4
"darkness"3
# View issues by class
results.aggregate_by_class(metadata)
shape: (11, 9)
class_namebrightnesscontrastentropykurtosisskewvarzerosTotal
catu32u32u32u32u32u32u32u32
"airplane"71354419021127
"bird"11620412457
"cat"0138302742
"frog"0143003139
"automobile"0131003136
"deer"0619201533
"horse"0111001922
"ship"0037001020
"dog"0120001215
"truck"022110713
"Total"8156094291197404
# View issues by class (classwise)
results_classwise.aggregate_by_class(metadata)
shape: (11, 10)
class_namebrightnesscontrastdarknessentropykurtosisskewvarzerosTotal
catu32u32u32u32u32u32u32u32u32
"airplane"020218212146
"cat"010710302445
"truck"3221010201645
"frog"01063003141
"automobile"000113002539
"bird"000310222037
"deer"16066301537
"horse"02175001934
"ship"100314111333
"dog"01064001526
"Total"51536183134199383

See also

How-to guides

Tutorials