标签:TSN main tensor RuntimeError py 报错 forward 源代码 pytorch1.8
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
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。