Keras: How to find the predicted class for a specific testing sample?

Created on 21 Mar 2017  路  5Comments  路  Source: keras-team/keras

I have created a model in keras for classifying MNIST digits. Now I want to see the predicted classes for first 10 testing samples. How do I do that ?

Most helpful comment

I assume your outputs are a softmax over classes. If your input is (n, 1, 28, 28) or whatever, run model.predict(x), and you will get a numpy array shaped (n, 10). If you just want to see the most likely class for each sample, use np.argmax(y, axis=1) to convert the softmax outputs into an array of integers representing the most likely class for each sample.

Cheers

All 5 comments

I assume your outputs are a softmax over classes. If your input is (n, 1, 28, 28) or whatever, run model.predict(x), and you will get a numpy array shaped (n, 10). If you just want to see the most likely class for each sample, use np.argmax(y, axis=1) to convert the softmax outputs into an array of integers representing the most likely class for each sample.

Cheers

I resolved the issue. Actually model.prect_classes() function does that for me. I didn't know that. Thanks anyway.

@codeheadshopon There is no function named prect_classes
I got the error when I tried: AttributeError: 'Model' object has no attribute 'prect_classes'
Are you sure you typed it right?

@DNXie The function name is actually predict_classes()

python throws me an error when I put model.predict_classes(). It says that it needs an argument for the function :(

TypeError: predict_classes() missing 1 required positional argument: 'x'

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MarkVdBergh picture MarkVdBergh  路  3Comments

amityaffliction picture amityaffliction  路  3Comments

harishkrishnav picture harishkrishnav  路  3Comments

snakeztc picture snakeztc  路  3Comments

oweingrod picture oweingrod  路  3Comments