0

以下最小示例代码

#!/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再次成功下载,但之后出现相同的错误。我错过了什么?

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

4

1 回答 1

1

这是 TF-Keras 特有的问题。它已在此GitHub 问题中讨论并已修复。据作者介绍,

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

然而,它已经被修复了。如果升级到 TF 1.6,您将不再看到此问题。例如,您现在可以pip install使用 TF 1.6 候选版本1.6.0rc0

于 2018-02-17T08:22:27.310 回答