change tf.contrib.layers.xavier_initializer() to 2.0.0

Issue

how can I change

tf.contrib.layers.xavier_initializer()

to tf version >= 2.0.0 ??

all codes:

W1 = tf.get_variable("W1", shape=[self.input_size, h_size],
                             initializer=tf.contrib.layers.xavier_initializer())

Solution

the TF2 replacement for tf.contrib.layers.xavier_initializer() is tf.keras.initializers.glorot_normal(Xavier and Glorot are 2 names for the same initializer algorithm) documentation link.

if dtype is important for some compatibility reasons – use tf.compat.v1.keras.initializers.glorot_normal

Answered By – Poe Dator

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published