334 Star 1.5K Fork 864

MindSpore / docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
initTruncNormal.md 1.90 KB
一键复制 编辑 原始数据 按行查看 历史
luojianing 提交于 2023-07-21 15:16 . replace target=blank

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]]
1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
r2.0

搜索帮助