Serge-weihao / CCNet-Pure-Pytorch

Criss-Cross Attention (2d&3d) for Semantic Segmentation in pure Pytorch with a faster and more precise implementation.
MIT License
183 stars 21 forks source link

about_CC.py #6

Open baba1587 opened 3 years ago

baba1587 commented 3 years ago

hello i met this problem and please u to see . 1 x = torch.randn(2,64,5,6) 2 ----> 3 y = model(x)

1 frames /usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in call(self, *input, kwargs) 475 result = self._slow_forward(*input, *kwargs) 476 else: --> 477 result = self.forward(input, kwargs) 478 for hook in self._forward_hooks.values(): 479 hook_result = hook(self, input, result)

in forward(self, x) 24 proj_value_H = proj_value.permute(0,3,1,2).contiguous().view(m_batchsize*width,-1,height) 25 proj_value_W = proj_value.permute(0,2,1,3).contiguous().view(m_batchsize*height,-1,width) ---> 26 energy_H = (torch.bmm(proj_query_H, proj_key_H)+self.INF(m_batchsize, height, width)).view(m_batchsize,width,height,height).permute(0,2,1,3) 27 energy_W = torch.bmm(proj_query_W, proj_key_W).view(m_batchsize,height,width,width) 28 concate = self.softmax(torch.cat([energy_H, energy_W], 3)) RuntimeError: Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor for argument #3 'other'
Serge-weihao commented 3 years ago

you can add x = torch.randn(2,64,5,6) -> x = torch.randn(2,64,5,6).cuda() and model = model.cuda()

Serge-weihao commented 3 years ago

or you can remove .cuda() in def INF(B,H,W): return -torch.diag(torch.tensor(float("inf")).cuda().repeat(H),0).unsqueeze(0).repeat(B*W,1,1)

baba1587 commented 3 years ago

OK it works thank you