在GPU上使用火炬张量的Block_reduce

问题描述

我有一个2D张量,我试图通过平均每4列来减小它。对于numpy数组,可以使用skimage.measure模块中的block_reduce函数来完成。

我也可以将其用于CPU火炬张量,因为它在后台将输入张量转换为numpy数组。当我的张量加载到GPU上时,这将不起作用。在PyTorch中有什么有效的方法可以实现这一目标吗?

这是我想做的,由block_reduce演示:

import numpy as np
import torch
from skimage.measure import block_reduce

t1 = np.array([[0,4,2,1,5],[1,[2,[3,5]]).astype('float')
t1 = torch.from_numpy(t1)

t2 = block_reduce(t1,block_size=(1,4),func=np.mean)

print(t1)
print(t2)

产生的输出:

tensor([[0.,4.,2.,1.,5.],[1.,[2.,[3.,5.]],dtype=torch.float64)
[[2.5  2.  ]
 [2.75 2.  ]
 [3.   2.  ]
 [3.25 2.  ]]

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...