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]
).
- How To Import Word2vec Into Tensorflow Seq2seq Model?
- Pyqt5 Cannot Update Progress Bar From Thread And Received The Error "cannot Create Children For A Parent That Is In A Different Thread"
- Valueerror: Negative Dimension Size Caused By Subtracting 2 From 1 For Maxpool1d With Input Shapes: [?,1,1,128]. Full Code,output & Error In The Post:
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"