ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

pytorch1.8复现TSN踩坑记录(如何在源代码中进行过更改)

2021-03-24 12:02:10  阅读:1198  来源: 互联网

标签:TSN main tensor RuntimeError py 报错 forward 源代码 pytorch1.8


1 运行main.py时,

1.1 报错RuntimeError: Legacy autograd function with non-static forward method is deprecated.

参考1,针对TSN网络
参考2
参考3

新版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. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有