Limiting probability percentage of irrelevant image in CNN

时间秒杀一切 提交于 2021-02-10 14:51:40

问题


I am training a cnn model with five classes using keras library. Using model.predict function i get prediction percentage of the classes. My problem is for a image which doesn't belong to these classes and completely irrelevant, the predict class still predicts the percentages according to the classes.

How do I prevent it? How do I identify it as irrelevant?


回答1:


I assume you are using a softmax activation on your last layer to generate the probabilities for each class. By definition, the sum of the outputs from the softmax activation must add up to 1. Therefore, it is impossible for the neural net to say that the image does not belong to any of your classes, with your current setup.

There are two potential ways you could address this:

  1. Add another class that represents "other" or "unknown" objects (so you have 6 classes).

  2. Add another output to your neural net (or train a completely independent neural net) that does binary classification on whether or not the image is in one of the 5 classes. That way, if your secondary output says that the image is not in the 5 classes, you can ignore the softmax output.

In both cases, you will need to augment your dataset with images that do not fall in your 5 classes.



来源:https://stackoverflow.com/questions/62322703/limiting-probability-percentage-of-irrelevant-image-in-cnn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!