关于深度学习:MindSpore报错RuntimeError-Unexpected-error-Inconsistent-batch

6次阅读

共计 1077 个字符,预计需要花费 3 分钟才能阅读完成。

1 报错形容 1.1 零碎环境 ardware Environment(Ascend/GPU/CPU): CPUSoftware 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 操作。

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:

2 起因剖析依据报错信息提醒,batch 操作须要输出的数据集 shape 统一,但自定义数据集中的 shape 没有对立,导致报错。3 解决办法 1. 去掉 batch 操作。

2. 如果肯定要对 shape 不统一的数据进行 batch 操作,须要整顿数据集,通过 pad 补全等形式进行输出数据 shape 的对立。4 相似问题用户在做 M2Det 模型迁徙时,若将代码中的 create_m2det_dataset 函数中的 batch_size= 1 会失去每个图像的 shape 和每个 targets 的 shape 已批改为大小形态雷同,程序能够顺利执行。然而,如果将 batch_size 改为 10 会报出如下谬误。

此处定位到是因为 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/tuto…

正文完
 0