7

I want to initialize a 4*11 matrix using glorot uniform in Keras, using following code:

import keras
keras.initializers.glorot_uniform((4,11))

I get this output :

<keras.initializers.VarianceScaling at 0x7f9666fc48d0>

How can I visualize the output? I have tried c[1] and got output 'VarianceScaling' object does not support indexing.

petezurich
  • 9,280
  • 9
  • 43
  • 57
Hitesh
  • 1,285
  • 6
  • 20
  • 36

1 Answers1

5

The glorot_uniform() creates a function, and later this function will be called with a shape. So you need:

# from keras.initializers import * #(tf 1.x)

from tensorflow.keras.initializers import *

unif = glorot_uniform() #this returns a 'function(shape)'
mat_as_tensor = unif((4,11)) #this returns a tensor - use this in keras models if needed   
mat_as_numpy = K.eval(mat) #this returns a numpy array (don't use in models)
print(mat_as_numpy) 
Daniel Möller
  • 84,878
  • 18
  • 192
  • 214