justchenhao / STANet

official implementation of the spatial-temporal attention neural network (STANet) for remote sensing image change detection
BSD 2-Clause "Simplified" License
405 stars 110 forks source link

TypeError: Cannot handle this data type: (1, 1, 64), |u #85

Open weizhiliang0520 opened 2 years ago

weizhiliang0520 commented 2 years ago

我首先运行代码中的python demo.py ,然后报标题的错误。 自己的也分段查看涉及的代码模块,打印从模型输出的图像张量:print(pred) = [1,64,256,256,],请问最后代码中的result结果的图像是2562563。我不知道这个demo.py中最后保存的64chanel,如何变成3的?谢谢

zhangtaohua commented 2 years ago

我的结果和你的一样,请问你解决了嘛,怎么解决,谢谢!

weizhiliang0520 commented 2 years ago

我的结果和你的一样,请问你解决了嘛,怎么解决,谢谢

我之前遇到的是在colab上调试的,后面没有用google colab,直接用服务器跑代码就可以了。听说是因为python版本的问题,有说换成python3.8就好了,我在服务器上跑的是python3.6.12,你试试。

weizhiliang0520 commented 2 years ago

我的结果和你的一样,请问你解决了嘛,怎么解决,谢谢!

你看看这个博客: https://blog.csdn.net/qq_41647438/article/details/108344141

zhangtaohua commented 2 years ago

好的, 非常感谢!!

p00uya commented 2 years ago

Hi @justchenhao Is this problem still unresolved?

Amirjomaa commented 2 years ago

hello Is this problem still unresolved?

seigechan commented 2 years ago

我首先运行代码中的python demo.py ,然后报标题的错误。 自己的也分段查看涉及的代码模块,打印从模型输出的图像张量:print(pred) = [1,64,256,256,],请问最后代码中的result结果的图像是256_256_3。我不知道这个demo.py中最后保存的64chanel,如何变成3的?谢谢

你好,我跟你遇到了同样的问题,请问您解决了吗,我也想知道64通道如何变成3通道输出

LVBoA commented 2 years ago

I changed the python version to 3.8.13 but it didn't make sense. The key is the pytorch version. I have tried this:

pip install torch==1.8.1+cu102 torchvision==0.9.1+cu102 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

and it worked. cuda 10.1 could also be used with pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

you can refer to this website https://pytorch.org/get-started/previous-versions/

OmarXu commented 2 years ago

self.dist = F.pairwise_distance(self.feat_A, self.feat_B, keepdim=True) F.pairwise_distance: 在PyTorch1.7中返回值的shape是torch.Size([1,64,64,1]) 在PyTorch1.8中返回值的shape是torch.Size([1,1,64,64])

sunhoro commented 2 years ago

Is anyone able to fix this issue?

angle011 commented 2 years ago

Just Dimension problem. As above comments mentioned, we just need to permute dims. torch 1.10.0 ---> x1,x2 shape[B,H,W,C] --->result shape [B,H,W,1] self.feat_A = self.feat_A.permute(0, 2, 3, 1) self.feat_B = self.feat_B.permute(0, 2, 3, 1) self.dist = F.pairwise_distance(self.feat_A, self.featB, keepdim=True) # 特征距离 self.dist = self.dist.permute(0, 2, 3, 1) torch 1.8.0 ---> x1,x2 shape[B,C,H,W] --->result shape [B,1,H,W]_ self.dist = F.pairwise_distance(self.feat_A, self.feat_B, keepdim=True) # 特征距离

mohamedabdallah1996 commented 2 years ago

Just Dimension problem. As above comments mentioned, we just need to permute dims. torch 1.10.0 ---> x1,x2 shape[B,H,W,C] --->result shape [B,H,W,1] self.feat_A = self.feat_A.permute(0, 2, 3, 1) self.feat_B = self.feat_B.permute(0, 2, 3, 1) self.dist = F.pairwise_distance(self.feat_A, self.featB, keepdim=True) # 特征距离 self.dist = self.dist.permute(0, 2, 3, 1) torch 1.8.0 ---> x1,x2 shape[B,C,H,W] --->result shape [B,1,H,W]_ self.dist = F.pairwise_distance(self.feat_A, self.feat_B, keepdim=True) # 特征距离

Thank you, installing torch 1.8 worked with me

ZhaoRuu commented 1 year ago

I want to know who have an idea to solve this problem.I have the same problem but i don't know how to deal it.

ZhaoRuu commented 1 year ago

Just Dimension problem. As above comments mentioned, we just need to permute dims. torch 1.10.0 ---> x1,x2 shape[B,H,W,C] --->result shape [B,H,W,1] self.feat_A = self.feat_A.permute(0, 2, 3, 1) self.feat_B = self.feat_B.permute(0, 2, 3, 1) self.dist = F.pairwise_distance(self.feat_A, self.featB, keepdim=True) # 特征距离 self.dist = self.dist.permute(0, 2, 3, 1) torch 1.8.0 ---> x1,x2 shape[B,C,H,W] --->result shape [B,1,H,W]_ self.dist = F.pairwise_distance(self.feat_A, self.feat_B, keepdim=True) # 特征距离 不好意思想再请教一下,还是没太懂怎么修改