1.系统环境
硬件环境(Ascend/GPU/CPU): Ascend
执行模式:静态图
Python版本:3.7
操作系统平台:Linux
2. 报错信息
2.1 问题描述
静态图跑动态shape场景报错
ValueError: The 7th input dims of 'set_inputs' must be the same as network's input, but got 'set_inputs' : 2 and network's input: 3.
复制
2.2 报错信息
File “*/python3.7/site-packages/mindspore/nn/cell.py”, line 2221, in _check_compile_dynamic_shape f”The {index + 1}th input dims of ‘set_inputs’ must be the same as network’s input,”
ValueError: the 7th input dims of ‘set_inputs’ must be the same as network’s input, but got ‘set_inputs’: 2 and network’s input: 3
复制
3. 根因分析
动态shape场景,这是说在set_inputs的时候的输入和网络输入的shape不一致,当我们使用静态图动态shape功能时,需要在训练之前给动态的部分置为None如下:
xs_pad = Tensor(shape=[batch_size, None, 80], dtype=mindspore.float32)
ys_pad = Tensor(shape=[batch_size, 50], dtype=mindspore.int32, init=One())
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_)
复制
这是因为第7个输入的shape和网络真实所需要的不符合。
4. 解决方案
可以通过迭代打印数据部分看下数据的情况(shape,dtype信息etc.),根据这些信息来设定上图中输入。