Answers.Body: <p>The usual way to implement this would be to add the new class with data examples.</p>
  
  <p>Some things you need to address:</p>
  
  <ul>
  <li><p>Sourcing new data for your "other" class. </p></li>
  <li><p>Ensuring the amount and variation of data in "other" class examples matches how the predictor will be used.</p></li>
  </ul>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>YOLO is quite complicated architecture, so you might want to look at <a href="https://github.com/experiencor/basic-yolo-keras" rel="nofollow noreferrer">this example using Keras on a Github project</a> for more details, if object detection is your goal.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-21T11:12:46.137Z
Answers.Text: "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!
Answers.UserDisplayName: flakes
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-01T13:30:01.833Z
Answers.LastActivityDate: 2018-01-01T13:35:07.220Z
Answers.LastEditDate: 2018-01-01T13:35:07.220Z
Answers.UserDisplayName: Neil Slater
Answers.Body: <p>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.</p>
  
  <p>This idea comes from a research paper that does a much better job of explaining the process than what I just said: <a href="https://arxiv.org/abs/1610.02136" rel="nofollow noreferrer">A Baseline for Detecting Misclassified and Out-of-Distribution Examples in Neural Networks</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-08T16:18:48.567Z
Answers.LastActivityDate: 2019-01-08T16:18:48.567Z
Answers.UserDisplayName: Karl Wenzel
Body: <p>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 &quot;not a digit&quot;, so that any letter, any other type of image, or random noise would be classified as &quot;not a digit&quot;. Similarly, with CIFAR-10, I want to have the 11th &quot;unknown&quot; class to classify any image that contains something out of the available 10 classes of CIFAR-10.</p>
  <p>So, how to implement such a feature? Maybe there are some examples somewhere, preferable with Keras.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-28T09:12:56.630Z
Comments.Text: hello, did you get solution for this?
Comments.UserDisplayName: Coder
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-11T13:02:11.207Z
Comments.Text: future readers may find [zero shot learning](https://en.wikipedia.org/wiki/Zero-shot_learning) interesting
Comments.UserDisplayName: Gulzar
Tags: <deep-learning><classification><image-recognition><implementation><multiclass-classification>
Title: How to implement an "unknown" class in multi-class classification with neural networks?
UserDisplayName: Sergey Kravchenko
ThreadText: # How to implement an "unknown" class in multi-class classification with neural networks?
  
  (Asked by: username_0 on 2017-12-31)
  
  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.
  
  **Tags:** deep-learning, classification, image-recognition, implementation, multiclass-classification
  
  > **Comments:**
  > **username_1**: hello, did you get solution for this?  
  > **username_2**: future readers may find [zero shot learning](https://en.wikipedia.org/wiki/Zero-shot_learning) interesting  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2018-01-01. Score: 4
  
  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](https://github.com/experiencor/basic-yolo-keras) for more details, if object detection is your goal.
  
  > **Comments:**
  > **username_4**: "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!  
  
  ---
  
  ### Answer by username_5 on 2019-01-08. Score: 3
  
  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](https://arxiv.org/abs/1610.02136)
  
  
  ---
  
  