Hitesh
Hitesh

Reputation: 1325

Keras initializers outside Keras

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.

Upvotes: 7

Views: 642

Answers (1)

Daniel M&#246;ller
Daniel M&#246;ller

Reputation: 86630

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) 

Upvotes: 5

Related Questions