问题1:电脑无GPU出现
AssertionError: Torch not compiled with CUDA enabled
解决:
在程序最开始的地方加上:
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
代码其余地方出现.cuda()的地方改成.to(device)就可以在无gpu的环境中运行了。
问题2:
Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [64, 1024]], which is output 0 of ReluBack ward0, is at version 1; expected version 0 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detec
t_anomaly(True).
解决:
1、
x = F.dropout(x, inplace=False)#改true为flase
在inplace为True的时候,将其改为Flase,如drop(),还有Relu()函数
2、tensor的运算不能用inplace的操作。
在python中, inplace operation 可以是一些 += 或 *= 导致的。比如 x += y,需要改成 x = x +y
比如将
Output[t] += self.Conv1(Output[b])
改为
Output[t] = Output[t] + self.Conv1(Output[b])