!34101 Roll back the import method of the initializer

Merge pull request !34101 from 冯一航/initializer_import_rolling_back
This commit is contained in:
i-robot 2022-05-12 02:50:33 +00:00 committed by Gitee
commit 98cb5274a2
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 20 additions and 46 deletions

View File

@ -26,9 +26,6 @@ from .parameter import Parameter, ParameterTuple
from .seed import set_seed, get_seed
from .tensor import Tensor, RowTensor, SparseTensor, COOTensor, CSRTensor
from .variable import Variable
from .initializer import Initializer, TruncatedNormal, Normal, \
Uniform, HeUniform, HeNormal, XavierUniform, One, Zero, Constant, Identity, \
Sparse, Dirac, Orthogonal, VarianceScaling
# symbols from dtype
__all__ = [
@ -53,14 +50,7 @@ __all__ = [
"complex64", "complex128",
# __method__ from dtype
"dtype_to_nptype", "issubclass_", "dtype_to_pytype",
"pytype_to_dtype", "get_py_obj_dtype", 'Initializer',
'TruncatedNormal', 'Normal',
'Uniform', 'HeUniform',
'HeNormal', 'XavierUniform',
'One', 'Zero',
'Constant', 'Identity',
'Sparse', 'Dirac',
'Orthogonal', 'VarianceScaling'
"pytype_to_dtype", "get_py_obj_dtype"
]
__all__.extend([

View File

@ -94,8 +94,7 @@ class Zero(Initializer):
Examples:
>>> import mindspore
>>> from mindspore import Zero
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, Zero
>>> tensor1 = initializer(Zero(), [1, 2, 3], mindspore.float32)
>>> tensor2 = initializer('zeros', [1, 2, 3], mindspore.float32)
"""
@ -110,8 +109,7 @@ class One(Initializer):
Examples:
>>> import mindspore
>>> from mindspore import One
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, One
>>> tensor1 = initializer(One(), [1, 2, 3], mindspore.float32)
>>> tensor2 = initializer('ones', [1, 2, 3], mindspore.float32)
"""
@ -249,8 +247,7 @@ class XavierUniform(Initializer):
Examples:
>>> import mindspore
>>> from mindspore import XavierUniform
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, XavierUniform
>>> tensor1 = initializer(XavierUniform(), [1, 2, 3], mindspore.float32)
>>> tensor2 = initializer('xavier_uniform', [1, 2, 3], mindspore.float32)
"""
@ -294,8 +291,7 @@ class HeUniform(Initializer):
Examples:
>>> import mindspore
>>> from mindspore import HeUniform
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, HeUniform
>>> tensor1 = initializer(HeUniform(), [1, 2, 3], mindspore.float32)
>>> tensor2 = initializer('he_uniform', [1, 2, 3], mindspore.float32)
"""
@ -341,8 +337,7 @@ class HeNormal(Initializer):
Examples:
>>> import mindspore
>>> from mindspore import HeNormal
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, HeNormal
>>> tensor1 = initializer(HeNormal(), [1, 2, 3], mindspore.float32)
>>> tensor2 = initializer('he_normal', [1, 2, 3], mindspore.float32)
"""
@ -393,8 +388,7 @@ class Identity(Initializer):
Examples:
>>> import mindspore
>>> from mindspore import Identity
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, Identity
>>> tensor1 = initializer(Identity(), [2, 3], mindspore.float32)
>>> tensor2 = initializer('identity', [2, 3], mindspore.float32)
"""
@ -421,8 +415,7 @@ class Sparse(Initializer):
Examples:
>>> import mindspore
>>> from mindspore import Sparse
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, Sparse
>>> tensor1 = initializer(Sparse(sparsity=0.1, sigma=0.01), [5, 8], mindspore.float32)
"""
def __init__(self, sparsity, sigma=0.01):
@ -459,8 +452,7 @@ class Dirac(Initializer):
Examples:
>>> import mindspore
>>> from mindspore import Dirac
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, Dirac
>>> tensor1 = initializer(Dirac(groups=2), [6, 4, 3, 3], mindspore.float32)
>>> tensor2 = initializer("dirac", [6, 4, 3, 3], mindspore.float32)
"""
@ -511,8 +503,7 @@ class Orthogonal(Initializer):
Examples:
>>> import mindspore
>>> from mindspore import Orthogonal
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, Orthogonal
>>> tensor1 = initializer(Orthogonal(gain=2.), [2, 3, 4], mindspore.float32)
>>> tensor2 = initializer('orthogonal', [2, 3, 4], mindspore.float32)
"""
@ -567,8 +558,7 @@ class VarianceScaling(Initializer):
Examples:
>>> import mindspore
>>> from mindspore import VarianceScaling
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, VarianceScaling
>>> tensor1 = initializer(VarianceScaling(scale=1.0, mode='fan_out',
... distribution='untruncated_normal'), [2, 3], mindspore.float32)
>>> tensor2 = initializer('varianceScaling', [2, 3], mindspore.float32)
@ -625,8 +615,7 @@ class Uniform(Initializer):
Examples:
>>> import mindspore
>>> from mindspore import Uniform
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, Uniform
>>> tensor1 = initializer(Uniform(), [1, 2, 3], mindspore.float32)
>>> tensor2 = initializer('uniform', [1, 2, 3], mindspore.float32)
"""
@ -654,8 +643,7 @@ class Normal(Initializer):
Examples:
>>> import mindspore
>>> from mindspore import Normal
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, Normal
>>> tensor1 = initializer(Normal(), [1, 2, 3], mindspore.float32)
>>> tensor2 = initializer('normal', [1, 2, 3], mindspore.float32)
"""
@ -683,8 +671,7 @@ class TruncatedNormal(Initializer):
Examples:
>>> import mindspore
>>> from mindspore import TruncatedNormal
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, TruncatedNormal
>>> tensor1 = initializer(TruncatedNormal(), [1, 2, 3], mindspore.float32)
>>> tensor2 = initializer('truncatedNormal', [1, 2, 3], mindspore.float32)
"""
@ -728,8 +715,7 @@ def initializer(init, shape=None, dtype=mstype.float32):
>>> import numpy as np
>>> import mindspore
>>> from mindspore import Tensor
>>> from mindspore import One
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, One
>>> data = Tensor(np.zeros([1, 2, 3]), mindspore.float32)
>>> tensor1 = initializer(data, [1, 2, 3], mindspore.float32)
>>> tensor2 = initializer('ones', [1, 2, 3], mindspore.float32)

View File

@ -64,7 +64,7 @@ class Tensor(Tensor_):
>>> import numpy as np
>>> import mindspore as ms
>>> from mindspore import Tensor
>>> from mindspore import One
>>> from mindspore.common.initializer import One
>>> # initialize a tensor with numpy.ndarray
>>> t1 = Tensor(np.zeros([1, 2, 3]), ms.float32)
>>> print(t1)
@ -1827,8 +1827,7 @@ class Tensor(Tensor_):
Examples:
>>> import mindspore as ms
>>> from mindspore import Constant
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, Constant
>>> x = initializer(Constant(1), [2, 2], ms.float32)
>>> out = x.init_data()
>>> print(out)
@ -1903,8 +1902,7 @@ class Tensor(Tensor_):
Examples:
>>> import mindspore as ms
>>> from mindspore import Constant
>>> from mindspore.common.initializer import initializer
>>> from mindspore.common.initializer import initializer, Constant
>>> x = initializer(Constant(1), [2, 2], ms.float32)
>>> out = x.to_tensor()
>>> print(out)

View File

@ -255,7 +255,7 @@ For DNN researchers who are unfamiliar with Bayesian models, MDP provides high-l
1. Define a Deep Neural Network. The LeNet is used in this example.
```python
from mindspore import TruncatedNormal
from mindspore.common.initializer import TruncatedNormal
import mindspore.nn as nn
import mindspore.ops.operations as P

View File

@ -105,7 +105,7 @@ class CheckpointConfig:
Examples:
>>> from mindspore import Model, nn
>>> from mindspore import ModelCheckpoint, CheckpointConfig
>>> from mindspore import Normal
>>> from mindspore.common.initializer import Normal
>>>
>>> class LeNet5(nn.Cell):
... def __init__(self, num_class=10, num_channel=1):