如何修复imdb.load_data()函数中的'Object arrays cannot be loaded when allow_pickle=False'错误?

5 浏览
0 Comments

如何修复imdb.load_data()函数中的'Object arrays cannot be loaded when allow_pickle=False'错误?

我正在尝试在Google Colab中使用IMDb数据集实现二分类示例。我之前已经实现过这个模型。但是当我在几天后再次尝试时,load_data()函数返回了一个"value error: 'Object arrays cannot be loaded when allow_pickle=False'"。

我已经尝试解决这个问题,参考了一个类似问题的现有答案:如何修复'sketch_rnn算法中的“Object arrays cannot be loaded when allow_pickle=False”错误

但是事实证明,只添加一个allow_pickle参数是不够的。

我的代码:

from keras.datasets import imdb
(train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000)

错误信息:

ValueError                                Traceback (most recent call last)
 in ()
      1 from keras.datasets import imdb
----> 2 (train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000)
2 frames
/usr/local/lib/python3.6/dist-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 
/usr/local/lib/python3.6/dist-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)
/usr/local/lib/python3.6/dist-packages/numpy/lib/format.py in read_array(fp, allow_pickle, pickle_kwargs)
    690         # The array contained Python objects. We need to unpickle the data.
    691         if not allow_pickle:
--> 692             raise ValueError("Object arrays cannot be loaded when "
    693                              "allow_pickle=False")
    694         if pickle_kwargs is None:
ValueError: Object arrays cannot be loaded when allow_pickle=False

0