CDLab icon indicating copy to clipboard operation
CDLab copied to clipboard

尊敬的作者,你好! 附载的STANet模型为什么会出现pred和tar尺寸不匹配问题,总是相差64倍。

Open HZWXW371 opened this issue 1 year ago • 6 comments

报错信息如下: Traceback (most recent call last): File "/first_disk/hongzheng/CDLab-master/src/train.py", line 59, in main trainer.run() File "/first_disk/hongzheng/CDLab-master/src/core/trainer.py", line 75, in run self.train() File "/first_disk/hongzheng/CDLab-master/src/core/trainer.py", line 96, in train acc = self.evaluate_epoch(epoch=epoch) File "/first_disk/hongzheng/CDLab-master/src/impl/trainers/cd_trainer.py", line 185, in evaluate_epoch loss = self.criterion(pred, tar) File "/home/ly/miniconda3/envs/hz/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl return self._call_impl(args, **kwargs) File "/home/ly/miniconda3/envs/hz/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl return forward_call(args, **kwargs) File "/first_disk/hongzheng/CDLab-master/src/utils/losses.py", line 100, in forward loss = 0.5torch.sum(utartorch.pow(pred, 2)) / n_u +
RuntimeError: The size of tensor a (4) must match the size of tensor b (64) at non-singleton dimension 1

或者

Traceback (most recent call last): File "/first_disk/hongzheng/STANet/./train.py", line 169, in miou_current = val(opt, model) File "/first_disk/hongzheng/STANet/./train.py", line 86, in val score = model.test(val=True) # run inference File "/first_disk/hongzheng/STANet/models/CDFA_model.py", line 79, in test metrics.update(self.L.detach().cpu().numpy(), pred.detach().cpu().numpy()) File "/first_disk/hongzheng/STANet/util/metrics.py", line 121, in update self.confusion_matrix += self.__fast_hist(lt.flatten(), lp.flatten()) File "/first_disk/hongzheng/STANet/util/metrics.py", line 108, in __fast_hist hist = np.bincount(self.num_classes * label_gt[mask].astype(int) + label_pred[mask], IndexError: boolean index did not match indexed array along dimension 0; dimension is 4194304 but corresponding boolean dimension is 65536

HZWXW371 avatar Jun 19 '24 09:06 HZWXW371

请给出复现这个错误的方法,以便我帮忙排查问题~

Bobholamovic avatar Jun 19 '24 11:06 Bobholamovic

这是我的执行命令 python train.py train --exp_config ../configs/whu/config_whu_stanet.yaml

HZWXW371 avatar Jun 19 '24 11:06 HZWXW371

如果我记得没错的话,对于WHU数据集,需要使用脚本先预处理数据:

https://github.com/Bobholamovic/CDLab/tree/master/scripts

Bobholamovic avatar Jun 19 '24 15:06 Bobholamovic

我已经用这个脚本处理过了的,数据集其他都可以跑就是STANet这个方法不行

HZWXW371 avatar Jun 20 '24 01:06 HZWXW371

这边初步已经调试完毕啦,是因为pytorch版本的问题,安装1.6.0就可以了,辛苦你了

HZWXW371 avatar Jun 20 '24 02:06 HZWXW371

不客气,也没帮上忙~很高兴你的问题能得到解决

Bobholamovic avatar Jun 20 '24 04:06 Bobholamovic