Skip to content

  • 体验新版
    • 正在加载...
  • 登录
  • PaddlePaddle
  • Paddle
  • Issue
  • #15547

P
Paddle
  • 项目概览

PaddlePaddle / Paddle
大约 2 年 前同步成功

通知 2325
Star 20933
Fork 5424
  • 代码
    • 文件
    • 提交
    • 分支
    • Tags
    • 贡献者
    • 分支图
    • Diff
  • Issue 1423
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 543
  • Wiki 0
    • Wiki
  • 分析
    • 仓库
    • DevOps
  • 项目成员
  • Pages
P
Paddle
  • 项目概览
    • 项目概览
    • 详情
    • 发布
  • 仓库
    • 仓库
    • 文件
    • 提交
    • 分支
    • 标签
    • 贡献者
    • 分支图
    • 比较
  • Issue 1,423
    • Issue 1,423
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 543
    • 合并请求 543
  • Pages
  • 分析
    • 分析
    • 仓库分析
    • DevOps
  • Wiki 0
    • Wiki
  • 成员
    • 成员
  • 收起侧边栏
  • 动态
  • 分支图
  • 创建新Issue
  • 提交
  • Issue看板
已关闭
开放中
Opened 1月 28, 2019 by saxon_zh@saxon_zhGuest

array_read编译和运行时返回结果的shape不一致

Created by: Ashleychen

def train_program(self):
    loss = fluid.layers.zeros(shape = [1], dtype = 'float')
    image_lod = fluid.layers.data(name = 'image_lod', dtype = 'float32',
        shape = [784], lod_level = 1)
    print('%s' % image_lod)
    label_lod = fluid.layers.data(name = 'label_lod', dtype = 'float32',
        shape = [1], lod_level = 1)
    print('%s' % label_lod)
    last_label_lod = fluid.layers.data(name = 'last_label_lod', dtype = 'float32',
        shape = [1], lod_level = 1)
    image_lod_rank_table = fluid.layers.control_flow.lod_rank_table(image_lod)
    label_lod_rank_table = fluid.layers.control_flow.lod_rank_table(label_lod)
    last_label_lod_rank_table = fluid.layers.control_flow.lod_rank_table(last_label_lod)
    image_array = lod_tensor_to_array(x = image_lod, table = image_lod_rank_table)
    label_array = lod_tensor_to_array(x = label_lod, table = label_lod_rank_table)
    last_label_array = lod_tensor_to_array(x = last_label_lod, table = last_label_lod_rank_table)
    array_len = fluid.layers.fill_constant(
        shape = [1], dtype = 'int64', value = self.list_size)
    counter = fluid.layers.zeros(shape = [1], dtype = 'int64')
    cond = fluid.layers.less_than(x = counter, y = array_len)
    while_op = fluid.layers.While(cond = cond)
    with while_op.block():
        current_image = fluid.layers.array_read(array = image_array, i = counter)
        current_label = fluid.layers.array_read(array = label_array, i = counter)
        print('%s' % current_label)
        # current_label_input = fluid.layers.unsqueeze(
        #     input = current_label,
        #     axes = [-1])
        # print('%s' % current_label_input)
        current_last_label = fluid.layers.array_read(array = last_label_array, i = counter)
        image_fc = fluid.layers.fc(input = current_image, size = 20)
        last_label_fc = fluid.layers.fc(input = current_label, size = 20)
        loss_input = fluid.layers.elementwise_add(
            x = image_fc, y = last_label_fc)
        current_loss = fluid.layers.softmax_with_cross_entropy(
            logits = loss_input, label = current_label)
        loss = fluid.layers.elementwise_add(
            loss, fluid.layers.reduce_sum(current_loss, dim = 0))
        #loss += current_loss
        fluid.layers.increment(x = counter, value = 1, in_place = True)
        fluid.layers.less_than(x = counter, y = array_len, cond = cond)
    return loss

我在跑一个简单的demo,用来测试序列数据的分布处理,发现当序列数据最后一维的大小为1的时候(如我的label数据)array_read运行时返回的结果会将shape的最后一维去掉,如我想要current_label返回的shape为(128,1),实际返回的却是(128),导致我fc的时候报错了: I0128 13:51:52.005067 11374 mul_op.cc:41] mul operator x.shape=128 y.shape=1, 20 x_num_col_dims=1 y_num_col_dims=1。 而且这样的话我在调用 current_loss = fluid.layers.softmax_with_cross_entropy(logits = loss_input, label = current_label)的时候编译的时候没有问题,运行的也是会报错:

Traceback (most recent call last):
  File "train_omniglot.py", line 202, in <module>
    ntm_main()
  File "train_omniglot.py", line 82, in ntm_main
    'last_label_lod': last_label_lod})
  File "/home/ol/anaconda2/lib/python2.7/site-packages/paddle/fluid/executor.py", line 470, in run
    self.executor.run(program.desc, scope, 0, True, True)
paddle.fluid.core.EnforceNotMet: Enforce failed. Expected labels_dims.size() == 2UL, but received labels_dims.size():1 != 2UL:2.
The labels should be a 2-D tensor. at [/paddle/paddle/fluid/operators/softmax_with_cross_entropy_op.cc:106]```
感觉这两个报错都是因为array_read返回结果的shape在编译和运行时不一致导致的。能帮忙解决一下吗?
指派人
分配到
无
里程碑
无
分配里程碑
工时统计
无
截止日期
无
标识: paddlepaddle/Paddle#15547
渝ICP备2023009037号

京公网安备11010502055752号

网络110报警服务 Powered by GitLab CE v13.7
开源知识
Git 入门 Pro Git 电子书 在线学 Git
Markdown 基础入门 IT 技术知识开源图谱
帮助
使用手册 反馈建议 博客
《GitCode 隐私声明》 《GitCode 服务条款》 关于GitCode
Powered by GitLab CE v13.7