简体   繁体   中英

get_file(fname, origin=_URL, extract=True) not extracting the file

My code:

import matplotlib.pyplot as plt
import numpy as np
import os
import tensorflow as tf
from tensorflow.keras.preprocessing import image_dataset_from_directory

import os
os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

_URL = 'https://storage.googleapis.com/mledu-datasets/cats_and_dogs_filtered.zip'
dl_fname = '/Volumes/D/PythonCode/tf_transfer_learning/cats_and_dogs.zip'
path_to_zip = tf.keras.utils.get_file(dl_fname, origin=_URL, extract=True)

I can see cats_and_dogs.zip being downloaded, however, it is not extracted/unzipped. I am on MacOS, using PyCharm.

I am not sure why not. Anyone has a pointer? Thanks.

The URL is https://storage.googleapis.com/mledu-datasets/cats_and_dogs_filtered.zip but you saved it as cats_and_dogs.zip . When you extract it, you get a directory cats_and_dogs_filtered , no matter what the name of the zip file is.

Though it does seem that the extracted file is in ~/.keras/datasets/cats_and_dogs_filtered.zip even if one uses an absolute path.

import tensorflow as tf

url = 'https://storage.googleapis.com/mledu-datasets/cats_and_dogs_filtered.zip'
dl_path = "/tmp/cats_and_dogs_filtered.zip"
path_to_zip = tf.keras.utils.get_file(dl_path, origin=url, extract=True)

The zip file is saved to the absolute path, but the extracted path goes to ~/.keras/datasets/cats_and_dogs_filtered/ .

print(path_to_zip)
# /tmp/cats_and_dogs_filtered.zip

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM