In the MNIST dataset, you have 10 defined classes, one for each digit. But you don't have a "not a digit" class. It seems that most image classification datasets are the same. But in a business setting, for a production model, you could certainly get invalid images that don't correspond to any of the defined classes.

So let's say you were to create a handwritten digit image classifying model to be used in a real-world project. If you don't have a "not a digit" class, then if somebody submits a picture of the letter "M", then it will incorrectly be classified as one of the 10 digit classes.

So, in this example, should you define a "not a digit" class and train the model on a set of images that the model may be expected to receive that have nothing to do with handwritten digits such that invalid images are correctly classified as "not a digit"?


1 Answer 1


You can have that but I recommend something else for your case. Suppose that you have 10 classes of digits that they are mutually exclusive. Consequently, your output vector will always be on-hot encoded. In a simple case, your output vector should contain ten entries for each class. To make your model distinguish between those inputs which are digits and those which are not, do the following:

Increase the size of output to eleven. Provide data-set that contains eleven-entries labels. the first entry corresponds to the existence of a digit. If it is a digit the first entry should be one and next 10 entries should be activated for the according to the value of the digit. So, your labels will not be one-hot encoded. If the input is not a digit the first entry of the output should be zero and other entries are don't cares.

  • $\begingroup$ This is a slightly different approach to what I was asking. I don't see why you have to have a flag for "is digit" plus a one hot encoded vector of size 10, when you could just have an a "not a digit" class and add it to the one hot encoded vector making it a size of 11. $\endgroup$
    – AshleyS
    Apr 9, 2018 at 9:31
  • $\begingroup$ @AshleyS I didn't understand what you said. I'm saying you have to have 11 outputs, but your output vector won't be one-hot encoded for digits. $\endgroup$ Apr 10, 2018 at 15:05

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.