Keras - Get Probability Per Each Class
Solution 1:
The problem is that you are using the 'sparse_categorical_crossentropy'
loss with class_mode='binary'
in your ImageDataGenerator
.
You have two possibilities here:
- Change the loss to
'categorical_crossentropy'
and setclass_mode='categorical'
. - Leave the loss as is but set
class_mode='sparse'
.
Either will work.
Refer to this answer for the difference between the two losses (in Tensorflow, but it holds for Keras too). The short version is that the sparse loss expects labels to be integer classes (e.g. 1, 2, 3...), whereas the normal one wants one-hot encoded vectors (e.g. [0, 1, 0, 0]
).
Cheers
EDIT: as @Simeon Kredatus pointed out, it was a normalization issue.
This can be easily solved by setting the appropriate flags in the ImageDataGenerator
constructors for both training and test sets, namely samplewise_center=True
and samplewise_std_normalization=True
.
Updating the answer so people can see the solution. In general, remember the trash-in-trash-out principle.
Post a Comment for "Keras - Get Probability Per Each Class"