MindSpore报错: `seed2` in `StandardNormal` should be int and >=0

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

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的范围都有进行说明:
MindSpore报错: `seed2` in `StandardNormal` should be int and >=0_第1张图片
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接口

你可能感兴趣的:(机器学习人工智能深度学习)