飞桨能否更方便的进行Tensor的索引选择?Can the PaddlePaddle be more convenient for tensor index selection?

klr1opcd  于 2022-11-03  发布在  其他
关注(0)|答案(4)|浏览(130)

中文 (Chinese)

  • 版本、环境信息
Paddle With CUDA: True

OS: debian stretch/sid
Python version: 3.7.4

CUDA version: 9.2.148
cuDNN version: 7.3.1
Nvidia driver version: 418.67
  • 复现信息:

动态图版本

import paddle
import paddle.fluid as fluid
from paddle.fluid import layers, dygraph as dg

place = fluid.CUDAPlace(fluid.dygraph.ParallelEnv().dev_id)
fluid.enable_dygraph(place)

inp = layers.randn([5,4,128,128])
slc = inp > 0

# inp[layers.where(slc)] = 0

inp[slc] = 0

print(inp[layers.where(slc)])

静态图版本

import paddle
import paddle.fluid as fluid
from paddle.fluid import layers
import numpy as np

exe = fluid.Executor(fluid.CUDAPlace(0))

x = fluid.data(name='x', shape=[5,4,128,128], dtype='float32')
slc = x > 0
x[slc] = 0
y = x * 1.0

prog = fluid.default_main_program()
each_ret, = exe.run(prog, feed={'x':np.random.rand(5,4,128,128).astype(np.float32)}, fetch_list=[y])
print(each_ret)
  • 建议描述:希望能实现如上的操作,正如numpy所能做到的那样,这样比起index_select会方便很多

英文 (English)

Version/Environment Infomation

Paddle With CUDA: True

OS: debian stretch/sid
Python version: 3.7.4

CUDA version: 9.2.148
cuDNN version: 7.3.1
Nvidia driver version: 418.67

To Reproduce

Dynamic Graph Version

import paddle
import paddle.fluid as fluid
from paddle.fluid import layers, dygraph as dg

place = fluid.CUDAPlace(fluid.dygraph.ParallelEnv().dev_id)
fluid.enable_dygraph(place)

inp = layers.randn([5,4,128,128])
slc = inp > 0

# inp[layers.where(slc)] = 0

inp[slc] = 0

print(inp[layers.where(slc)])

Static Graph Version

import paddle
import paddle.fluid as fluid
from paddle.fluid import layers
import numpy as np

exe = fluid.Executor(fluid.CUDAPlace(0))

x = fluid.data(name='x', shape=[5,4,128,128], dtype='float32')
slc = x > 0
x[slc] = 0
y = x * 1.0

prog = fluid.default_main_program()
each_ret, = exe.run(prog, feed={'x':np.random.rand(5,4,128,128).astype(np.float32)}, fetch_list=[y])
print(each_ret)

Describe the feature and the current behavior/state.

Hope to achieve the above operation, as numpy can do, this will be much more convenient than index_select

zpgglvta

zpgglvta1#

同时希望实现 tensor[...,None,:] 这类类numpy操作方法

bqujaahr

bqujaahr2#

谢谢,我们将收录并考量和安排相应实现

lc8prwob

lc8prwob3#

同时希望实现 tensor[...,None,:] 这类类numpy操作方法

paddle现在有多个index索引op:可以试一下 indexl_select / index_sample / gather / gather_nd

htzpubme

htzpubme4#

同时希望实现 tensor[...,None,:] 这类类numpy操作方法

paddle现在有多个index索引op:可以试一下 indexl_select / index_sample / gather / gather_nd

谢谢,这个我本身就知道的,只是说不太方便,如标题, 更方便

相关问题