WangFeng18 / Swin-Transformer

Implementation of Swin Transformer with Pytorch
106 stars 17 forks source link

IndexError: tensors used as indices must be long, byte or bool tensors #8

Open intelljames opened 3 years ago

intelljames commented 3 years ago
in relative_embedding(self) 91 relation = cord[:, None, :] - cord[None, :, :] + self.window_size -1 92 # negative is allowed ---> 93 return self.relative_position_params[:, relation[:,:,0], relation[:,:,1]] 94 95 class Block(nn.Module): IndexError: tensors used as indices must be long, byte or bool tensors ----------------------------------------------------------------------------------- directly run the SwinTransformer.py
gaiyi7788 commented 2 years ago

I get the same error

TangYong1975 commented 2 years ago

90 cord = torch.tensor(np.array([[i, j] for i in range(self.window_size) for j in range(self.window_size)])) --->

TangYong1975 commented 2 years ago

90 cord = torch.tensor(np.array([[i, j] for i in range(self.window_size) for j in range(self.window_size)])).type(torch.long)