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.

Could you please help me in understanding how can I implement Bayesian CNN with transfer learning. Any material or reference link would be really helpful.

Thank you

  • 1
    $\begingroup$ 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" $\endgroup$
    – thanatoz
    Commented May 4, 2019 at 8:42
  • $\begingroup$ @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. $\endgroup$
    – deepguy
    Commented May 4, 2019 at 8:45
  • 2
    $\begingroup$ Given your phrasing, maybe you've already seen this, but we might as well have the link here: towardsdatascience.com/… $\endgroup$
    – Ben Reiniger
    Commented May 5, 2019 at 2:37
  • $\begingroup$ @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. $\endgroup$
    – deepguy
    Commented May 5, 2019 at 9:52
  • $\begingroup$ @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. $\endgroup$
    – deepguy
    Commented May 5, 2019 at 9:54

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.