[Solved] MindSpore Error: StridedSlice operator does not support input of uint8 data type on Ascend hardware

1 Error description

1.1 System Environment

Hardware Environment(Ascend/GPU/CPU): CPU
Software Environment:
– MindSpore version (source or binary): 1.8.0
– Python version (eg, Python 3.7.5): 3.7.6
– OS platform and distribution (eg, Linux Ubuntu 16.04): Ubuntu 4.15.0-74-generic
– GCC/Compiler version (if compiled from source):

1.2 Basic information

1.2.1 Script

The training script is to construct a single-operator network of StridedSlice, and extract slices from the input Tensor according to the step size and index. The script is as follows:

 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 Error reporting

The error message here is as follows:

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.


Cause Analysis

Let’s look at the error message. In TypeError, write 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, mainly It means that for the StridedSlice operator, on the CPU, the input and output types of the uint data type are currently not supported. The solution is to switch to run on the ascend/gpu platform.

2 Solutions

For the reasons known above, it is easy to make the following modifications:

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)

At this point, the execution is successful, and the output is as follows:

[[[3]]

 [[5]]]

 

3 Summary

Steps to locate the error report:

1. Find the line of user code that reported the error: out = Net()(input_x, (1, 0, 2), (3, 1, 3), (1, 1, 1));

2. According to the keywords in the log error message, narrow the scope of the analysis problem: input(kNumberTypeUInt8) output(kNumberTypeUInt8) is not supported;

3. It is necessary to focus on the correctness of variable definition and initialization.

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *