torch.utils.model_zoo#
Created On: Jan 09, 2017 | Last Updated On: Jun 11, 2025
Moved totorch.hub.
- torch.utils.model_zoo.load_url(url,model_dir=None,map_location=None,progress=True,check_hash=False,file_name=None,weights_only=False)[source]#
Loads the Torch serialized object at the given URL.
If downloaded file is a zip file, it will be automaticallydecompressed.
If the object is already present inmodel_dir, it’s deserialized andreturned.The default value of
model_diris<hub_dir>/checkpointswherehub_diris the directory returned byget_dir().- Parameters
url (str) – URL of the object to download
model_dir (str,optional) – directory in which to save the object
map_location (optional) – a function or a dict specifying how to remap storage locations (see torch.load)
progress (bool,optional) – whether or not to display a progress bar to stderr.Default: True
check_hash (bool,optional) – If True, the filename part of the URL should follow the naming convention
filename-<sha256>.extwhere<sha256>is the first eight or moredigits of the SHA256 hash of the contents of the file. The hash is used toensure unique names and to verify the contents of the file.Default: Falsefile_name (str,optional) – name for the downloaded file. Filename from
urlwill be used if not set.weights_only (bool,optional) – If True, only weights will be loaded and no complex pickled objects.Recommended for untrusted sources. See
load()for more details.
- Return type
Example
>>>state_dict=torch.hub.load_state_dict_from_url(..."https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth"...)