其他分享
首页 > 其他分享> > MindSpore报错"RuntimeError: Unexpected error. Inconsistent batch..

MindSpore报错"RuntimeError: Unexpected error. Inconsistent batch..

作者:互联网

1 报错描述

1.1 系统环境

ardware Environment(Ascend/GPU/CPU): CPU
Software Environment:
– MindSpore version (source or binary): 1.6.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脚本

此案例自定义数据集并进行batch操作。
图片.png

1.2.2报错

RuntimeError: Unexpected error. Inconsistent batch shapes, batch operation expect same shape for each data row, but got inconsistent shape in column 0, expected shape for this column is:, got shape:
图片.png

2 原因分析

根据报错信息提示,batch操作需要输入的数据集shape一致,但自定义数据集中的shape没有统一,导致报错。

3 解决方法

1.去掉batch操作。
图片.png

2.如果一定要对shape不一致的数据进行batch操作,需要整理数据集,通过pad补全等方式进行输入数据shape的统一。

4 类似问题

用户在做M2Det模型迁移时,若将代码中的create_m2det_dataset函数中的batch_size=1会得到每个图像的shape和每个targets的shape已修改为大小形状相同,程序可以顺利执行。但是,如果将batch_size改为10会报出如下错误。
图片.png
此处定位到是由于target数量不一致导致shape不一致,需要根据算法需求进行设计:
1.对target的数据进行调整,比如取target的最大值,表示这个网络里最多就这么多目标,然后用一些特殊分类来补齐,计算出来loss之后,再把这部分loss通过乘0过滤掉。
2.参考ssd/yolo之类的的模型做法,直接将target编码后与feature_map计算loss。

5 总结

1.进行batch操作必须保持输入数据的shape一致。
2.对原本shape不一致的数据一定要进行batch操作,需要考虑先将shape调整为一致,后续再对由于进行了shape调整导致的数值偏差进行处理。

6 参考文档

https://www.mindspore.cn/tutorials/zh-CN/master/advanced/dataset/transform.html

标签:loss,Unexpected,target,..,batch,shape,报错,一致
来源: https://www.cnblogs.com/skytier/p/16485301.html