关于神经网络:MindSpore报错-halfpixelcentersTrue-only-support-in-Ascend

39次阅读

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

1 报错形容 1.1 零碎环境 Hardware Environment(Ascend/GPU/CPU): CPUSoftware Environment:– MindSpore version (source or binary): 1.8.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 脚本调用 ResizeBilinear 算子,用双线性插值调整输出 Tensor 为指定的大小。脚本如下:01 context.set_context(device_target=’CPU’)
02 x = Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mindspore.float32)
03 resize_bilinear = ops.ResizeBilinear((5, 5), half_pixel_centers=True)
04 output = resize_bilinear(x)
05 print(output)
1.2.2 报错这里报错信息如下:Traceback (most recent call last):
File “C:/Users/l30026544/PycharmProjects/q2_map/new/ResizeBilinear.py”, line 7, in <module>

resize_bilinear = ops.ResizeBilinear((5, 5), half_pixel_centers=True)

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\nn_ops.py”, line 3263, in init

raise ValueError(f"Currently `half_pixel_centers`=True only support in Ascend device_target,"

ValueError: Currently half_pixel_centers=True only support in Ascend device_target, but got CPU

起因剖析咱们看报错信息,在 ValueError 中,写到 Currently half_pixel_centers=True only support in Ascend device_target, but got CPU,意思是只反对在 Ascend 环境下 half_pixel_centers 属性能力设置为 True。这一点官网 API 作了阐明:

2 解决办法基于下面已知的起因,很容易做出如下批改:01 context.set_context(device_target=’Ascend’)
02 x = Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mindspore.float32)
03 resize_bilinear = ops.ResizeBilinear((5, 5), half_pixel_centers=True)
04 output = resize_bilinear(x)
05 print(output)
此时执行胜利,输入如下:[[[1. 2. 3. 4. 5.1. 2. 3. 4. 5.[1. 2. 3. 4. 5.]]]]3 总结定位报错问题的步骤:1、找到报错的用户代码行: resize_bilinear = ops.ResizeBilinear((5, 5), half_pixel_centers=True);2、依据日志报错信息中的关键字,放大剖析问题的范畴 Currently half_pixel_centers=True only support in Ascend device_target, but got CPU ;4 参考文档 4.1 ResizeBilinear 算子 API 接口

正文完
 0