machrisaa / tensorflow-vgg

VGG19 and VGG16 on Tensorflow
2.21k stars 1.08k forks source link

python3 compability: load() got an unexpected keyword argument 'encoding' #6

Closed jiankang1991 closed 7 years ago

jiankang1991 commented 8 years ago

I got the following error when I run it on python3:

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

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

How to fix it? Thank you very much.

machrisaa commented 8 years ago

Copied from documentation of Numpy:

encoding : str, optional
What encoding to use when reading Python 2 strings. Only useful when loading Python 2 generated pickled files on Python 3, which includes npy/npz files containing object arrays. Values other than ‘latin1’, ‘ASCII’, and ‘bytes’ are not allowed, as they can corrupt numerical data. Default: ‘ASCII’

So I will suggest you remove the encoding parameter for Python 3.

jiankang1991 commented 8 years ago

Thank you. I tried, but it comes out the following error:

  File "<ipython-input-1-686846baf3f3>", line 1, in <module>
    runfile('/home/kang/Documents/work_code_PC1/tensorflow-vgg/test_vgg16.py', wdir='/home/kang/Documents/work_code_PC1/tensorflow-vgg')

  File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 685, in runfile
    execfile(filename, namespace)

  File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 85, in execfile
    exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)

  File "/home/kang/Documents/work_code_PC1/tensorflow-vgg/test_vgg16.py", line 20, in <module>
    vgg = vgg16.Vgg16()

  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)
machrisaa commented 7 years ago

This issue should be fixed in the recent update on the python3 compatibility.