pytorch报错:AttributeError: 'module' object has no attribute '_rebuild_tensor_v2'
转载自:
https://blog.csdn.net/qq_24305433/article/details/80844548
由于训练模型时使用的是新版本的pytorch,而加载时使用的是旧版本的pytorch
解决方法:
1、既然是pytorch版本较老,那最简单的解决方法当然是简单的升级一下pytorch就ok了。
2、国外的大神给了另一种解决方法,就是在程序开头添加下面的代码,即可以使老版本pytorch兼容新版本pytorch,参考链接https://discuss.pytorch.org/t/question-about-rebuild-tensor-v2/14560
import torch._utils
try:
torch._utils._rebuild_tensor_v2
except AttributeError:
def _rebuild_tensor_v2(storage, storage_offset, size, stride, requires_grad, backward_hooks):
tensor = torch._utils._rebuild_tensor(storage, storage_offset, size, stride)
tensor.requires_grad = requires_grad
tensor._backward_hooks = backward_hooks
return tensor
torch._utils._rebuild_tensor_v2 = _rebuild_tensor_v2
pytorch报错:AttributeError: 'module' object has no attribute '_rebuild_tensor_v2'的更多相关文章
- python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'
python中的文件都会生成pyc文件,包括模块也是这样,所以调用模块的时候,实际上会调用模块.pyc文件:在这个前提下,如果将文件名命名成跟模块名一样,在同一目录下就会生成一个跟模块名一样的pyc文 ...
- 运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"
最近学习pytest被此问题困扰,敲脑壳,实在是不该.百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢. 报错信息如下: 网上解决方法是这样的 ...
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
- dnspython模块报错 AttributeError: 'CNAME' object has no attribute 'address'
有时候用到这个模块的时候会报错 AttributeError: 'CNAME' object has no attribute 'address' 如下所示 [root@ansible ch01]# ...
- pytorch版本问题:AttributeError: 'module' object has no attribute '_rebuild_tensor_v2'
用pytorch加载训练好的模型的时候遇到了如下的问题: AttributeError: 'module' object has no attribute '_rebuild_tensor_v2' 到 ...
- py+selenium 明明定位不到元素,但却不报错或是报错AttributeError: 'list' object has no attribute 'click'【已解决】
问题:定位不到元素,但却不报错或者出现报错AttributeError: 'list' object has no attribute 'click' 如图 或者 解决方法: 将”driver ...
- 使用jieba导入引用方法时,报错AttributeError: module 'jieba' has no attribute 'cut'
一.问题描述 import jieba导入后,使用jieba.cut()方法时报错AttributeError: module 'jieba' has no attribute 'cut' 二.问题分 ...
- python中引入包的时候报错AttributeError: module 'sys' has no attribute 'setdefaultencoding'解决方法?
python中引入包的时候报错:import unittestimport smtplibimport timeimport osimport sysimp.reload(sys)sys.setdef ...
- 关于flask登录视图报错AttributeError: '_AppCtxGlobals' object has no attribute 'user'
在一个小程序中写了一个登录视图函数,代码如下: @app.route('/login',methods = ['GET','POST']) @oid.loginhandler def login(): ...
- [已解决]pycharm报错:AttributeError: module 'pip' has no attribute 'main'
> 更新pip后,pycharm更新模块报错,经过一番查找,现提供两种解决办法. 报错片段信息如下: AttributeError: module 'pip' has no attribute ...
随机推荐
- android studio: 9:57 Unsupported Modules Detected: Compilation is not supported for following modules: map, app, ota, MediaEditor, rcLcmSercive, DroneSDK, qrcodelibrary, rcService, speechService. Unfo
Android studio Error “Unsupported Modules Detected: Compilation is not supported for following modul ...
- osg 场景漫游
#ifdef _WIN32 #include <Windows.h> #endif // _WIN32 #include <osg/Group> #include <os ...
- webpack概述——资源、样式、图片的打包工具
官方地址:https://www.webpackjs.com/ Concepts At its core, webpack is a static module bundler for modern ...
- web手工项目04-测试报告的核心内容-HTTP请求和响应-fiddler工具进行抓包
回顾 登录功能测试(需求分析(输入分析,处理分析,输出分析),数据构造,编写用例) 测试点设计思路--扩展(相关业务,特殊角度-分支,异常,逆向) 流程图元素与画法(开始/结束,路径,数据,判定,步骤 ...
- python使用datetime模块计算各种时间间隔的方法
python使用datetime模块计算各种时间间隔的方法 本文实例讲述了python使用datetime模块计算各种时间间隔的方法.分享给大家供大家参考.具体分析如下: python中通过datet ...
- (二十)sql基础
sql基础 --单表查询 select * from student; select * from score; --投影查询 select * from student; --条件查询 select ...
- easyui datagrid设置一开始不加载数据
解决办法就是:一开始的url属性设置为空,例如: <table id="dg" title="用户管理" class="easyui-datag ...
- Centos7之pacemaker高可用安装配置详解
申明: centos7的pacemaker与6使用的方法不一致,即使用centos6.x的方法在centos7.x上面配置pacemaker不能成功. 因此openstack 上面的centos7.1 ...
- 高级UI-DrawerLayout侧滑
侧滑的方案有很多种,早期的开源SliddingMenu,以及后来的DrawerLayout以及NavigationView等都可实现侧滑效果,这里介绍的是DrawerLayout,下一节将介绍Navi ...
- CentOS 7 安装wordpress
1.安装php 要安装php 7,必须使用下面的命令在Centos7系统上安装并启用epel和remi存储库. 输入一下代码, yum install http://rpms.remirepo.net ...