CRST: Confidence Regularized Self-Training 代码报错整理

任务描述:

跑一个对比实验,将原文中的数据集换成自己的数据集。dataloader也换成自己的。


错误1

model.to(device)
_has_compatible_shallow_copy_type(): argument 'from' (position 2) must be Tensor, not NoneType

解决方案:

model.cuda(device)

错误2

images, labels, _, _ = batch
images = images.to(device)
'str' object has no attribute 'to'

原因分析:

输出images还是images,没有装载batch里面的内容。以为是命名的原因,因为batch中不是images而是img,修改为img, labels, _, _ = batch依然不对。后又尝试了解压batch的操作发现并不是这个问题。后来看了一下原dataloade发现人家的batch是一个字典……

解决方案:

img = batch['img']

错误3

Given groups=1, weight of size [64, 3, 7, 7], expected input[1, 1, 288, 288] to have 3 channels, but got 1 channels instead

原因分析:

原模型处理的是彩色的自然图像,是3通道。但要处理的数据集是灰度图像,是1通道。所以比较简单的解决方法是把原来的单通道cat三份,成为三通道。

解决方案:

img = torch.cat((img, img, img),1)

错误4

1 only batches of spatial targets supported (3D tensors) but got targets of size: : [1, 12, 288, 288]

原因分析:

未更改代码中针对原数据集(GTA5)的参数。应在默认参数中修改为自己数据集的size。(NUM_CLASSES = 4:前景1,target domain3)

解决方案:

NUM_CLASSES = 4
INPUT_SIZE = '288,288'

错误5

module 'torchvision.transforms.functional' has no attribute 'interpolate'

解决方案:参考博客

image = F.interpolate(
改为
upsampleimage = nn.Upsample(
image = upsampleimage(image)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值