PR: New Widget! Class Confusion - With Google Colab Support!

Hey everyone! Have you ever wanted to further explore where your model was being confused? Look and take a peek at which specific images were being confused for x vs y class? Or look at the distributions of your mislabeled classes for your tabular models? ClassConfusion will do exactly this!

For both images and tabular, we pass in our ClassificationInterpretation object, along with a list of classes, and we can specify if we want an ordered set of classes or just the two back to back. For instance with Pets, we can either pass in classlist = ['Ragdoll', 'Birman', 'Maine_Coon'] or classlist = [('Ragdoll', 'Birman'), ('British_Shorthair', 'Russian_Blue')]. If we want exact orders, simply pass in is_ordered=True

When the tabs pop up, you will be greeted with those images in order of the most_confused, along with their relative filenames (this was mostly to help the Google Colaboratory people as we do not have access to FileDeleter.) The first class in pairs will be the ‘truth’, and the second the ‘prediction’

For tabular, we can do the same as the above but also pass in a set of variables to look at too if we want to see specific ones. In order to use it on regular Jupyter notebooks, call from fastai.widgets import ClassConfusion. For Google Colaboratory users, my repo is available here

The documentation is available here

Here are some snippets of what each of the types look like:


Hi Zachary, this is invaluable, I have been having issues training classifiers, where the classes have similar images or data in them. This class makes it easy for me to now show to anyone concerned the limitations of the model. Also ethically it helps me to explain any contentious issues I may have with certain Datasets especially to people who have no interest in the technicalities of AI. It also appears to make it easier to remove images you may not want to use.

Exlcellent stuff, mrfabulous1 :smiley::smiley:


Hi Zachary:

I am trying to get your widget working under fastai v2 – it seems the object model has changed a bit. Before I trawl through the code and try and update it, I was just wondering if you have done this?


p.s. it seems to be getting stuck on e.g.

self._is_tab = (str(type( == "<class ''>")

I have, it’s a part of fastinference.

pip install fastinference
from fastinference.class_confusion import *

Thanks so much!!

Looking forward to investigating your library :slight_smile: