Confusion Matrix - Image Classification

Is there a way to create a confusion Matrix on Tflite Model Maker - Image Classification that is similar to Audio Classification?

Hi @Hagen_Hagen

Take a look at those notebooks for showing confusion matrix with sklearn and matplotlib:

and

Finally this one with Model maker classes:

I think by combining you can print confusion matrix also for Image Classification task.

Best

1 Like

Hi I followed the 3rd notebook and I get this error.

AttributeError: 'ImageClassifier' object has no attribute 'confusion_matrix'

Maybe ‘ImageClassifier’ object has no attribute 'confusion_matrix then. So create it customly by following the 2 first notebook with sklearn and matplotlib.

Best

1 Like

What I would, while it’s not available on the ImageClassifier, is to copy what AudioClassifier is doing: https://github.com/tensorflow/examples/blob/1ff6d7aa9bdf9749ada28bf67ad435ca518b6232/tensorflow_examples/lite/model_maker/core/task/audio_classifier.py#L86

the code might be easy to copy/adapt

2 Likes

Where will I put the code? Inside the image_classifier.py? or just in another cell in Jupyter Notebook?

I’d just create another cell with a function.
that is the easiest solution

1 Like

I put it inside the image_classifier.py and it worked. Will that be fine?

I guess so, if it’s working for you that’s enough, right?

1 Like

@Hagen_Hagen
Create a PR with that fix.

2 Likes

I am getting the same error “AttributeError: ‘ImageClassifier’ object has no attribute ‘confusion_matrix’” when I put it in another cell, I think putting it inside image_classifier.py would be fine since there’s no error and ‘model.confusion_matrix’ worked since I put it inside the image_classifier.py. I just thought it will break the package, but it worked. Thank you so much for the help guys!

1 Like

Hi @Hagen_Hagen
Checkout this link Quantization in tensorflow-lite | Tensor Examples