当前位置:网站首页>pickle.load报错【AttributeError: Can‘t get attribute ‘Vocabulary‘ on <module ‘__main__‘】
pickle.load报错【AttributeError: Can‘t get attribute ‘Vocabulary‘ on <module ‘__main__‘】
2022-07-01 18:44:00 【hei_hei_hei_】
pickle.load报错【AttributeError: Can’t get attribute ‘Vocabulary’ on <module ‘main’】
背景:在看代码的时候想看看一个pkl文件的文件结构和里面的数据,于是就用pickle.load打开,但是出现了
AttributeError: Can't get attribute 'Vocabulary' on <module '__main__'
错误原因:就像我们在保存模型的时候有两种方式,一种是保存整个模型,虽然很大但是使用方便;另一种是只保存了模型的参数,这里加载时就需要先初始化一个模型。这里也是一样的,
msvd_vocab.pkl
在加载时也需要找到其依赖的类,而在报错信息中也说明了,需要导入的类是Vocabulary
。所以需要在项目中找到类Vocabulary,然后在调用pickle.load('.../msvd_vocab.pkl','rb')
的python文件中import该类报错代码
import pickle
with open('.\data\MSVD\msvd_vocab.pkl','rb') as f:
v = pickle.load(f)
# 报错:在demo.py的main中没有‘Vocabulary’模块
AttributeError: Can't get attribute 'Vocabulary' on <module '__main__' from '.../demo.py'>
- 找到‘Vocabulary’类
- 更正
import pickle
from utils.utils import *
with open('.\data\MSVD\msvd_vocab.pkl','rb') as f:
v = pickle.load(f)
完美撒花
边栏推荐
- Digital business cloud: from planning to implementation, how does Minmetals Group quickly build a new pattern of digital development?
- 【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
- Solution: you can ping others, but others can't ping me
- Altair HyperWorks 2022 software installation package and installation tutorial
- Viewing technological changes through Huawei Corps (VI): smart highway
- Shell array
- 市值蒸发740亿,这位大佬转身杀入预制菜
- 微服务大行其道的今天,Service Mesh是怎样一种存在?
- Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
- How to realize the applet in its own app to realize continuous live broadcast
猜你喜欢
一次SQL优化,数据库查询速度提升 60 倍
CDGA|从事通信行业,那你应该考个数据管理证书
DTD建模
水产行业智能供应链管理平台解决方案:支撑企业供应链数字化,提升企业管理效益
PMP是被取消了吗??
Lake shore optimag superconducting magnet system om series
如何使用物联网低代码平台进行个人设置?
The best landing practice of cave state in an Internet ⽹⾦ financial technology enterprise
Supervarimag superconducting magnet system SVM series
Solidity - 合约结构 - 错误(error)- ^0.8.4版本新增
随机推荐
Is PMP cancelled??
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
Solidity - 合约结构 - 错误(error)- ^0.8.4版本新增
C-end dream is difficult to achieve. What does iFLYTEK rely on to support the goal of 1billion users?
Graduation summary
Netease games, radical going to sea
Lumiprobe 自由基分析丨H2DCFDA说明书
M91 fast hall measuring instrument - better measurement in a shorter time
Shell array
How to realize the applet in its own app to realize continuous live broadcast
Golang error handling
Lake Shore—CRX-EM-HF 型低温探针台
[quick application] win7 system cannot run and debug projects using Huawei ide
Transform + ASM data
Chinese and English instructions human soluble advanced glycation end products receptor (sRAGE) ELISA Kit
Digital business cloud: from planning to implementation, how does Minmetals Group quickly build a new pattern of digital development?
有关 M91 快速霍尔测量仪的更多信息
Cdga | if you are engaged in the communication industry, you should get a data management certificate
MySQL常用图形管理工具 | 黑马程序员
Huawei game failed to initialize init with error code 907135000