pytorch1.8复现TSN踩坑记录(如何在源代码中进行过更改)
作者:互联网
1 运行main.py时,
1.1 报错RuntimeError: Legacy autograd function with non-static forward method is deprecated.
新版pytorch中的前向传播forward变成静态的了
(1)basic_opt.py中最下面的forward中加入.forward(input)
(2)models.py中的base——model处加入.forward
1.2 报错RuntimeError: view size is not compatible with input tensor’s size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(…) instead.
修改main.py下的,将view替换成reshape
1.3 报错IndexError: invalid index of a 0-dim tensor. Use tensor.item()
in Python or tensor.item<T>()
in C++ to convert a 0-dim tensor to a number
将main.py中的loss.data[0]改为loss.data,同理更改prec1和prec5
1.4 报错RuntimeError: invalid argument 5: k not in range for dimension at /pytorch/aten/src/THC/generic/THCTensorTopK.cu:24
将main.py中topk的5修改为3
2 运行test_models.py时
2.1 net = torch.nn.DataParallel(net.cuda(devices[0]), device_ids=devices)报错AssertionError: Invalid device id
指定训练显卡
2.2RuntimeError: CUDA out of memory. Tried to allocate 192.00 MiB (GPU 0; 9.78 GiB total capacity; 7.50 GiB already allocated; 190.38 MiB free; 7.72 GiB reserved in total by PyTorch)
根据报错位置
加入with torch.no_grad():
标签:TSN,main,tensor,RuntimeError,py,报错,forward,源代码,pytorch1.8 来源: https://blog.csdn.net/weixin_44246079/article/details/115161214