使用pytorchviz进行模型可视化出现 'NoneType' object has no attribute 'grad_fn'
问题
最近学习pytorch, 原来用kreas重现的模型改为用pytorch实现训练,因为这样给模型的操作更加细致, 对模型的掌控更好。
当我写好一个模型 出现了这个问题
使用pytorchviz进行模型可视化出现r如下错误
raceback (most recent call last):
File "/home/jiwu/Documents/AttRCNN-CNNs/pyt_train.py", line 174, in <module>
g = make_dot(y)
File "/home/jiwu/.virtualenvs/jiwu/lib/python3.6/site-packages/torchviz/dot.py", line 37, in make_dot
output_nodes = (var.grad_fn,) if not isinstance(var, tuple) else tuple(v.grad_fn for v in var)
AttributeError: 'NoneType' object has no attribute 'grad_fn'
找了很久没发现原因在哪里, 翻pytorchviz的issue, 一直google没找到原因,最后才发现是只是在foward 函数 我没有return x。 所以出现了这个问题。
def forward(self, x):
print (x.shape)
x1 = self.conv1(x)
x2 = self.conv2(x)
print (x2.shape)
x3 = self.conv3(x)
x4 = self.conv4(x)
print (x1.shape, x2.shape, x3.shape, x4.shape)
x = torch.cat((x1, x2, x3, x4), dim = 1)
print (x.shape)
x = x.view(x.size(0), -1)
print(x.shape)
x = self.line1(x)
x = self.line2(x)
x = self.line3(x)
return x
使用pytorchviz进行模型可视化出现 'NoneType' object has no attribute 'grad_fn'的更多相关文章
- python3 AttributeError: 'NoneType' object has no attribute 'split'
from wsgiref.simple_server import make_server def RunServer(environ, start_response): start_response ...
- AttributeError: 'NoneType' object has no attribute 'split' 报错处理
报错场景 social_django 组件对原生 django 的支持较好, 但是因为 在此DRF进行的验证为 JWT 方式 和 django 的验证存在区别, 因此需要进行更改自行支持 JWT 方式 ...
- python提示AttributeError: 'NoneType' object has no attribute 'append'【转发】
在写python脚本时遇到AttributeError: 'NoneType' object has no attribute 'append' a=[] b=[1,2,3,4] a = a.appe ...
- python提示AttributeError: 'NoneType' object has no attribute 'append'
在写python脚本时遇到AttributeError: 'NoneType' object has no attribute 'append' a=[] b=[1,2,3,4] a = a.appe ...
- 'NoneType' object has no attribute '__getitem__'
报错 'NoneType' object has no attribute '__getitem__' 你 result 返回的是 None ,所以 result [0] 取不了值
- Keras AttributeError 'NoneType' object has no attribute '_inbound_nodes'
问题说明: 首先呢,报这个错误的代码是这行代码: model = Model(inputs=input, outputs=output) 报错: AttributeError 'NoneType' o ...
- OpenStack - keystone 问题 'NoneType' object has no attribute 'service_catalog'
'NoneType' object has no attribute 'service_catalog' 报错 编辑:/etc/keystone/keystone-paste.ini 在[pipeli ...
- pyspark AttributeError: 'NoneType' object has no attribute 'setCallSite'
pyspark: AttributeError: 'NoneType' object has no attribute 'setCallSite' 我草,是pyspark的bug.解决方法: prin ...
- AttributeError: 'NoneType' object has no attribute 'extend'
Python使用中可能遇到的小问题 AttributeError: 'NoneType' object has no attribute 'extend' 或者AttributeError: 'Non ...
随机推荐
- linux目录结构 主流Linux发行版的目录结构
目录 目录结构 一般教学的目录 CentOS7 openSUSE15.1 Ubuntu18.04 详细说明: /dev目录 /etc目录 /proc目录 /usr目录 /var目录 比较重要的目录 文 ...
- xss小游戏源码分析
配置 下载地址:https://files.cnblogs.com/files/Lmg66/xssgame-master.zip 使用:下载解压,放到www目录下(phpstudy),http服务下都 ...
- react中实现可拖动div
把拖动div功能用react封装成class,在页面直接引入该class即可使用. title为可拖动区域.panel为要实现拖动的容器. 优化了拖动框超出页面范围的情况,也优化了拖动太快时鼠标超出可 ...
- P4158 [SCOI2009]粉刷匠(洛谷)
今天A了个紫(我膨胀了),他看起来像个贪心一样,老师说我写的是dp(dp理解不深的缘故QWQ) 直接放题目描述(我旁边有个家伙让我放链接,我还是说明出处吧(万一出处没有了)我讲的大多数题目都是出自洛谷 ...
- 【Python学习笔记四】获取html内容之后,如何提取信息:使用正则表达式筛选
在能够获取到网页内容之后,发现内容很多,那么下一步要做信息的筛选,就和之前的筛选图片那样 而在python中可以通过正则表达式去筛选自己想要的数据 1.首先分析页面内容信息,确定正则表达式.例如想获取 ...
- MySQL数据库---库的操作
MySQL数据库中,以库,表,记录的形式管理所有的数据,安装MySQL数据库的服务器上可以包含多个库,一个库中包含多张表,一张表中包含多条记录.库对应的是文件系统中文件夹的概念,表对应的是文件的概念, ...
- Shell基本语法---函数
函数 函数定义 function 函数名 () { 指令... return n } 函数调用及参数传递 function func() { echo "第零个参数:" $ #脚本 ...
- C++语法小记---类型转换
类型转换 C++类型转换主要包含两种: 隐式类型转换 小类型向大类型转换 char -> int short ->int int -> unsigned int int -> ...
- 题解 洛谷 P4547 【[THUWC2017]随机二分图】
根据题意,题目中所求的即为所有\(n!\)种完美匹配的各自的出现概率之和再乘上\(2^n\)的值. 发现\(n\)很小,考虑状压\(DP\).设\(f_{S,T}\)为左部图匹配情况为\(S\),右部 ...
- python的pyc文件
编译型语言在程序执行之前,先会通过编译器对程序执行一个编译的过程,把程序转变成机器语言.运行时就不需要翻译,而直接执行就可以了.最典型的例子就是C语言. 解释型语言就没有这个编译的过程,而是在程序运行 ...