ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

MindSpore报错 StridedSlice这个算子在Ascend硬件上不支持input是uint8的数据类型

2022-07-17 17:37:25  阅读:135  来源: 互联网

标签:__ Ascend self 数据类型 报错 StridedSlice input Net out



1 报错描述

1.1 系统环境

Hardware Environment(Ascend/GPU/CPU): CPU
Software 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 脚本

训练脚本是通过构建StridedSlice的单算子网络,对输入Tensor根据步长和索引进行切片提取。脚本如下:

 01 class Net(nn.Cell):
 02     def __init__(self,):
 03         super(Net, self).__init__()
 04         self.strided_slice = ops.StridedSlice()
 05 
 06     def construct(self, x, begin, end, strides):
 07         out = self.strided_slice(x, begin, end, strides)
 08         return out
 09 input_x = Tensor([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]],
 10                   [[5, 5, 5], [6, 6, 6]]], mindspore.uint8)
 11 out = Net()(input_x,  (1, 0, 2), (3, 1, 3), (1, 1, 1))
 12 print(out)

1.2.2 报错

这里报错信息如下:

Traceback (most recent call last):
  File "160945-strided_slice.py", line 19, in <module>
    out = Net()(input_x,  (1, 0, 2), (3, 1, 3), (1, 1, 1))
  File "/root/miniconda3/envs/high_llj/lib/python3.7/site-packages/mindspore/nn/cell.py", line 574, in __call__
    out = self.compile_and_run(*args)
  File "/root/miniconda3/envs/high_llj/lib/python3.7/site-packages/mindspore/nn/cell.py", line 975, in compile_and_run
    self.compile(*inputs)
  File "/root/miniconda3/envs/high_llj/lib/python3.7/site-packages/mindspore/nn/cell.py", line 948, in compile
    jit_config_dict=self._jit_config_dict)
  File "/root/miniconda3/envs/high_llj/lib/python3.7/site-packages/mindspore/common/api.py", line 1092, in compile
    result = self._graph_executor.compile(obj, args_list, phase, self._use_vm_mode())
TypeError: Operator[StridedSlice]  input(UInt8) output(UInt8) is not supported. This error means the current input type is not supported, please refer to the MindSpore doc for supported types.


原因分析

我们看报错信息,在TypeError中,写到Operator[StridedSlice]  input(UInt8) output(UInt8) is not supported.. This error means the current input type is not supported, please refer to the MindSpore doc for supported types,主要意思是在对于StridedSlice算子,在cpu上, uint数据类型的输入和输出类型目前是不被支持的。解决方法是切换到ascend/gpu平台上运行。

2 解决方法

基于上面已知的原因,很容易做出如下修改:

context.set_context(device_target='Ascend')
class Net(nn.Cell):
    def __init__(self,):
        super(Net, self).__init__()
        self.strided_slice = ops.StridedSlice()

    def construct(self, x, begin, end, strides):
        out = self.strided_slice(x, begin, end, strides)
        return out
input_x = Tensor([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]],
                  [[5, 5, 5], [6, 6, 6]]], mindspore.uint8)
out = Net()(input_x,  (1, 0, 2), (3, 1, 3), (1, 1, 1))
print(out)

此时执行成功,输出如下:

[[[3]]

 [[5]]]

 

3 总结

定位报错问题的步骤:

1、找到报错的用户代码行:out = Net()(input_x,  (1, 0, 2), (3, 1, 3), (1, 1, 1));

2、 根据日志报错信息中的关键字,缩小分析问题的范围:input(kNumberTypeUInt8) output(kNumberTypeUInt8) is not supported;

3、需要重点关注变量定义、初始化的正确性。

4 参考文档

4.1 StridedSlice算子API接口

标签:__,Ascend,self,数据类型,报错,StridedSlice,input,Net,out
来源: https://www.cnblogs.com/skytier/p/16487819.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有