首页 > 解决方案 > Errno 13 权限被拒绝 Keras VGG16

问题描述

我正在尝试从 Keras 加载 VGG16 模型来执行迁移学习,

input_shape = (224, 224, 3)
model = VGG16(weights='imagenet', include_top=False, input_shape=input_shape)

但我收到以下错误:

Traceback (most recent call last):

  File "<ipython-input-27-898653ab5324>", line 1, in <module>
    model = VGG16(weights='imagenet', include_top=False)

  File "C:\Users\jywlj\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\keras\applications\__init__.py", line 49, in wrapper
    return base_fun(*args, **kwargs)

  File "C:\Users\jywlj\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\keras\applications\vgg16.py", line 32, in VGG16
    return vgg16.VGG16(*args, **kwargs)

  File "C:\Users\jywlj\AppData\Roaming\Python\Python37\site-packages\keras_applications\vgg16.py", line 209, in VGG16
    file_hash='6d6bbae143d832006294945121d1f1fc')

  File "C:\Users\jywlj\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\keras\utils\data_utils.py", line 223, in get_file
    if not validate_file(fpath, file_hash, algorithm=hash_algorithm):

  File "C:\Users\jywlj\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\keras\utils\data_utils.py", line 324, in validate_file
    if str(_hash_file(fpath, hasher, chunk_size)) == str(file_hash):

  File "C:\Users\jywlj\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\keras\utils\data_utils.py", line 299, in _hash_file
    for chunk in iter(lambda: fpath_file.read(chunk_size), b''):

  File "C:\Users\jywlj\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\keras\utils\data_utils.py", line 299, in <lambda>
    for chunk in iter(lambda: fpath_file.read(chunk_size), b''):

PermissionError: [Errno 13] Permission denied

这真的很奇怪,因为加载 VGG19 网络对我没有任何问题。此外,如果我删除“include_top”参数,模型会成功加载而不会引发错误。

# This works fine
model = VGG16(weights='imagenet')

有人能帮忙吗?谢谢。

标签: pythontensorflowkerasvgg-net

解决方案


您可以从 tensorflow 导入,而不是从 keras 导入。

from tensorflow.keras.applications import VGG16

这将解决您的问题


推荐阅读