1、raise notImplementedError
不是什么大錯,先檢查一下代碼的縮進是否正確。
2、RuntimeError: Tensor: invalid storage offset at /pytorch/aten/src/THC/generic/THCTensor.c:759
哎,這個錯就很氣人了,在pytorch 中 執行loss.backward()出現的問題,正如https://discuss.pytorch.org/t/error-when-using-spectral-norm-on-multiple-gpus/25072 所說的,是reshape函數導致的問題,把它改成view函數就可以了。
3、訓練和驗證的配置完全一樣,而訓練的時候正常,測試的時候報如下錯誤:
RuntimeError: cuda runtime error (2) : out of memory at /data/users/soumith/miniconda2/conda-bld/pytorch-0.1.9_1487346124464/work/torch/lib/THC/generic/THCStorage.cu:66
這是因為驗證的時候,沒有設置變量屬性為 volatile ,在pytorch 0.4.0之后,pytorch取消了volatile這個變量,改為如下寫法:
x = Variable(torch.Tensor([34, 54]), requires_grad=True)
with torch.no_grad():
y = x * 2
4、 Input type (CUDAFloatTensor) and weight type (CPUFloatTensor) should be the same
最初遇到這個問題的時候,網上大家的回答都是參數是在GPU ,而模型沒有放在GPU 上面,添加model=model.cuda()語句就能解決。我這個錯誤出現的比較奇怪,是運行到網絡中間才出現這個錯誤。原因是我的網絡結構中存在下面的定義:
layer=[]
for dilation in dilations:
layer.append(ResidualBlock(channels,dilation))
self.transformlayers=layer
其中 self.transformlayers=layer這句話出了問題,這個定義的網絡,出來的結果如下

雖然這樣定義在cpu上計算沒有問題,但是如果要在GPU上面運算的話,在model=model.cuda()的作用下,網絡其他部分都被部署到gpu上面,而 transformlayers 里面的結構卻還在cpu上面。正確的定義是:
self.transformlayers=nn.Sequential(*layer)
這樣輸出網絡可以看到
transformlayers里面是有結構信息的,model=model.cuda(),就能將整個網絡部署到GPU上面去了。
