栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Object arrays cannot be loaded when allow

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Object arrays cannot be loaded when allow

1. 报错问题:(来自《Python 深度学习》P190页代码) 在Vscode运行下述代码的时候,报错:Object arrays cannot be loaded when allow_pickle=False
from keras.datasets import imdb
from keras.preprocessing import sequence

max_features = 10000  
# Number of words to consider as features(作为特征的单词个数)
max_len = 500  
# cut texts after this number of words (among top max_features most common words)
# 在这么多单词之后截断文本(这些单词都属于前 max_features 个最常见的单词)
print('Loading data...')
(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=max_features)
print(len(x_train), 'train sequences')
print(len(x_test), 'test sequences')

print('Pad sequences (samples x time)')
x_train = sequence.pad_sequences(x_train, maxlen=max_len)
x_test = sequence.pad_sequences(x_test, maxlen=max_len)
print('x_train shape:', x_train.shape)
print('x_test shape:', x_test.shape)
2. 解决方法  

参考链接:Object arrays cannot be loaded when allow_pickle=False

① 首先找到该运行环境envs下的目录→Lib→site-packages→keras→datasets→imdb.py

比如说我的这个python37运行环境,最后就在:

D:AnacondaDonenvspython37Libsite-packageskerasdatasetsimdb.py

②打开imdb.py,找到with np.load这行,将np.load(path)改成np.load(path,allow_pickle=True),保存!

③ 重启Jupyter内核!一定要重启!然后重新运行该段代码!就没问题了! 

 最后运行的结果:

Using TensorFlow backend.
Loading data...
25000 train sequences
25000 test sequences
Pad sequences (samples x time)
x_train shape: (25000, 500)
x_test shape: (25000, 500)

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/530303.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号