Reputation: 81
I am trying to predict the cat/dog image using the model.predict method. Since it is 2 class classifier I am getting an array of 2 values. As per my understanding, these values represent the probabilities to belong in each class (correct me if I am wrong). If it is so the probability must be summed to 1. But I am getting the same probability for both classes
Model History
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
flatten (Flatten) multiple 0
_________________________________________________________________
dense (Dense) multiple 30848
_________________________________________________________________
dropout (Dropout) multiple 0
_________________________________________________________________
batch_normalization (BatchNo multiple 512
_________________________________________________________________
dense_1 (Dense) multiple 12900
_________________________________________________________________
dropout_1 (Dropout) multiple 0
_________________________________________________________________
batch_normalization_1 (Batch multiple 400
_________________________________________________________________
dense_2 (Dense) multiple 10100
_________________________________________________________________
dropout_2 (Dropout) multiple 0
_________________________________________________________________
batch_normalization_2 (Batch multiple 400
_________________________________________________________________
dense_3 (Dense) multiple 10100
_________________________________________________________________
dropout_3 (Dropout) multiple 0
_________________________________________________________________
batch_normalization_3 (Batch multiple 400
_________________________________________________________________
dense_4 (Dense) multiple 10100
_________________________________________________________________
dropout_4 (Dropout) multiple 0
_________________________________________________________________
batch_normalization_4 (Batch multiple 400
_________________________________________________________________
dense_5 (Dense) multiple 202
=================================================================
Total params: 76,362
Trainable params: 75,306
Non-trainable params: 1,056
Prediction Code
class_prob=model.predict(new_array_2.T,batch_size=1)
print(class_prob)
classifications=model.predict_classes(new_array_2.T,batch_size=1)
print(classifications)
print(CATEGORIES[classifications[0]])
output
[[0.39456758 0.39456758]]
[0]
Dog
Upvotes: 0
Views: 135
Reputation: 56347
model.predict
just returns the computed output of your model given the input, so all the details you mentioned depend on the model's output, for example, activations at the last layer.
That the model outputs probabilities that sum to one is only produced by the softmax
activation at the output layer, to me it looks like your last layer has a different activation, probably sigmoid
, which will not produce probabilities that sum to one. You should prefer to use softmax
for multi-class classification.
Upvotes: 1