Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of axis=-1 in keras.argmax?

Tags:

keras

axis

argmax

I am a beginner in Keras and need help to understand keras.argmax(a, axis=-1) and keras.max(a, axis=-1). What is the meaning of axis=-1 when a.shape = (19, 19, 5, 80)? And also what will be the output of keras.argmax(a, axis=-1) and keras.max(a, axis=-1)?

like image 328
youngtackpark Avatar asked Nov 22 '17 13:11

youngtackpark


People also ask

What is np argmax axis=- 1?

argmax along axis-1. Remember: for 2D Numpy arrays, axis-1 points horizontally across the columns. So when we set axis = 1 , argmax identifies the maximum value for every row. And it returns the column index of that maximum value.

What does axis=- 1 mean in numpy?

The axis parameter specifies the index of the new axis in the dimensions of the result. For example, if axis=0 it will be the first dimension and if axis=-1 it will be the last dimension.

What does it mean axis=- 1 in python?

A DataFrame object has two axes: “axis 0” and “axis 1”. “axis 0” represents rows and “axis 1” represents columns. Now it's clear that Series and DataFrame share the same direction for “axis 0” – it goes along rows direction.

What is argmax in keras?

argmax( x, axis=-1 ) Defined in tensorflow/python/keras/_impl/keras/backend.py . Returns the index of the maximum value along an axis.


1 Answers

This means that the index that will be returned by argmax will be taken from the last axis.

Your data has some shape (19,19,5,80). This means:

  • Axis 0 = 19 elements
  • Axis 1 = 19 elements
  • Axis 2 = 5 elements
  • Axis 3 = 80 elements

Now, negative numbers work exactly like in python lists, in numpy arrays, etc. Negative numbers represent the inverse order:

  • Axis -1 = 80 elements
  • Axis -2 = 5 elements
  • Axis -3 = 19 elements
  • Axis -4 = 19 elements

When you pass the axis parameter to the argmax function, the indices returned will be based on this axis. Your results will lose this specific axes, but keep the others.

See what shape argmax will return for each index:

  • K.argmax(a,axis= 0 or -4) returns (19,5,80) with values from 0 to 18
  • K.argmax(a,axis= 1 or -3) returns (19,5,80) with values from 0 to 18
  • K.argmax(a,axis= 2 or -2) returns (19,19,80) with values from 0 to 4
  • K.argmax(a,axis= 3 or -1) returns (19,19,5) with values from 0 to 79
like image 146
Daniel Möller Avatar answered Sep 20 '22 21:09

Daniel Möller