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.
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With