记录在mmsegmentation框架里写代码跑实验时出现的bug

1. ValueError: size shape must match input shape. Input is 2D, size is 1

这种是尺寸没对上,用input.shape和targe.shape把尺寸弄清楚,我缺的是通道那一维,用torch.unsqueeze(input, 1)就行了

2. KeyError: ‘layers.0.blocks.0.attn.relative_position_bias_table’

这通常是别人的权重拿到自己的网络没转换的原因

3. KeyError: ‘data_time’

mmseg在保存权重时出现的问题
mmseg/apis/train.py里,加上priority='LOW'
同时,如果想保存最佳结果,可以加上save_best='mIoU',或其他指标

runner.register_hook(eval_hook(val_dataloader, **eval_cfg), priority='LOW')
runner.register_hook(eval_hook(val_dataloader,save_best='mIoU', **eval_cfg), priority='LOW')

mmd_loss=True,

4. RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn

加的loss报了错
loss = loss.requires_grad_()
loss.backward()
突然想起来计算图,有无计算图的

5. AttributeError: ‘list’ object has no attribute ‘size’

我利用feat = self.get_model().extract_feat(img)来获取特征
但是该特征是不能直接拿来计算的
需要通过feat = [f.detach() for f in feat]这样遍历获取特征,再用feat[-1]来计算

6. RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 ‘target’ in call to _thnn_nll_loss2d_forward

将标签(lable或target)加上.long(),我还要加权的权重,把权重也加上.long()

7.ValueError: Expected input batch_size (2) to match target batch_size (1).

把每个数据的维度打印出来,看了在代码里该怎么转变~

你可能感兴趣的:(实验,bug,深度学习,pytorch,mmsegmentation)