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

后端 未结 20 2062
花落未央
花落未央 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 12:00

    Here's a trick to force imdb.load_data to allow pickle by, in your notebook, replacing this line:

    (train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000)
    

    by this:

    import numpy as np
    # save np.load
    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)
    
    # call load_data with allow_pickle implicitly set to true
    (train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000)
    
    # restore np.load for future normal usage
    np.load = np_load_old
    
    0 讨论(0)
  • 2020-12-04 12:04

    In my case worked with:

    np.load(path, allow_pickle=True)
    
    0 讨论(0)
提交回复
热议问题