Function Differences with tf.keras.initializers.TruncatedNormal

View Source On Gitee

tf.keras.initializers.TruncatedNormal

tf.keras.initializers.TruncatedNormal(
    mean=0.0, stddev=0.05, seed=None, dtype=tf.dtypes.float32
)

For more information, see tf.keras.initializers.TruncatedNormal.

mindspore.common.initializer.TruncatedNormal

mindspore.common.initializer.TruncatedNormal(sigma=0.01)

For more information, see mindspore.common.initializer.TruncatedNormal.

Usage

TensorFlow: By default, based on a normal distribution with mean 0.0 and standard deviation 0.05, limit the variables to be within 2 times the standard deviation from the mean and regenerate the distribution. Default values: mean=0.0, stddev=0.05.

MindSpore: By default, based on a normal distribution with mean 0.0 and standard deviation 0.01, limit the variables to be within 2 times the standard deviation from the mean and regenerate the distribution. Default values: sigma=0.01.

Code Example

The following results are random.

import tensorflow as tf

init = tf.keras.initializers.TruncatedNormal()
x = init(shape=(1, 2))

with tf.Session() as sess:
    print(x.eval())

# out:
# [[-0.71518797 -0.6879003 ]]
import mindspore as ms
from mindspore.common.initializer import TruncatedNormal, initializer

x = initializer(TruncatedNormal(), shape=[1, 2], dtype=ms.float32)
print(x)

# out:
# [[0.01012452 0.00313655]]