Keras下载Mnist、Cifar10数据集无法下载,出现URL fetch failure on问题错误的特殊解决方法

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/apple/Desktop/读研/CNN/main.py", line 10, in <module>
    (x_train,y_train),(x_test,y_test)=cifar10.load_data()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/keras/datasets/cifar10.py", line 58, in load_data
    '6d958be074577803d12ecdefd02955f39262c83c16fe9348329d7fe0b5c001ce')
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/keras/utils/data_utils.py", line 282, in get_file
    raise Exception(error_msg.format(origin, e.errno, e.reason))
Exception: URL fetch failure on https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz: None -- [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:719)

下载cifar10数据集出现Exception: URL fetch failure on https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz: None -- [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:719)的错误,试过科学上网、手动下载(出现hash不匹配问题)。最终找到了一个“特殊”的解决方法解决了这个问题。

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tensorflow/python/keras/utils/data_utils.py

我们进入da ta_utils.py文件

    try:
      try:
        urlretrieve(origin, fpath, dl_progress)
      except HTTPError as e:
        raise Exception(error_msg.format(origin, e.code, e.msg))
      except URLError as e:
        raise Exception(error_msg.format(origin, e.errno, e.reason))
    except (Exception, KeyboardInterrupt) as e:
      if os.path.exists(fpath):
        os.remove(fpath)
      raise

将位于276-286行的代码注释掉,再次运行发现可以下载了。

    # try:
    #   try:
    #     urlretrieve(origin, fpath, dl_progress)
    #   except HTTPError as e:
    #     raise Exception(error_msg.format(origin, e.code, e.msg))
    #   except URLError as e:
    #    raise Exception(error_msg.format(origin, e.errno, e.reason))
    # except (Exception, KeyboardInterrupt) as e:
    #   if os.path.exists(fpath):
    #     os.remove(fpath)
    #   raise
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /Users/apple/Desktop/读研/CNN/main.py
Downloading data from https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
2020-11-12 15:15:21.725049: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-11-12 15:15:21.789464: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x148a6fb00 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-11-12 15:15:21.789490: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
-------------------load the model--------------------------
Epoch 1/5
   1/1563 [..............................] - ETA: 0s - loss: 1.2484 - sparse_categorical_crossentropy: 1.2484
   3/1563 [..............................] - ETA: 28s - loss: 1.4327 - sparse_categorical_crossentropy: 1.4327
   5/1563 [..............................] - ETA: 36s - loss: 1.4299 - sparse_categorical_crossentropy: 1.4299
   7/1563 [..............................] - ETA: 44s - loss: 1.3903 - sparse_categorical_crossentropy: 1.3903
   8/1563 [..............................] - ETA: 50s - loss: 1.4012 - sparse_categorical_crossentropy: 1.4012
   9/1563 [..............................] - ETA: 54s - loss: 1.3669 - sparse_categorical_crossentropy: 1.3669

最后总结:可能是由于数据集比较大,接近于150MB,很容易导致超时错误,但是我们把出现超时错误的代码注释掉,就可以跳过报错进行正常下载。

 

  • 5
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值