使用C3D的resume功能时,报错RuntimeError: expected device cpu but got device cuda:0
报错位置在optimizer.step()。原因是optimizer加载参数时,tensor默认在CPU上,故需将所有的tensor都放到GPU上。

解决方案:

在这一段代码后面加入
for state in optimizer.state.values():
for k, v in state.items():
if torch.is_tensor(v):
state[k] = v.cuda()
最终代码为

cuda out of memory错误
原因是显卡内存不够,解决方案是修改batch-size,改小一点,batch-size改成8一般合适。