MindSpore报错 `half_pixel_centers`=True only support in Ascend

发布时间:2022-11-17 21:00

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

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作了说明:
MindSpore报错 `half_pixel_centers`=True only support in Ascend_第1张图片
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接口

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号