Search code examples
pythonmachine-learningdeep-learningconv-neural-networkimage-classification

How to have a default output for an Image Classifier?


I coded a simple image classifier using CNN to classify input images to labels: Dog or Cat. When images other than Cats/Dogs are shown the CNN classifies it into any one of the label(Dog or Cat), which is incorrect. I wanted my CNN to classify/label all other random images(House, People, Birds, etc.) as Invalid input. How can this be done?


Solution

  • There are two ways you can do it..

    1 . Include a 3rd class in your training data having any random images like House, People, Birds, etc. so that while inferencing you will get this prediction for random data (if you include all possible max amount of images).

    2 . Use of threshold after your softmax classifir like any thing below a thresold of 0.7 ( change according to your wish after doing some trials) would be unknown class ( This trick i use very often)