What does keras normalize axis argument does?
Asked Answered
V

2

6

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?

Valley answered 15/10, 2018 at 8:44 Comment(0)
M
6

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

Mouthpart answered 15/10, 2018 at 9:47 Comment(1)
Quick follow up to this, I'm trying to do deep learning on spectrograms with two channels. I have a tensor with shape (50, 50, 60, 2). I want to normalize every spectrogram and each channel (so along the (:, 50, 60, :) axis. When I do normalize(tens[: , :, :, 0], axis=0)[0][0] == normalize(tens[0, :, :, 0])[0] I get all False. Why is that? Shouldn't they be the same?Disconformity
P
3

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.

Pedometer answered 15/10, 2018 at 10:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.