Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 697
Hitesh Avatar asked Oct 16 '17 12:10

Hitesh


1 Answers

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) 
like image 150
Daniel Möller Avatar answered Sep 28 '22 01:09

Daniel Möller