tensorlayer / TensorLayer

Deep Learning and Reinforcement Learning Library for Scientists and Engineers
http://tensorlayerx.com
Other
7.34k stars 1.61k forks source link

Enable allow_pickle in numpy.load #1019

Closed edenau closed 5 years ago

edenau commented 5 years ago

New Issue Checklist

Issue Description

I encountered the following error when I was trying to run python train.py in repo tensorlayer/srgan.

Traceback (most recent call last):
  File "train.py", line 357, in <module>
    train()
  File "train.py", line 75, in train
    VGG = tl.models.vgg19(pretrained=True, end_with='pool4', mode='static')
  File "/home/s1895566/venv/lib/python3.6/site-packages/tensorlayer/models/vgg.py", line 317, in vgg19
    restore_model(model, layer_type='vgg19')
  File "/home/s1895566/venv/lib/python3.6/site-packages/tensorlayer/models/vgg.py", line 169, in restore_model
    npz = np.load(os.path.join('models', model_saved_name[layer_type]), encoding='latin1').item()
  File "/home/s1895566/venv/lib/python3.6/site-packages/numpy/lib/npyio.py", line 447, in load
    pickle_kwargs=pickle_kwargs)
  File "/home/s1895566/venv/lib/python3.6/site-packages/numpy/lib/format.py", line 696, in read_array
    raise ValueError("Object arrays cannot be loaded when "
ValueError: Object arrays cannot be loaded when allow_pickle=False

I did a little digging, and it turns out that recent development in numpy stated in numpy/numpy#13359 changed the default value of allow_pickle from True to False. A quick grep in tensorlayer folder suggested that most np.load() did not explicitly pass True argument for allow_pickle.

./models/vgg.py:        npz = np.load(os.path.join('models', model_saved_name[layer_type]))
./models/vgg.py:        npz = np.load(os.path.join('models', model_saved_name[layer_type]), encoding='latin1').item()
./files/utils.py:        v = np.load(np_file)
./files/utils.py:        v = np.load(np_file)
./files/utils.py:            v = np.load(np_file)
./files/utils.py:    d = np.load(os.path.join(path, name), allow_pickle=True)
./files/utils.py:    weights = np.load(name)
./files/utils.py:        return np.load(file_path).item()
./files/utils.py:        return np.load(file_path)

Suggestion

Pass allow_pickle=True explicitly in all np.load(), it works as intended as I did so in my own environment.

warshallrho commented 5 years ago

Thanks for your suggestion! I will deal with this issue soon.

warshallrho commented 5 years ago

Fixed in PR #1021