19
$\begingroup$

For example, I need to detect classes for MNIST data. But I want to have not 10 classes for digits, but also I want to have 11th class "not a digit", so that any letter, any other type of image, or random noise would be classified as "not a digit". Similarly, with CIFAR-10, I want to have the 11th "unknown" class to classify any image that contains something out of the available 10 classes of CIFAR-10.

So, how to implement such a feature? Maybe there are some examples somewhere, preferable with Keras.

$\endgroup$
2
  • $\begingroup$ hello, did you get solution for this? $\endgroup$
    – Coder
    Commented Aug 28, 2021 at 9:12
  • $\begingroup$ future readers may find zero shot learning interesting $\endgroup$
    – Gulzar
    Commented Jan 11, 2022 at 13:02

2 Answers 2

4
$\begingroup$

The usual way to implement this would be to add the new class with data examples.

Some things you need to address:

  • Sourcing new data for your "other" class.

  • Ensuring the amount and variation of data in "other" class examples matches how the predictor will be used.

Code examples for this are not necessary, as you would just use the same network design as you already have and just add another output. This is a data and model definition problem.

Logically you have another option: As well as outputting the predicted class, you predict separately whether there is any detectable object at all as a true/false value. This still requires the additional data, but is for example how the YOLO algorithm works for object detection. Object detection has a specific meaning - it involves finding the co-ordinates and class of possibly multiple objects in an image. This goes beyond the wording of your question, but is a typical end goal if you are asking this kind of question.

YOLO predicts the presence of an object separately from the class of object. The additional data for YOLO training comes from segmenting the source images, so many parts of the target image are background with no objects. In that case the additional data you require is due to more detailed labelling within each image example.

YOLO is quite complicated architecture, so you might want to look at this example using Keras on a Github project for more details, if object detection is your goal.

$\endgroup$
1
  • 2
    $\begingroup$ "As well as outputting the predicted class, you predict separately whether there is any detectable object at all as a true/false value." Thanks for this! Combining this as a first step to my existing model has decreased the noise significantly! $\endgroup$
    – flakes
    Commented Dec 21, 2018 at 11:12
3
$\begingroup$

If you are using a softmax distribution for your classification, then you could determine what your baseline max probability is for correctly classified samples, and then infer if a new sample doesn't belong to any of your known classes if its max probability is below some kind of threshold.

This idea comes from a research paper that does a much better job of explaining the process than what I just said: A Baseline for Detecting Misclassified and Out-of-Distribution Examples in Neural Networks

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .