在python3.4中加载.npy文件错误

时间:2016-06-15 11:15:00

标签: python python-3.x numpy tensorflow deep-learning

我最近测试了Tensorflow VGG16的代码。当我在python3.4中加载vgg16.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 个答案:

答案 0 :(得分:1)

您似乎已为Python 3.4安装了旧版本的NumPy。据我所知,encoding参数已在version 1.9.0version 1.9.1之间添加到np.load()。尝试升级到更新版本的NumPy:

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