Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does keras normalize axis argument does?

I am a beginner in deep learning and I am working upon the mnist dataset in keras.

I used normalization as

tf.keras.utils.normalize(x_train, axis = 1)

I don't understand what does the axis argument means. Can you help me out with this?

like image 928
Aparajit Garg Avatar asked Oct 15 '18 08:10

Aparajit Garg


2 Answers

The normalize function just performs a regular normalization to improve performance:

Normalization is a rescaling of the data from the original range so that all values are within the range of 0 and 1.

There is a nice explanation of the axis argument in another post:

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

For example:

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

Also, for those who want to go deeper, there is an explanation from François Chollet - Keras’ author- on GitHub:

  • For Dense layer, all RNN layers and most other types of layers, the default of axis=-1 is what you should use,
  • For Convolution2D layers with dim_ordering=“th” (the default), use axis=1,
  • For Convolution2D layers with dim_ordering=“tf”, use axis=-1 (i.e. the default).

https://github.com/fchollet/keras/issues/1921

like image 113
Tina Iris Avatar answered Sep 21 '22 14:09

Tina Iris


keras.utils.normalize() function calls the numpy.linalg.norm() to compute the norm and then normalize the input data. The given axis argument is therefore passed to norm() function to compute the norm along the given axis.

like image 40
today Avatar answered Sep 20 '22 14:09

today