from keras.datasets import imdb
from keras.datasets import reuters
在anaconda3中使用tensorflow调用keras的数据集时,发现速度特别慢,甚至有时候会出现连接错误。
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/reuters.npz
Traceback (most recent call last):
File “D:\Anaconda3\envs\test\lib\urllib\request.py”, line 1349, in do_open
encode_chunked=req.has_header(‘Transfer-encoding’))
……
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “D:\Anaconda3\envs\test\lib\site-packages\tensorflow\python\keras\utils\data_utils.py”, line 278, in get_file
urlretrieve(origin, fpath, dl_progress)
……
urllib.error.URLError: <urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “D:/PyCharm/PythonProject/reuters.py”, line 2, in <module
……Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/tf-keras-datasets/reuters.npz: None – [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
网上查找多方资料,发现是可能是由于墙的原因或者网站已关闭,于是数据无法下载。
好在一些人已经将这些数据下载了下来,我们只需要根据他们的链接将这些数据集下载到本地,再调用就好了。
下面两种下载方式都可以正常下载,主要来自于本文最后的两篇参考博客。
下载完成后解压后是如下这些文件,都是已经下载好的数据集。
我们只需要将这些文件放到指定位置下就可以调用它们。
指定位置:C:\Users\Administrator\ .keras\datasets\
注意:如果你装了anaconda,这个路径并不是你创建的虚拟环境下的keras所在位置,是你的主机用户所在位置。
参考博客: