OS:Windows 10
tensorflow和keras成功导入,python 3.7.9
tf.__version__
>>> '2.1.0'
keras.__version__
>>> '2.2.4-tf'
问题
已尝试加载数据集或tf.ker中可用的任何数据集,例如:
(train_images, train_labels), (test_images, test_labels) = tf.keras.datasets.fashion_mnist.load_data()
给出这个错误
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
During handling of the above exception, another exception occurred:
.
.
.
URLError: <urlopen error [WinError 10054] An existing connection was forcibly closed by the remote host>
During handling of the above exception, another exception occurred:
.
.
.
Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-
idx1-ubyte.gz: None -- [WinError 10054] An existing connection was forcibly closed by the remote host
这三个点显示了一堆无法执行的代码行。
有人知道怎么解决吗?我一直在寻找可能的解决方案,但我能找到的最接近的是解决认证/验证问题,我认为我的是关于URL的。
我知道解决方法是从kaggle等下载数据集,但我想知道是什么原因造成的。谢谢各位
编辑:不是URL问题,无法访问https://storage.googleapis.com使用IDM,但文件可以直接在浏览器中下载。所以我想是安全问题
终于在这里和那里阅读了5个小时。。
请点击此处查看CRLannister的解决方案https://github.com/tensorflow/tensorflow/issues/33285
它没有提到data_utils.py
在Windows操作系统和anaconda环境中的位置。它位于此处~Anaconda3envs*your_env*Libsite-packagestensorflow_corepythonkerasutilsdata_utils.py
只需在所有导入语句之后添加以下内容
import requests
requests.packages.urllib3.disable_warnings()
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context