tf.keras.initializers.Constant(value=0)
For more information, see tf.keras.initializers.Constant.
mindspore.common.initializer.Constant(value)
For more information, see mindspore.common.initializer.Constant.
TensorFlow: The function input parameter value
supports scalar, list, tuple, and array types. Suppose you need to create a tensor of the specified shape, and the input parameter value
of this interface is a list or an array, the number of elements contained in value
must be less than or equal to the number of elements with the specified shape. If the number of elements contained in value
must be less than the number of elements with the specified shape, the last element of value
is used to fill the remaining positions.
MindSpore: The function input parameter value
supports scalar and array types. When value
is an array, only a tensor with the same shape as value
can be generated.
As an example, if the input is an array, the code sample is as follows:
TensorFlow:
import numpy as np
import tensorflow as tf
value = np.array([0, 1, 2, 3, 4, 5, 6, 7])
value = value.reshape([2, 4])
init = tf.keras.initializers.Constant(value)
x = init(shape=(2, 4))
y = init(shape=(3, 4))
with tf.Session() as sess:
print(x.eval(), "\n")
print(y.eval())
# out:
# [[0. 1. 2. 3.]
# [4. 5. 6. 7.]]
# [[0. 1. 2. 3.]
# [4. 5. 6. 7.]
# [7. 7. 7. 7.]]
MindSpore:
import numpy as np
import mindspore as ms
from mindspore.common.initializer import initializer, Constant
value = np.array([0, 1, 2, 3, 4, 5, 6, 7])
value = value.reshape([2, 4])
x = initializer(Constant(value), shape=[2, 4], dtype=ms.float32)
print(x)
# out:
# [[0. 1. 2. 3.]
# [4. 5. 6. 7.]]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。