Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use keras for binary classification?

I need simple example about how to use keras model. It is not clear for me what difference between model.evaluate and model.predict.

I want to create model for binary classification. Lets say I have images of cats and dogs, train model and can use it to predict which animal on given photo. Maybe there is some good into or tutorials. I read anything in first five pages in google, but found only complex level tutorials and discussions.

like image 523
Dmitry Manannikov Avatar asked Sep 29 '16 19:09

Dmitry Manannikov


Video Answer


1 Answers

To make things short:

  • model.evaluate evaluates a pair (X,Y) and returns the loss (and all other metrics configured for the model). This is for testing your model on a vaildation or test set.
  • model.predict predicts the outcome given an input X. This if for predicting the class from an input image for example.

This, among other things, is also clearly documented in the linked documentation.

You can find a lot of example models for Keras in the git repository (keras/examples) or on the Keras website (here and here).

For binary classification you could use this model for example:

model = Sequential()
model.add(Dense(300, init='uniform'))
model.add(Activation('relu'))
model.add(Dense(2, init='uniform'))
model.add(Activation('softmax'))

model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=0.02))
model.fit(X, Y)
like image 79
nemo Avatar answered Nov 14 '22 20:11

nemo