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,很容易导致超时错误,但是我们把出现超时错误的代码注释掉,就可以跳过报错进行正常下载。