关于人工智能:MindSpore报错-StridedSlice这个算子在Ascend硬件上不支持input是uint8的数据类型

5次阅读

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

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 接口

正文完
 0