问题

最近学习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'的更多相关文章

  1. python3 AttributeError: 'NoneType' object has no attribute 'split'

    from wsgiref.simple_server import make_server def RunServer(environ, start_response): start_response ...

  2. AttributeError: 'NoneType' object has no attribute 'split' 报错处理

    报错场景 social_django 组件对原生 django 的支持较好, 但是因为 在此DRF进行的验证为 JWT 方式 和 django 的验证存在区别, 因此需要进行更改自行支持 JWT 方式 ...

  3. 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 ...

  4. 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 ...

  5. 'NoneType' object has no attribute '__getitem__'

    报错 'NoneType' object has no attribute '__getitem__' 你 result 返回的是 None ,所以 result [0] 取不了值

  6. Keras AttributeError 'NoneType' object has no attribute '_inbound_nodes'

    问题说明: 首先呢,报这个错误的代码是这行代码: model = Model(inputs=input, outputs=output) 报错: AttributeError 'NoneType' o ...

  7. OpenStack - keystone 问题 'NoneType' object has no attribute 'service_catalog'

    'NoneType' object has no attribute 'service_catalog' 报错 编辑:/etc/keystone/keystone-paste.ini 在[pipeli ...

  8. pyspark AttributeError: 'NoneType' object has no attribute 'setCallSite'

    pyspark: AttributeError: 'NoneType' object has no attribute 'setCallSite' 我草,是pyspark的bug.解决方法: prin ...

  9. AttributeError: 'NoneType' object has no attribute 'extend'

    Python使用中可能遇到的小问题 AttributeError: 'NoneType' object has no attribute 'extend' 或者AttributeError: 'Non ...

随机推荐

  1. Python实现性能自动化测试的方法【推荐好文】

    1.什么是性能自动化测试? ◆ 性能 △ 系统负载能力 △ 超负荷运行下的稳定性 △ 系统瓶颈 ◆ 自动化测试 △ 使用程序代替手工 △ 提升测试效率 ◆ 性能自动化 △ 使用代码模拟大批量用户 △ ...

  2. 网课神器之obs-studio的安装使用

    obs-studio 首先,下载obs-studio安装文件,然后点击安装. 建议安装完后直接跳过配置,然后进入文件-设置-通用-系统托盘-勾选"总是最小化到系统托盘,而不是任务栏" ...

  3. go : 连接数据库并插入数据

      package main import ( "database/sql" "fmt" "log" "net/http" ...

  4. python怎么自学?今日头条技术大佬的真实经历分享

    大家好,我是武州,27岁,目前在字节跳动担任Python后端工程师一职. (摆拍一下,假装是保安) 在开始今天的文章之前,不知道你们有没有遇到过这样的问题: 大学没学到什么实质技术,毕业后找不到高薪的 ...

  5. 食用Win系统自带的PowerShell登录服务器

    运行powershell输入ssh root@你的服务器ip -p你的端口 切换rm ~/.ssh/known_hosts cmd 运行 ping 你的ip -t一直ping ctrl+c停止 tra ...

  6. css的一些小技巧。修改input样式

    在第一次正式写项目的时候,遇到了几个布局的小技巧.记录一下. 我们常常会遇到图片和文字对齐的一种样式.比如 这样的样式,我们写的时候有时候会出现不对齐的情况.我们有俩种方法 一种就是flex的布局,还 ...

  7. jmeter配置原件之使用CSV Data Set Config参数化

    测试过程中经常需要对发送的请求进行参数化,jmeter提供的CSV Data Set Config 配置元件可以很好的对请求数据进行参数化,下面介绍使用CSV Data Set Config参数化 1 ...

  8. pv绑定pvc

    创建pvapiVersion: v1kind: PersistentVolumemetadata: name: pv003 labels: app: vnc003 namespace: vnc-spa ...

  9. Android集成百度地图

    1. 百度地图api Android定位SDK Android地图SDK Android地图SDK<------

  10. C#winform将dll封装到exe当中

    我们在在winform程序时经常会用到外部dll,正常情况下,我的exe运行文件旁就需要这些dll文件相伴,总感觉不爽~~特别是要把软件给别人的时候,如果DLL比较多或者没有放在同一个地方,那麻烦大了 ...