# Make the CNN to say “I don't know”

I am currently working on an image classification problem. To ease the implementation I used transfer learning in Keras with Resnet50 as base model.
I have 2 classes, however there are many possibilities that the input image may not belong to both the classes. In such cases the CNN should be able to output as Unknown.
Note : I can not create a separate class for unknown as it can come from any distribution.

I read that the Bayesian neural network would help in such cases.

Thank you

• 2 things can be done for this. 1. Make a label for other classes. 2. Set a threshold value of confidence and if the confidence is lower than the threshold, predict "I don't know" – thanatoz May 4 at 8:42
• @thanatoz Thanks for the swift response. 1. This could be difficult as it would be difficult to label those unknown classes (which may not be known during the training phase). 2. Setting confidence threshold, will try this approach and update. – deepguy May 4 at 8:45
• Given your phrasing, maybe you've already seen this, but we might as well have the link here: towardsdatascience.com/… – Ben Reiniger May 5 at 2:37
• @BenReiniger Thats great. I did look into that. It is in Pytorch, if I get the Keras implementation it would be much more helpful. Anyways I will check if I can generate the same for the image dataset I am using. – deepguy May 5 at 9:52
• @thanatoz I did look into the 2nd option. The problem with that is for this binary image classification most of the time I am getting the final probability as [0, 1] or [1, 0]. I tried to feed a plain image and it didn't vary much either. Any thoughts on this please. – deepguy May 5 at 9:54

You could put a one-class classification model before your CNN.

This would mean that you treat both your classes as one and then frame it as an anomaly detection problem. There are some different ways of achieving this. One way could be to do dimensionality reduction on the images and then use that image encoding to train an outlier detector like an one-class SVM. You can get some ideas here:

Learning Deep Features for One-ClassClassification

Anomaly Detection using One-Class Neural Networks

You can also look at cbeleites answer to this related questions. This was actually where I learned about one-class classification on images and it goes into a bit more detail and explains some caveats with using it.