【发布时间】:2018-03-14 04:49:20
【问题描述】:
我正在尝试在 PyTorch 中计算每个通道的渐变图像。为此,我想在图像的每个通道上使用 Sobel 滤波器执行标准 2D 卷积。我正在为此使用torch.nn.functional.conv2d 函数
在下面的最小工作示例代码中,我收到一个错误:
import torch
import torch.nn.functional as F
filters = torch.autograd.Variable(torch.randn(1,1,3,3))
inputs = torch.autograd.Variable(torch.randn(1,3,10,10))
out = F.conv2d(inputs, filters, padding=1)
RuntimeError: Given groups=1, weight[1, 1, 3, 3], 所以预期 input[1, 3, 10, 10] 有 1 个通道,但有 3 个通道
这表明 groups 需要为 3。但是,当我创建 groups=3 时,我得到一个不同的错误:
import torch
import torch.nn.functional as F
filters = torch.autograd.Variable(torch.randn(1,1,3,3))
inputs = torch.autograd.Variable(torch.randn(1,3,10,10))
out = F.conv2d(inputs, filters, padding=1, groups=3)
RuntimeError:无效参数 4:超出范围 /usr/local/src/pytorch/torch/lib/TH/generic/THTensor.c:440
当我检查THTensor类中的那个代码sn-p时,它指的是一堆维度检查,但我不知道我哪里出错了。
这个错误是什么意思?如何使用此 conv2d 函数执行我想要的卷积?我相信我误解了groups 参数。
【问题讨论】:
标签: convolution pytorch