I am getting an error when trying to load a dataset using TensorFlow Keras. Here is the code:
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)
I have changed the URL to 'sample_file.zip' for security reasons.
This is the error that I am getting:
---------------------------------------------------------------------------
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'
What is causing this error? How can I fix it?
This is the first block of code run after imports so I don't know why 'FileExistsError' happens.
I have tried changing the name of the file.
I have checked TensorFlow documentation and it uses code like this:
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)
I have run this above code and it is working. But I cannot figure out why the same code is showing error for my data. Please advice.
I think you have a file (without any extension) called /root/.keras/datasets/sample_file
, which is why there is an error. Try giving it a different name fname='my_very_unique_sample_file_name_that_does_not_exist_yet'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.