Facing issue while initializing parameters in tensorflow

hi, you can try something like this (low level):

def weights(name, shape, mean=0.0, stddev=0.02):
    var = tf.Variable(tf.random_normal_initializer(mean=mean, stddev=stddev)(shape), name=name)
    return var

values = weights(name='w1', shape=[25, 1])

or following the tensorflow docs (keras):

def weights(name, shape):
    initializer = tf.keras.initializers.GlorotNormal()
    val = initializer(shape=shape)
    return tf.Variable(val, name=name)

values = weights(name='w1', shape=[25, 1])
2 Likes