1.系统环境
硬件环境(Ascend/GPU/CPU): Ascend
执行模式:静态图
Python版本:3.7
操作系统平台:Linux
2. 报错信息
2.1 问题描述
TypeError: For 'Tensor', the type of 'input_data' should be one of '['Tensor', 'ndarray', 'str_', 'list', 'tuple', 'float', 'int', 'bool', 'complex']', but got type 'NoneType'.
复制
3. 根因分析
根据报错我们可以知道输入的数据类型不对,从本文的标题可以知道我们得到了一个','(逗号),类型是它。这里指明了报错的大概位置是我们可以去输入里面去找问题
以下代码为输入数据:
xs_pad = Tensor(shape=[batch_size, None, 80], dtype=mindspore.float32)
ys_pad = Tensor(shape=[batch_size, 50], dtype=mindspore.int32,)
ys_in_pad = Tensor(shape=[batch_size, 51], dtype=mindspore.int32, init=One())
ys_out_pad = Tensor(shape=[batch_size, 51], dtype=mindspore.int32, init=One())
xs_masks = Tensor(shape=[batch_size, 1, None], dtype=mindspore.float32)
ys_sub_masks = Tensor(shape=[batch_size, 51, 51], dtype=mindspore.float32, init=One())
ys_masks = Tensor(shape=[batch_size, 1, 51], dtype=mindspore.float32, init=One())
ys_lengths = Tensor(shape=[batch_size], dtype=mindspore.int32, init=One())
xs_chunk_masks = Tensor(shape=[batch_size, 1, None], dtype=mindspore.bool_)
复制
我们仔细排查以上代码能够发现ys_pad代码的错误,多了一个逗号。
4. 解决方案
修改如下:
ys_pad = Tensor(shape=[batch_size, 50], dtype=mindspore.int32, init=One())