提问人:singa1994 提问时间:6/11/2019 最后编辑:singa1994 更新时间:7/31/2020 访问量:13439
Pytorch 中的批处理矩阵乘法 - 与输出维度的处理混淆
Batch-Matrix multiplication in Pytorch - Confused with the handling of the output's dimension
问:
我有两个数组:
A
B
数组包含一批RGB图像,形状为:A
[batch, Width, Height, 3]
而 Array 包含对图像进行“类似变换”操作所需的系数,其形状为:B
[batch, 4, 4, 3]
简单地说,单个图像的运算是输出环境映射()的乘法。normalMap * Coefficients
我想要的输出应该保持形状:
[batch, Width, Height, 3]
我尝试使用但失败了。这可能吗?torch.bmm
答:
5赞
prosti
6/13/2019
#1
我认为您需要计算 PyTorch 可以与
BxCxHxW : number of mini-batches, channels, height, width
格式,并使用 matmul
,因为 bmm
使用张量或 ndim/dim/rank =3。
我知道您可能会在网上找到这个,但无论如何:
batch1 = torch.randn(10, 3, 20, 10)
batch2 = torch.randn(10, 3, 10, 30)
res = torch.matmul(batch1, batch2)
res.size() # torch.Size([10, 3, 20, 30])
评论
torch.nn.functional.conv2d