Fix initializer

Merge pull request  from shaojunsong/fix/initializer
This commit is contained in:
i-robot 2022-06-15 06:32:02 +00:00 committed by Gitee
commit 38862988f5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 4 additions and 3 deletions
mindspore/python/mindspore/common

View File

@ -747,9 +747,10 @@ def initializer(init, shape=None, dtype=mstype.float32):
f"but got {shape}")
if isinstance(init, str):
init = _INITIALIZER_ALIAS[init.lower()]()
if init is None:
raise ValueError("The class corresponding to '{}' was not found.".format(init))
class_name = _INITIALIZER_ALIAS.get(init.lower())
if class_name is None:
raise ValueError(f"For 'initializer', the class corresponding to '{init}' was not found.")
init = class_name()
elif isinstance(init, numbers.Number):
init = Constant(init)
shape = shape if shape is not None else init.shape