静态图跑动态shape场景报错ValueError:The 7th input dims of ‘set_inputs‘ must be the same as network‘s input,but

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.),根据这些信息来设定上图中输入。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值