I understand you want to handle unknown classes in a Convolutional Neural Network (CNN). When you introduce a new image (unknown-not belonging to any of the 3 classes), the model predicts it as any of the 3 classes, with a score that is around 0.98. This might be because of overfitting as it can lead to high confidence predictions even when they are incorrect, especially for classes that the model was not exposed to during training. To mitigate the impact of overfitting and make more reliable predictions, you can consider the following steps:
- Regularization: Apply regularization techniques, such as dropout or L2 regularization, during training. Regularization helps prevent overfitting and encourages the model to learn more general features.
- Data Augmentation: Increase the diversity of your training dataset by applying data augmentation techniques, such as random rotations, translations, or scaling. This can help the model generalize better to unseen examples.
After addressing overfitting and training a more robust model, you can set a threshold for your confidence score, if the highest predicted class probability is less than the threshold, classify the sample as the "unknown" class.
For further information, refer to the documentation links below: