在Keras中加载数据集时如何解决错误? [英] How to fix error when load dataset in Keras?

查看:432
本文介绍了在Keras中加载数据集时如何解决错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我加载路透社"数据集时,出现错误

When I'm load 'reuters' dataset , I get a Error

我尝试使用一些:

np_load_old = np.load
np.load = lambda *a,**k: np_load_old(*a, allow_pickle=True, **k)
(train_data, train_labels), (test_data, test_labels) = reuters.load_data(num_words=10000)
np.load = np_load_old

最初是:

from keras.datasets import reuters
import numpy as np
(train_data, train_labels), (test_data, test_labels) = reuters.load_data(num_words=10000)

TypeError:()为关键字参数获取了多个值 'allow_pickle'

TypeError: () got multiple values for keyword argument 'allow_pickle'

完整追溯:

    TypeError                                 Traceback (most recent call last)
    <ipython-input-11-8669b9ae66ea> in <module>()
          1 from keras.datasets import reuters
    ----> 2 (train_data, train_labels), (test_data, test_labels) = reuters.load_data(num_words=10000)
          3 
          4 

    2 frames
    <ipython-input-2-8333ca7e6c7f> in <lambda>(*a, **k)
          4 
          5 np_load_old = np.load
    ----> 6 np.load = lambda *a,**k: np_load_old(*a, allow_pickle=True, **k)
          7 (train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000)
     >     8 np.load = np_load_old

TypeError: <lambda>() got multiple values for keyword argument 'allow_pickle'

推荐答案

所以我花了一些时间才弄清楚,但是我终于解决了它. 因为我们的问题是np.load的默认值,所以我们只需要更改它们(至少暂时).

so it took me a while to figure this out, but I finally fixed it. since our problem is the default values of np.load then we simply need to change them(temporarily at least).

因此在使用numpy之前,您只需将以下行添加到代码中即可:

so before using numpy you can simply add this line to your code:

np.load.__defaults__=(None, True, True, 'ASCII')

这会将allow_pickle更改为True.

然后在完成工作后将其修复

then when you're done with what you were doing fix it back

np.load.__defaults__=(None, False, True, 'ASCII')

干杯!

这篇关于在Keras中加载数据集时如何解决错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆