Downloads a file from a URL if it not already in the cache.
tf.keras.utils.get_file(
fname=None,
origin=None,
untar=False,
md5_hash=None,
file_hash=None,
cache_subdir='datasets',
hash_algorithm='auto',
extract=False,
archive_format='auto',
cache_dir=None,
force_download=False
)
Used in the notebooks
Used in the guide | Used in the tutorials |
---|---|
By default the file at the url origin
is downloaded to the
cache_dir ~/.keras
, placed in the cache_subdir datasets
,
and given the filename fname
. The final location of a file
example.txt
would therefore be ~/.keras/datasets/example.txt
.
Files in .tar
, .tar.gz
, .tar.bz
, and .zip
formats can
also be extracted.
Passing a hash will verify the file after download. The command line
programs shasum
and sha256sum
can compute the hash.
Example:
path_to_downloaded_file = get_file(
origin="https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz",
extract=True,
)
Returns | |
---|---|
Path to the downloaded file. |
⚠️ Warning on malicious downloads ⚠️
Downloading something from the Internet carries a risk.
NEVER download a file/archive if you do not trust the source.
We recommend that you specify the file_hash
argument
(if the hash of the source file is known) to make sure that the file you
are getting is the one you expect.