关于机器学习:MindSpore报错-seed2-in-StandardNormal-should-be-int-and-0

43次阅读

共计 2627 个字符,预计需要花费 7 分钟才能阅读完成。

1 报错形容 1.1 零碎环境 Hardware Environment(Ascend/GPU/CPU): GPUSoftware Environment:– MindSpore version (source or binary): 1.6.0– Python version (e.g., Python 3.7.5): 3.7.6– OS platform and distribution (e.g., Linux Ubuntu 16.04): Ubuntu 4.15.0-74-generic– GCC/Compiler version (if compiled from source):1.2 根本信息 1.2.1 脚本训练脚本是通过构建 StandardNormal 的单算子网络,生成合乎正态分布的随机数。脚本如下:01 class Net(nn.Cell):
02 def __init__(self, seed=2, seed2=-3):
03 super(Net, self).__init__()
04 self.standard_normal = ops.StandardNormal(seed=seed, seed2=seed2)
05 def construct(self, output_shape):
06 output = self.standard_normal(output_shape)
07 return output
08
09 output_shape = (2, 3, 4)
10 net = Net()
11 output = net(output_shape)
12 print(“OUTPUT: “, output)
1.2.2 报错这里报错信息如下:Traceback (most recent call last):
File “C:/Users/l30026544/PycharmProjects/q2_map/new/I4DSWV-standardNormal.py”, line 16, in <module>

net = Net()

File “C:/Users/l30026544/PycharmProjects/q2_map/new/I4DSWV-standardNormal.py”, line 10, in init

self.standard_normal = ops.StandardNormal(seed=seed, seed2=seed2)

File “C:\Users\l30026544\PycharmProjects\q2_map\lib\site-packages\mindspore\ops\primitive.py”, line 687, in deco

fn(self, *args, **kwargs)

File “C:\Users\l30026544\PycharmProjects\q2_map\lib\site-packages\mindspore\ops\operations\random_ops.py”, line 67, in init

Validator.check_non_negative_int(seed2, "seed2", self.name)

File “C:\Users\l30026544\PycharmProjects\q2_map\lib\site-packages\mindspore\_checkparam.py”, line 304, in check_non_negative_int

return check_number(arg_value, 0, Rel.GE, int, arg_name, prim_name)

File “C:\Users\l30026544\PycharmProjects\q2_map\lib\site-packages\mindspore\_checkparam.py”, line 168, in check_number

raise type_except(f'{prim_info} should be {arg_type.__name__} and must {rel_str},'

ValueError: seed2 in StandardNormal should be int and must >= 0, but got -3 with type int.

起因剖析咱们看报错信息,在 ValueError 中,写到 seed2 in StandardNormal should be int and must >= 0, but got -3 with type int,意思是 StandardNormal 算子里的 seed2 属性必须是大于等于 0 的整数,然而失去了一个正数。官网对两个参数 seed,seed2 的范畴都有进行阐明:

2 解决办法基于下面已知的起因,很容易做出如下批改:01 class Net(nn.Cell):
02 def __init__(self, seed=2, seed2=3):
03 super(Net, self).__init__()
04 self.standard_normal = ops.StandardNormal(seed=seed, seed2=seed2)
05 def construct(self, output_shape):
06 output = self.standard_normal(output_shape)
07 return output
08
09 output_shape = (2, 3, 4)
10 net = Net()
11 output = net(output_shape)
12 print(“OUTPUT: “, output)
此时执行胜利,输入如下:OUTPUT: [[-0.7503836 -1.4105444 1.689283 1.0585287 [ 0.3017666 -1.1502111 -0.3734214 -0.4361166]][0.7154948 0.6556154 2.3681476 1.1285974 [-0.4574307 0.36757398 -0.28976655 0.4996464]]]3 总结定位报错问题的步骤:1、找到报错的用户代码行:self.standard_normal = ops.StandardNormal(seed=seed, seed2=seed2);2、依据日志报错信息中的关键字,放大剖析问题的范畴 t seed2 in StandardNormal should be int and must >= 0, but got ;3、须要重点关注变量定义、初始化的正确性。4 参考文档 4.1 StandardNormal 算子 API 接口

正文完
 0