Function Differences with tf.keras.initializers.RandomNormal

View Source On Gitee

tf.keras.initializers.RandomNormal

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

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

mindspore.common.initializer.Normal

mindspore.common.initializer.Normal(sigma=0.01, mean=0.0)

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

Usage

TensorFlow: generate a normal distribution with a mean of 0.0 and a standard deviation of 0.05 by default. Default values: mean=0.0, stddev=0.05.

MindSpore: generate a normal distribution with a mean of 0.0 and a standard deviation of 0.01 by default. Default values: mean=0.0, sigma=0.01.

Code Example

The following results are random.

import tensorflow as tf

init = tf.keras.initializers.RandomNormal()

x = init(shape=(2, 2))

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

# out:
# [[-1.4192176  1.9695756]
#  [ 1.6240929  0.9677597]]
import mindspore as ms
from mindspore.common.initializer import Normal, initializer

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

# out:
# [[ 0.01005767 -0.00049193]
#  [-0.00026987  0.02598832]]