Confusion Matrix#

This notebooks provides an overview for using and understanding the confusion matrix check.


What is the purpose of the check?#

The confusion matrix check outputs a confusion matrix for both classification problems and object detection problems. In object detection problems, some predictions do not overlap on any label and can be classified as not found in the confusion matrix.

Generate Dataset#

We generate a sample dataset of 128 images from the COCO dataset, and using the YOLOv5 model.


In this example, we use the pytorch version of the coco dataset and model. In order to run this example using tensorflow, please change the import statements to:

from import coco_tensorflow as coco
from import coco_torch as coco

train_ds = coco.load_dataset(object_type='VisionData')
Downloading to

  0%|          | 0.00/14.1M [00:00<?, ?B/s]
100%|██████████| 14.1M/14.1M [00:00<00:00, 300MB/s]

Run the check#

from import ConfusionMatrixReport

check = ConfusionMatrixReport(categories_to_display=10)
result =
Processing Batches:
|     | 0/1 [Time: 00:00]
Processing Batches:
|█████| 1/1 [Time: 00:00]
Processing Batches:
|█████| 1/1 [Time: 00:00]

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

Computing Check:
|█████| 1/1 [Time: 00:00]
Confusion Matrix

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.

Total running time of the script: (0 minutes 1.561 seconds)

Gallery generated by Sphinx-Gallery