【发布时间】:2020-07-17 13:23:30
【问题描述】:
我正在尝试将 sobel 过滤器应用于我的网络。我收到此错误:“'Tensor' 对象不可调用” 这是我的代码:
class SobelFilter(nn.Module):
def __init__(self):
super(SobelFilter, self).__init__()
kernel1=torch.Tensor([[1, 0, -1],[2,0,-2],[1,0,-1]])
kernela=kernel1.expand((1,1,3,3))
kernel2=torch.Tensor([[1, 2, 1],[0,0,0],[-1,-2,-1]])
kernelb=kernel2.expand((1,1,3,3))
inputs = torch.randn(1,1,64,128)
self.conv1 = F.conv2d(inputs,kernela,stride=1,padding=1)
self.conv2 = F.conv2d(inputs,kernelb,stride=1,padding=1)
def forward(self, x ):
print(x.shape)
G_x = self.conv1(x) %GIVES ERROR AT THIS LINE
G_y = self.conv2(x)
out = torch.sqrt(torch.pow(G_x,2)+ torch.pow(G_y,2))
return out
class EXP(nn.Module):
def __init__(self, maxdisp):
super(EXP, self).__init__()
self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
self.SobelFilter = SobelFilter()
def forward(self, im):
% just think "im" to be [1,32,64,128]
for i in range(im.shape[1]):
out1= im[:,i,:,:].unsqueeze(1)
im[:,i,:,:] = self.SobelFilter(out1)
什么会导致问题? 谢谢!
【问题讨论】:
标签: python-3.x pytorch gradient sobel