What is the better way to predict classes for the models developed using the functional API in Keras

We can predict the class for new data instances using the Sequential classification model in Keras using the predict_classes() function. What is the way to predict the class for models that developed using the functional API?

For example, I have a model (functional API based) with sigmoid activation on the last layer to get probabilities in a multi-label classification. When I apply model.predict(), I got a series of probabilities even though the loss is binary_crossentropy.

I understand that I can do this classification manually e.g. following approach.

test_predict_proba = model.predict(x_test, batch_size=batch_size)
class_predict = (test_predicted_proba  0.5).astype(int)

I am wondering is there any standard procedure to do the same?

Topic predict functional-api keras multilabel-classification

Category Data Science


Is this a multi-label problem or a pure classification problem? If it is just classification change the activation function in the final layer to softmax. When you do predictions select the output with the highest probability as the class. Alternatively use model.evaluate(.....). versus model.predict Documentation is here,

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.