我正在尝试从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')有人能帮上忙吗?谢谢。
发布于 2021-01-29 01:52:29
您可以从tensorflow导入,而不是从keras导入。
from tensorflow.keras.applications import VGG16这会解决你的问题
https://stackoverflow.com/questions/65942067
复制相似问题