【debug】keras使用基础问题

一、下载报错

报错详情

1、下载数据报错

(x_train, y_train_cats), (x_test, y_test_cats) = cifar10.load_data()

报错信息

Exception: URL fetch failure on https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/keras/src/utils/file_utils.py:295, in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir, force_download)
293 raise Exception(error_msg.format(origin, e.code, e.msg))
294 except urllib.error.URLError as e:
295 raise Exception(error_msg.format(origin, e.errno, e.reason))
296 except (Exception, KeyboardInterrupt):
297 if os.path.exists(fpath):
Exception: URL fetch failure on https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz: None – [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)

下载模型报错

model = kapp.VGG19()

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/keras/src/utils/file_utils.py:295, in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir, force_download)
293 raise Exception(error_msg.format(origin, e.code, e.msg))
294 except urllib.error.URLError as e:
295 raise Exception(error_msg.format(origin, e.errno, e.reason))
296 except (Exception, KeyboardInterrupt):
297 if os.path.exists(fpath):
Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/keras-applications/vgg19/vgg19_weights_tf_dim_ordering_tf_kernels.h5: None – [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)

解决方式

忽略ssl检查

在可以访问该地址的情况下,出现该报错,原因即是在进行证书校验时出错的。所以在可以ssl基础库中设置忽略证书校验即可。

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

提前将数据或者包下载到本地

这里找到了针对以上数据报错的解决方式,或者针对部分不能直接访问原地址的用户,可以通过其他途径提前将数据压缩包下载。之后放入到keras在系统环境中的数据目录下。

进入指定网址,手动下载压缩包
https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
并重命名为:cifar-10-batches-py.tar.gz
放到路径:/.keras/datasets下

参考

downloading ResNet50 in Keras generates “SSL: CERTIFICATE_VERIFY_FAILED”
【Bug解决】Exception: URL fetch failure on https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz

相关推荐

  1. 【debug】keras使用基础问题

    2024-07-10 19:54:03       19 阅读
  2. RecycleView基本使用及常见问题汇总

    2024-07-10 19:54:03       51 阅读
  3. MYSQL基础问题

    2024-07-10 19:54:03       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 19:54:03       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 19:54:03       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 19:54:03       58 阅读
  4. Python语言-面向对象

    2024-07-10 19:54:03       69 阅读

热门阅读

  1. Qt 绘图详解

    2024-07-10 19:54:03       24 阅读
  2. MySQL篇七:复合查询

    2024-07-10 19:54:03       26 阅读
  3. [GDOUCTF 2023]Tea writeup

    2024-07-10 19:54:03       27 阅读
  4. 软件开发C#(Sharp)总结(续)

    2024-07-10 19:54:03       17 阅读
  5. CSS 样式链接的多方面应用与最佳实践

    2024-07-10 19:54:03       22 阅读
  6. 西门子7MB2335-0AL00-3AA1

    2024-07-10 19:54:03       19 阅读