python - 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')
有人能帮忙吗?谢谢。
解决方案
您可以从 tensorflow 导入,而不是从 keras 导入。
from tensorflow.keras.applications import VGG16
这将解决您的问题
推荐阅读
- c# - Xamarin.Forms MasterDetailPage 是否适用于 Kindle VoiceOver 辅助功能
- pandas - pandas df 按多列分组的百分比计数
- python - 如何从 Pandas DataFrame 中的路径获取基本文件名
- javascript - React & Progressbar.js:自定义形状的进度圈
- c# - 文本框填充网格行中的所有可用空间
- vb.net - 注册表双字值在vb中更改
- sql - 比较 2 条记录并在 POSTGRESQL 中使用 YES 或 NO 更新新字段
- javascript - 使用 React Firebase 添加到收藏夹时出现问题
- typescript - 如何在nestjs中创建rest api?
- sql - Clickhouse LEFT JOIN 部分匹配(或子选择)