Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

keras

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.

like image 756
cadip92 Avatar asked Oct 18 '18 16:10

cadip92


1 Answers

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).

like image 91
IonicSolutions Avatar answered Oct 22 '22 20:10

IonicSolutions