使用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 ...
随机推荐
- OSCP Learning Notes - WebApp Exploitation(2)
Cross-Site Scripting(XSS) 1. Using the tool - netdiscover to find the IP of target server. netdiscov ...
- JAVA面向对象:三大特征 封装讲解
一.JAVA封装 1.封装的理解 封装是 JAVA 面向对象思想的 一 种特性,也是一种信息隐蔽的技术 2.封装的原则 将类中的某些信息隐藏起来,来防止外部程序直接访问,通过类中的方法实现对隐藏的信息 ...
- vue : 对 vue-class-component 的个人理解
vue-class-component 是 vue 的官方库,作用是用类的方式编写组件. 这种编写方式可以让.vue文件的js域结构更扁平,并使vue组件可以使用继承.混入等高级特性. 简单的示例: ...
- java8中parallelStream提升数倍查询效率是怎样实现的,来看看这篇文章
作者:我恰芙蓉王 原文:https://www.cnblogs.com/-tang/p/13283216.html 业务场景 在很多项目中,都有类似数据汇总的业务场景,查询今日注册会员数,在线会员数, ...
- OpenWrt 编译分割
本文主要参考:http://macbruins.com/2011/05/08/downloading-sources-for-building-openwrt/ OpenWrt系统在buildroot ...
- Flask框架(一):介绍与环境搭建
1.Flask介绍 Flask诞生于2010年,是Armin ronacher(人名)用 Python 语言基于 Werkzeug 工具箱编写的轻量级Web开发框架. Flask 本身相当于一个内核, ...
- time strptime()方法 时间操作
Python time strptime()方法 时间操作 描述 Python time strptime() 函数根据指定的格式把一个时间字符串解析为时间元组. 语法 strptime()方法语 ...
- sed打印包含一个字符串的行到包含另一个字符串的行解答
sed -n '/字符串1/,/字符串2/p' filename 这个命令为什么有时候打印不出来想要的东西,例如:sed -n '/root/,/adm/p' /etc/passwd 我 ...
- ⛅剑指 Offer 11. 旋转数组的最小数字
20207.22 LeetCode 剑指 Offer 11. 旋转数组的最小数字 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个递增排序的数组的一个旋转,输出旋转数组的最小 ...
- 7.1 NOI模拟赛 计数问题 dp
还是可以想出来的题目 不过考场上没有想出来 要 引以为戒. 初看觉得有点不可做 10分给到了爆搜. 考虑第一个特殊情况 B排列为1~m. 容易发现A排列中前m个数字 他们之间不能产生交换 且 第k个数 ...