keras / tensorflow没有找到权重文件imagenet

时间:2018-02-15 15:38:18

标签: tensorflow keras imagenet

以下最小示例代码

#!/usr/bin/env python3
from tensorflow.contrib.keras.api import keras
model = keras.applications.xception.Xception(input_shape=(299, 299, 3))

失败
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/_impl/keras/applications/xception.py", line 307, in Xception
    model.load_weights(weights)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/_impl/keras/engine/topology.py", line 1101, in load_weights
    f = h5py.File(filepath, mode='r')
  File "/usr/local/lib/python3.5/dist-packages/h5py/_hl/files.py", line 269, in __init__
    fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
  File "/usr/local/lib/python3.5/dist-packages/h5py/_hl/files.py", line 99, in make_fid
    fid = h5f.open(name, flags, fapl=fapl)
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py/h5f.pyx", line 78, in h5py.h5f.open
OSError: Unable to open file (unable to open file: name = 'imagenet', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

即使在跑步前这样做:

rm -r ~/.keras/models/

然后它再次成功下载https://github.com/fchollet/deep-learning-models/releases/download/v0.4/xception_weights_tf_dim_ordering_tf_kernels.h5,但之后又出现了同样的错误。我错过了什么?

我在Ubuntu 16.04上使用的是TensorFlow版本1.5.0(来自pip3的tensorflow-gpu)。

1 个答案:

答案 0 :(得分:1)

这是TF-Keras特有的问题。它在GitHub issue中进行了讨论并得到修复。据作者说,

  

它是在PR #15146中引入的,它适用于Xception和   MobileNet。

     

但是,它已经修复了。如果你升级到TF 1.6,你会   不再看到这个问题。例如,你可以pip install TF 1.6   发布候选人1.6.0rc0截至目前。