cadip92
cadip92

Reputation: 151

What is the difference between keras.backend.max vs keras.backend.argmax?

I am a beginner in Deep Learning and while performing a practical assignment, came across the Keras documentation on keras.backend.

I went through the explanation a number of times. however, i cannot exactly understand the difference between max and argmax function.

Upvotes: 13

Views: 6508

Answers (1)

IonicSolutions
IonicSolutions

Reputation: 2599

I will explain this using max and argmax from the numpy package, but the two functions are identical to the ones in the Keras backend:

import numpy as np
vector = np.array([1, 2, 3, 2, 1])

Now, np.max(vector) returns the number 3, as this is the maximal value in the vector. np.argmax(vector) however returns 2, as this is the index of the maximal value in the vector.

The argmax function is often used to post-process the output of a softmax layer. Say the output layer of your classifier (which classifies some image into one of four classes) is

output = Dense(4, activation='softmax')(...)

and the output of predict(some_random_image) is [0.02, 0.90, 0.06, 0.02]. Then, argmax([0.02, 0.90, 0.06, 0.02]) immediately gives you the class (1).

Upvotes: 27

Related Questions