Heatmap Comparison#

This notebooks provides an overview for using and understanding Heatmap comparison check.

Structure:

What Is a Heatmap Comparison?#

Heatmap comparison is a method of detecting data drift in image data. Data drift is simply a change in the distribution of data over time or between several distinct cases. It is also one of the top reasons that a machine learning model performance degrades over time, or when applied to new scenarios.

The Heatmap comparison check simply computes an average image for all images in each dataset, train and test, and visualizes both the average images of both. That way, we can visually compare the difference between the datasets’ brightness distribution. For example, if training data contains significantly more images with sky, we will see that the average train image is brighter in the upper half of the heatmap.

Comparing Labels for Object Detection#

For object detection tasks, it is also possible to visualize Label Drift, by displaying the average of bounding box label coverage. This is done by producing label maps per image, in which each pixel inside a bounding box is white and the rest and black. Then, the average of all these images is displayed.

In our previous example, the drift caused by more images with sky in training would also be visible by a lack of labels in the upper half of the average label map of the training data, due to lack of labels in the sky.

Other Methods of Drift Detection#

Another, more traditional method to detect such drift would be to use statistical methods. Such an approach is covered by several builtin check in the deepchecks.vision package, such as the Label Drift Check or the Image Dataset Drift Check.

Run the Check on a Classification Task (MNIST)#

Imports#

from deepchecks.vision.datasets.classification.mnist import load_dataset

Loading Data#

mnist_data_train = load_dataset(train=True, batch_size=64, object_type='VisionData')
mnist_data_test = load_dataset(train=False, batch_size=64, object_type='VisionData')
from deepchecks.vision.checks import HeatmapComparison

check = HeatmapComparison()
result = check.run(mnist_data_train, mnist_data_test)
result
Validating Input:
|     | 0/1 [Time: 00:00]
Validating Input:
|#####| 1/1 [Time: 00:00]

Ingesting Batches - Train Dataset:
|                                                                                                                                                             | 0/157 [Time: 00:00]

Ingesting Batches - Train Dataset:
|#######################                                                                                                                                      | 23/157 [Time: 00:00]

Ingesting Batches - Train Dataset:
|##############################################                                                                                                               | 46/157 [Time: 00:00]

Ingesting Batches - Train Dataset:
|#####################################################################                                                                                        | 69/157 [Time: 00:00]

Ingesting Batches - Train Dataset:
|############################################################################################                                                                 | 92/157 [Time: 00:00]

Ingesting Batches - Train Dataset:
|##################################################################################################################9                                          | 115/157 [Time: 00:00]

Ingesting Batches - Train Dataset:
|##########################################################################################################################################                   | 138/157 [Time: 00:00]

Ingesting Batches - Train Dataset:
|#############################################################################################################################################################| 157/157 [Time: 00:00]


Ingesting Batches - Test Dataset:
|                                                                                                                                                             | 0/157 [Time: 00:00]


Ingesting Batches - Test Dataset:
|#######################                                                                                                                                      | 23/157 [Time: 00:00]


Ingesting Batches - Test Dataset:
|###############################################                                                                                                              | 47/157 [Time: 00:00]


Ingesting Batches - Test Dataset:
|#######################################################################                                                                                      | 71/157 [Time: 00:00]


Ingesting Batches - Test Dataset:
|##############################################################################################                                                               | 94/157 [Time: 00:00]


Ingesting Batches - Test Dataset:
|####################################################################################################################9                                        | 117/157 [Time: 00:00]


Ingesting Batches - Test Dataset:
|#############################################################################################################################################                | 141/157 [Time: 00:00]


Ingesting Batches - Test Dataset:
|#############################################################################################################################################################| 157/157 [Time: 00:00]



Computing Check:
|     | 0/1 [Time: 00:00]



Computing Check:
|#####| 1/1 [Time: 00:00]
Heatmap Comparison


To display the results in an IDE like PyCharm, you can use the following code:

#  result.show_in_window()

The result will be displayed in a new window.

Run the Check on an Object Detection Task (Coco)#

from deepchecks.vision.datasets.detection.coco import load_dataset

train_ds = load_dataset(train=True, object_type='VisionData')
test_ds = load_dataset(train=False, object_type='VisionData')
check = HeatmapComparison()
result = check.run(train_ds, test_ds)
result
Validating Input:
|     | 0/1 [Time: 00:00]
Validating Input:
|#####| 1/1 [Time: 00:00]

Ingesting Batches - Train Dataset:
|     | 0/2 [Time: 00:00]

Ingesting Batches - Train Dataset:
|##5  | 1/2 [Time: 00:00]

Ingesting Batches - Train Dataset:
|#####| 2/2 [Time: 00:00]

Ingesting Batches - Train Dataset:
|#####| 2/2 [Time: 00:00]


Ingesting Batches - Test Dataset:
|     | 0/2 [Time: 00:00]


Ingesting Batches - Test Dataset:
|##5  | 1/2 [Time: 00:00]


Ingesting Batches - Test Dataset:
|#####| 2/2 [Time: 00:00]


Ingesting Batches - Test Dataset:
|#####| 2/2 [Time: 00:00]



Computing Check:
|     | 0/1 [Time: 00:00]



Computing Check:
|#####| 1/1 [Time: 00:00]
Heatmap Comparison