【问题标题】:ValueError: Object arrays cannot be loaded when allow_pickle=False for IMDB data for KerasValueError:对于 Keras 的 IMDB 数据,当 allow_pickle=False 时无法加载对象数组
【发布时间】:2020-05-26 10:50:33
【问题描述】:

首先我使用的是 Tensorflow 1.15 和 Keras 2.2.4。

我在 Jupyter Notebook 中运行了以下代码:

from keras.datasets import imdb
from keras import preprocessing

max_features = 10000                                                     
maxlen = 20                                                              

(x_train, y_train), (x_test, y_test) = imdb.load_data(
    num_words=max_features)                                              

x_train = preprocessing.sequence.pad_sequences(x_train, maxlen=maxlen)    
x_test = preprocessing.sequence.pad_sequences(x_test, maxlen=maxlen)

它给了我这个错误:

Downloading data from https://s3.amazonaws.com/text-datasets/imdb.npz
17465344/17464789 [==============================] - 8s 0us/step
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-609d113f6ed2> in <module>
      6 
      7 (x_train, y_train), (x_test, y_test) = imdb.load_data(
----> 8     num_words=max_features)                                              
      9 
     10 x_train = preprocessing.sequence.pad_sequences(x_train, maxlen=maxlen)

~\.conda\envs\tensorflow_env\lib\site-packages\keras\datasets\imdb.py in load_data(path, num_words, skip_top, maxlen, seed, start_char, oov_char, index_from, **kwargs)
     57                     file_hash='599dadb1135973df5b59232a0e9a887c')
     58     with np.load(path) as f:
---> 59         x_train, labels_train = f['x_train'], f['y_train']
     60         x_test, labels_test = f['x_test'], f['y_test']
     61 

~\.conda\envs\tensorflow_env\lib\site-packages\numpy\lib\npyio.py in __getitem__(self, key)
    260                 return format.read_array(bytes,
    261                                          allow_pickle=self.allow_pickle,
--> 262                                          pickle_kwargs=self.pickle_kwargs)
    263             else:
    264                 return self.zip.read(key)

~\.conda\envs\tensorflow_env\lib\site-packages\numpy\lib\format.py in read_array(fp, allow_pickle, pickle_kwargs)
    720         # The array contained Python objects. We need to unpickle the data.
    721         if not allow_pickle:
--> 722             raise ValueError("Object arrays cannot be loaded when "
    723                              "allow_pickle=False")
    724         if pickle_kwargs is None:

ValueError: Object arrays cannot be loaded when allow_pickle=False

它有什么问题?我从“使用 Python 进行深度学习”一书中获取了这段代码。

谢谢

【问题讨论】:

    标签: python-3.x keras dataset loading imdb


    【解决方案1】:

    当 numpy 加载大量数据时,需要将 allow_pickle 设置为 True。您应该手动更改它。

    np.load("place of bumpy file.npy", allow_pickle=True)
    

    我认为 imdb 内部有 numpy 负载。

    【讨论】:

      猜你喜欢
      • 2020-05-12
      • 2019-09-17
      • 2022-01-24
      • 2019-09-13
      • 2019-12-19
      • 2021-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多