# How to get probabilities values with keras?

tensorflow version = '1.12.0'

keras version = '2.1.6-tf'

I'm using keras with tensorflow backend.

I want to get the probabilities values of the prediction. I want the probabilities to sum up to 1. I tried using 'softmax' and 'categorical_crossentropy' but nothing works.

This is my model:

X = pickle.load(open("X.pickle", "rb"))

number_of_gestures = 5
y = to_categorical(y, num_classes=number_of_gestures) #to_categorical is a function from keras - np_utils.

model = Sequential()
model.add(Conv2D(16, (2,2), input_shape=(IMG_SIZE, IMG_SIZE, 1), activation='relu'))

sgd = optimizers.SGD(lr=1e-2)
model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
model.fit(X, y, batch_size=500, epochs=40, validation_split=0.1)


The probabilities looks like that:

[1. 0. 0. 0. 0.]

And I want it to look like this:

[0.897. 0.023. 0.158. 0.780. 0.1021]

I know it does not sum up to 1 but this is just an example.

• A couple of questions: When you say that "the probabilities look like this", how do you get them right now? What is the size of your datasets? – Mark.F Feb 12 '19 at 7:25
• Can you please provide the code for your prediction cycles? The output that you're posting is quite telling. It's possible that you're already getting the probabilities you want but your prediction code is using some sort of argmax() function that is creating the [1,0,0,0] output. – I_Play_With_Data Feb 12 '19 at 22:52

I faced such a problem using CNN in Keras. Even, I thought that the output is being processed in the such a way like the argmax().