2016-06-15 78 views
1

我最近測試了代碼Tensorflow VGG16。當我加載python3.4中的vgg16.npy。它出來的錯誤。 的代碼是這樣的:在python3.4中加載.npy文件錯誤

self.data_dict = np.load(vgg16_npy_path, encoding='latin1').item() 

錯誤:

TypeError: load() got an unexpected keyword argument 'encoding' 

但我刪除encoding='latin1',只是

self.data_dict = np.load(vgg16_npy_path).item() 

這裏還配備了一個錯誤:

File "/home/kang/Documents/work_code_PC1/tensorflow-vgg/vgg16.py", line 20, in __init__ 
    self.data_dict = np.load(vgg16_npy_path).item() 

    File "/usr/lib/python3/dist-packages/numpy/lib/npyio.py", line 394, in load 
    return format.read_array(fid) 

    File "/usr/lib/python3/dist-packages/numpy/lib/format.py", line 446, in read_array 
    array = pickle.load(fp) 

UnicodeDecodeError: 'ascii' codec can't decode byte 0xed in position 0: ordinal not in range(128) 

那麼如何使用np.load在python3.4中加載.npy文件? 非常感謝。

回答

1

您似乎已經爲Python 3.4安裝了舊版本的NumPy。從我所知道的情況來看,encoding參數被添加到np.load()之間version 1.9.0version 1.9.1之間。嘗試升級到NumPy的較新版本:

$ sudo pip3 install --upgrade numpy 
# ...or, if the above doesn't work on your platform: 
$ sudo pip install --upgrade numpy