Skip to content Skip to sidebar Skip to footer

Output Probability Score With Keras Using Model.predict()

I have a cnn model for image classification which uses a sigmoid activation function as its last layer from keras import layers from keras import models model = model

Solution 1:

I'm not sure if this is a version issue, but I do get probability scores.

I used a dummy network to test the output:

from keras import layers
from keras import models
from keras import __version__ as used_keras_version
import numpy as np


model = models.Sequential()
model.add(layers.Dense(5, activation='sigmoid', input_shape=(1,)))
model.add(layers.Dense(1, activation='sigmoid'))
print((model.predict(np.random.rand(10))))
print('Keras version used: {}'.format(used_keras_version))

Yields to the following output:

[[0.252406  ]
 [0.25795603]
 [0.25083578]
 [0.24871194]
 [0.24901393]
 [0.2602583 ]
 [0.25237608]
 [0.25030616]
 [0.24940264]
 [0.25713784]]
Keras version used: 2.1.4

Really weird that you get only a binary output of 0 and 1. Especially as the sigmoid layer actually returns float values.

I hope this helps somehow.


Post a Comment for "Output Probability Score With Keras Using Model.predict()"