shicaiwei123 / TGRS-MSHNet

Code for MSH-Net: Modality-Shared Hallucination with Joint Adaptation Distillation for Remote Sensing Image Classification Using Missing Modalities
MIT License
4 stars 0 forks source link

RuntimeError: expand(torch.cuda.FloatTensor{[1, 64, 64, 4, 4]}, size=[64, 64, 64]): the number of sizes provided (3) must be greater or equal to the number of dimensions in the tensor (5) #4

Open yingzhige00 opened 9 months ago

yingzhige00 commented 9 months ago

大佬,我在运行huston2013_T_HL_L.sh的时候,可以运行一次,在运行第二次的时候开始计算cls_loss了,然后就有了如下报错: Traceback (most recent call last): File "huston2013_transfer.py", line 101, in <module> deeppix_main(args=args) File "huston2013_transfer.py", line 97, in deeppix_main args=args) File "../lib/model_develop.py", line 2680, in train_knowledge_distill_jda kd_loss = criterionKD(feature_student, feature_teacher.detach(), x_whole_student, x_whole_teacher.detach()) File "/opt/conda/envs/MSHNet/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl return forward_call(*input, **kwargs) File "../loss/kd/jda.py", line 52, in forward D1 = self.mmd_loss(feature_student, feature_teacher) File "/opt/conda/envs/MSHNet/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl return forward_call(*input, **kwargs) File "../loss/kd/jda.py", line 23, in forward total0 = total.unsqueeze(0).expand(int(total.size(0)), int(total.size(0)), int(total.size(1))) RuntimeError: expand(torch.cuda.FloatTensor{[1, 64, 64, 4, 4]}, size=[64, 64, 64]): the number of sizes provided (3) must be greater or equal to the number of dimensions in the tensor (5) 貌似是说张量的尺寸不对,有什么办法解决吗?还是说我哪里出了错。 我看你原来引入的老师模型是‘fusion_hsi_lidar.pth’但是上一个训练训练出的是fusion_11__hsi_lidar_version_0.pth,我修改了引入,不知道这个引入是否正确?

yingzhige00 commented 9 months ago

抱歉刚刚看错了,应该是KD_loss出的错,应该是在JDA部分有问题

yingzhige00 commented 9 months ago

大哥,我就想知道你想把jda.py里的MMD_loss的total0和total1展开成什么样子,来让他们能够计算L2距离。

shicaiwei123 commented 9 months ago

我已经更新了代码,现在可以跑了,差异在jda.py的53行,忽略了shape的转换

yingzhige00 commented 9 months ago

好的,谢谢