How to fix 'Object arrays cannot be loaded when allow_pickle=False' for imdb.load_data() function?

后端 未结 20 2063
花落未央
花落未央 2020-12-04 11:28

I\'m trying to implement the binary classification example using the IMDb dataset in Google Colab. I have implemented this model before. But when I tried to

相关标签:
20条回答
  • 2020-12-04 11:47

    none of the above listed solutions worked for me: i run anaconda with python 3.7.3. What worked for me was

    • run "conda install numpy==1.16.1" from Anaconda powershell

    • close and reopen the notebook

    0 讨论(0)
  • 2020-12-04 11:49

    I think the answer from cheez (https://stackoverflow.com/users/122933/cheez) is the easiest and most effective one. I'd elaborate a little bit over it so it would not modify a numpy function for the whole session period.

    My suggestion is below. I´m using it to download the reuters dataset from keras which is showing the same kind of error:

    old = np.load
    np.load = lambda *a,**k: old(*a,**k,allow_pickle=True)
    
    from keras.datasets import reuters
    (train_data, train_labels), (test_data, test_labels) = reuters.load_data(num_words=10000)
    
    np.load = old
    del(old)
    
    0 讨论(0)
  • 2020-12-04 11:49

    Yes, installing previous a version of numpy solved the problem.

    For those who uses PyCharm IDE:

    in my IDE (Pycharm), File->Settings->Project Interpreter: I found my numpy to be 1.16.3, so I revert back to 1.16.1. Click + and type numpy in the search, tick "specify version" : 1.16.1 and choose--> install package.

    0 讨论(0)
  • 2020-12-04 11:49

    The easiest way is to change imdb.py setting allow_pickle=True to np.load at the line where imdb.py throws error.

    0 讨论(0)
  • 2020-12-04 11:50

    on jupyter notebook using

    np_load_old = np.load
    
    # modify the default parameters of np.load
    np.load = lambda *a,**k: np_load_old(*a, allow_pickle=True, **k)
    

    worked fine, but the problem appears when you use this method in spyder(you have to restart the kernel every time or you will get an error like:

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

    I solved this issue using the solution here:

    0 讨论(0)
  • 2020-12-04 11:50

    What I have found is that TensorFlow 2.0 (I am using 2.0.0-alpha0) is not compatible with the latest version of Numpy i.e. v1.17.0 (and possibly v1.16.5+). As soon as TF2 is imported, it throws a huge list of FutureWarning, that looks something like this:

    FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
      _np_qint8 = np.dtype([("qint8", np.int8, 1)])
    /anaconda3/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
      _np_qint8 = np.dtype([("qint8", np.int8, 1)])
    /anaconda3/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
      _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
    /anaconda3/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
    

    This also resulted in the allow_pickle error when tried to load imdb dataset from keras

    I tried to use the following solution which worked just fine, but I had to do it every single project where I was importing TF2 or tf.keras.

    np.load = lambda *a,**k: np_load_old(*a, allow_pickle=True, **k)
    

    The easiest solution I found was to either install numpy 1.16.1 globally, or use compatible versions of tensorflow and numpy in a virtual environment.

    My goal with this answer is to point out that its not just a problem with imdb.load_data, but a larger problem vaused by incompatibility of TF2 and Numpy versions and may result in many other hidden bugs or issues.

    0 讨论(0)
提交回复
热议问题