追溯(最近一次通话):convert_model.py

时间:2018-09-07 14:38:56

标签: python keras

实施代码时: https://github.com/fizyr/keras-retinanet 下面是convert_model.py脚本的代码

  # Allow relative imports when being executed as script.
if __name__ == "__main__" and __package__ is None:
    sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
    import keras_retinanet.bin  # noqa: F401
    __package__ = "keras_retinanet.bin"

# Change these to absolute imports if you copy this script outside the keras_retinanet package.
from keras_retinanet.models import load_model
model_path = os.path.join('..', 'snapshots', 'resnet50_coco_best_v2.1.0.h5')
model = load_model(model_path, backbone_name='resnet50')

执行convert_model.py脚本时,发生以下错误:

Traceback (most recent call last):
  File "convert_model.py", line 33, in <module>
    model = load_model(model_path, backbone_name='resnet50')
  File "..\..\keras_retinanet\models\__init__.py", line 83, in load_model
    model = keras.models.load_model(filepath, custom_objects=backbone(backbone_name).custom_objects)
  File "C:\Python\Python36\lib\site-packages\keras\engine\saving.py", line 249, in load_model
    f = h5py.File(filepath, mode='r')
  File "C:\Python\Python36\lib\site-packages\h5py\_hl\files.py", line 312, in __init__
    fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
  File "C:\Python\Python36\lib\site-packages\h5py\_hl\files.py", line 142, 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 = '..\snapshots\resnet50_coco_best_v2.1.0.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

能帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

确保已下载参考文件,并且该文件与当前python脚本位于同一文件夹中。然后将最后一行更改为:

模型= load_model('文件名',骨干名称='resnet50')