<p>This is not really a programming problem, its way more complicated. What you want is called Out of Distribution detection, where the classifier has a way to tell you that the sample is not on the training set.</p>

<p>There are recent research papers that deal with this problem, such as <a href="https://arxiv.org/abs/1802.04865" rel="nofollow noreferrer">https://arxiv.org/abs/1802.04865</a> and <a href="https://arxiv.org/abs/1711.09325" rel="nofollow noreferrer">https://arxiv.org/abs/1711.09325</a></p>

<p>In general you cannot use a model that has not been trained specifically for this, for example, the probabilities produced by a softmax classifier are not calibrated for this purpose, so thresholding these probabilities will not work at all.</p>
My CNN classifier gives wrong prediction on random images
<p>I trained my CNN classifier (using tensorflow) with 3 data categories (ID card, passport, bills).<br>
When I test it with images that belong to one of the 3 categories, it gives the right prediction. However, when I test it with a wrong image (a car image for example) it keeps giving me prediction (i.e. it predicts that the car belongs the ID card category).   </p>

<p><strong>Is there a way to make it display an error message instead of giving a wrong prediction?</strong></p>