'Apply Tensorflow tf.keras.initializers.GlorotNormal(seed=1) to tf.Variable

How to apply the initializer to the tf.Variable function? Am I on the right track?

def initialize_parameters():
                                
    initializer = tf.keras.initializers.GlorotNormal(seed=1)   
   
    W1 = tf.Variable(initializer(shape=([25, 12288]))
    b1 = tf.Variable(initializer(shape=([25, 1]))
    W2 = tf.Variable(initializer(shape=([12, 25]))
    b2 = tf.Variable(initializer(shape=([12, 1]))
    W3 = tf.Variable(initializer(shape=([6, 12]))
    b3 = tf.Variable(initializer(shape=([6, 1]))
  

    parameters = {"W1": W1,
                  "b1": b1,
                  "W2": W2,
                  "b2": b2,
                  "W3": W3,
                  "b3": b3}
    
    return parameters

I want the shapes to be as follow -


W1 shape: (25, 12288)
b1 shape: (25, 1)
W2 shape: (12, 25)
b2 shape: (12, 1)
W3 shape: (6, 12)
b3 shape: (6, 1)



Solution 1:[1]

It should be W1 = tf.Variable(initializer(shape=(25, 12288))). Notice the round bracket

Solution 2:[2]

W1 =  tf.Variable(initializer(shape=[25, 12288]))
b1 = tf.Variable(initializer(shape=[25, 1]))
W2 = tf.Variable(initializer(shape=[12, 25]))
b2 = tf.Variable(initializer(shape=[12, 1]))
W3 = tf.Variable(initializer(shape=[6, 12]))
b3 = tf.Variable(initializer(shape=[6, 1]))

should be like this

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Byron Wong
Solution 2 Namit Patel