Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

one_hot op不支持double类型 && paddle文档对应示例有误

Open alexqdh opened this issue 7 years ago • 2 comments

paddle版本1.3 python2.7 发现one_hot这个op不支持float32类型,只能先cast成int32才能正常跑,这点paddle文档上示例代码也是错的 http://www.paddlepaddle.org/documentation/api/en/0.15.0/layers.html#one-hot image

报错代码如下

def test_one_hot():
    with fluid.program_guard(fluid.Program()):
        label = fluid.layers.data(name='label', shape=[1], dtype='float32')
        one_hot_label = fluid.layers.one_hot(label, 3)
        one_hot_label_float = fluid.layers.cast(x=one_hot_label, dtype='float32')

        place = fluid.CUDAPlace(0)
        exe = fluid.Executor(place)
        y = np.array([[2.0], [2.0], [2.0]])
        outs = exe.run(
                feed={'label':y},
                fetch_list=[one_hot_label_float])
        print(outs[0])

label类型dtype和对应输入改为int32才能正常跑

def test_one_hot():
    with fluid.program_guard(fluid.Program()):
        label = fluid.layers.data(name='label', shape=[1], dtype='int32')
        one_hot_label = fluid.layers.one_hot(label, 3)
        one_hot_label_float = fluid.layers.cast(x=one_hot_label, dtype='float32')

        place = fluid.CUDAPlace(0)
        exe = fluid.Executor(place)
        y = np.array([[2], [2], [2]])
        outs = exe.run(
                feed={'label':y},
                fetch_list=[one_hot_label_float])
        print(outs[0])

alexqdh avatar Mar 30 '19 06:03 alexqdh

one hot输入肯定是正整数的,float不支持应该是OK的,文档问题很多很坑,哈哈😄

hjchen2 avatar Mar 30 '19 06:03 hjchen2

已在develop分支修复

https://github.com/PaddlePaddle/Paddle/blob/712bfb17cb6d10658d804748c84b67badf47f0d7/python/paddle/fluid/layers/nn.py#L6446

kuke avatar May 16 '19 06:05 kuke