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

后端 未结 20 2064
花落未央
花落未央 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:51

    I don't usually post to these things but this was super annoying. The confusion comes from the fact that some of the Keras imdb.py files have already updated:

    with np.load(path) as f:
    

    to the version with allow_pickle=True. Make sure check the imdb.py file to see if this change was already implemented. If it has been adjusted, the following works fine:

    from keras.datasets import imdb
    (train_text, train_labels), (test_text, test_labels) = imdb.load_data(num_words=10000)
    
    0 讨论(0)
  • 2020-12-04 11:52

    I just used allow_pickle = True as an argument to np.load() and it worked for me.

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

    find the path to imdb.py then just add the flag to np.load(path,...flag...)

        def load_data(.......):
        .......................................
        .......................................
        - with np.load(path) as f:
        + with np.load(path,allow_pickle=True) as f:
    
    0 讨论(0)
  • 2020-12-04 11:53

    The error also can occur if you try to save a python list of numpy arrays with np.save and load with np.load. I am only saying it for the sake of googler's to check out that this is not the issue. Also using allow_pickle=True fixed the issue if a list is indeed what you meant to save and load.

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

    Use this

     from tensorflow.keras.datasets import imdb
    

    instead of this

     from keras.datasets import imdb
    
    0 讨论(0)
  • 2020-12-04 11:57

    Tensorflow has a fix in tf-nightly version.

    !pip install tf-nightly
    

    The current version is '2.0.0-dev20190511'.

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