任务描述:
跑一个对比实验,将原文中的数据集换成自己的数据集。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)