【发布时间】:2020-11-14 00:45:52
【问题描述】:
尝试使用 TensorFlow Keras 加载数据集时出现错误。代码如下:
dataset_url = "https://storage.googleapis.com/sample_org/sample_file.zip"
data_dir = tf.keras.utils.get_file(origin=dataset_url,
fname='sample_file',
extract=True)
data_dir = pathlib.Path(data_dir)
出于安全原因,我已将 URL 更改为“sample_file.zip”。
这是我得到的错误:
---------------------------------------------------------------------------
FileExistsError Traceback (most recent call last)
<ipython-input-12-1cdc186b0389> in <module>()
2 data_dir = tf.keras.utils.get_file(origin=dataset_url,
3 fname='sample_file',
----> 4 extract=True)
5 data_dir = pathlib.Path(data_dir)
3 frames
/usr/lib/python3.6/zipfile.py in _extract_member(self, member, targetpath, pwd)
1572 if member.is_dir():
1573 if not os.path.isdir(targetpath):
-> 1574 os.mkdir(targetpath)
1575 return targetpath
1576
FileExistsError: [Errno 17] File exists: '/root/.keras/datasets/sample_file'
是什么导致了这个错误?我该如何解决?
这是导入后运行的第一段代码,所以我不知道为什么会发生“FileExistsError”。
我已尝试更改文件名。
我检查了 TensorFlow 文档,它使用如下代码:
dataset_url = "https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz"
data_dir = tf.keras.utils.get_file(origin=dataset_url,
fname='flower_photos',
untar=True)
data_dir = pathlib.Path(data_dir)
我已经运行了上面的代码并且它正在工作。但我无法弄清楚为什么相同的代码对我的数据显示错误。请指教。
【问题讨论】:
标签: python tensorflow keras google-colaboratory