Search code examples
pythontensorflowkerastensorflow2.0

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


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, referring to one researcher named Xavier Glorot) documentation link.

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