How to interpret Model.predict_classes() ?

1,197 views
Skip to first unread message

Jasper Bernales

unread,
Apr 2, 2016, 9:29:38 AM4/2/16
to Keras-users
Sorry for a very noob question here.

say for example I have the following model.

model = Sequential()
model.add(Convolution2D(1, filter_size, filter_size, border_mode='same',
                        input_shape=(1, 54, 36)))
model.add(LeakyReLU())
model.add(Flatten())
model.add(Dense(54*36, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam')

How is it different with the Model.predict()? 
Why am I getting a dimension of (samples,)? I was expecting a dimension of (samples, 54*36) though just like predict() & predict_proba.

aaditya prakash

unread,
Apr 3, 2016, 9:47:19 AM4/3/16
to Keras-users
Hi Jasper

Model.predict_classes gives you the most likely class only (highest probability value), therefore it is of dimension (samples,), for every input in sample there is one output - the  class.

To be more precise  Model.predict_classes calls argmax on the output of predict. See the code (of predict_classes below)

def predict_classes(self, X, batch_size=128, verbose=1):
  proba = self.predict(X, batch_size=batch_size, verbose=verbose)
        if self.class_mode == 'categorical':
            return proba.argmax(axis=-1)
        else:
            return (proba > 0.5).astype('int32')
Reply all
Reply to author
Forward
0 new messages