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

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

    The answer of @cheez sometime doesn't work and recursively call the function again and again. To solve this problem you should copy the function deeply. You can do this by using the function partial, so the final code is:

    import numpy as np
    from functools import partial
    
    # save np.load
    np_load_old = partial(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
    

提交回复
热议问题