load_state_dict_from_url

paddle.hub. load_state_dict_from_url ( url: str, model_dir: str | None = None, check_hash: bool = False, file_name: str | None = None, map_location: Literal[cpu, gpu, xpu, npu, numpy, np] | None = None ) Any [source]

Download Paddle’s model weights (i.e., state_dict) from the specified URL and extract the downloaded file if necessary

Parameters
  • url (str) – URL of the object to download.

  • model_dir (Optional[str], optional) – Directory in which to save the object.

  • check_hash (bool, optional) – If True, the filename part of the URL should follow the naming convention filename-<sha256>.ext where <sha256> is the first eight or more digits of the SHA256 hash of the contents of the file. The hash is used to ensure unique names and to verify the contents of the file. Default: False.

  • file_name (Optional[str], optional) – Name for the downloaded file. Filename from URL will be used if not set.

  • map_location (Optional[Literal["cpu", "gpu", "xpu", "npu", "numpy", "np"]], optional) – Specifies how to remap storage locations. Default: None.

Returns

A target object that can be used in Paddle.

Return type

Any

Examples

>>> import paddle
>>> paddle.hub.load_state_dict_from_url(url='https://paddle-hapi.bj.bcebos.com/models/resnet18.pdparams', model_dir="./paddle/test_load_from_url")
>>> paddle.hub.load_state_dict_from_url(url='https://x2paddle.bj.bcebos.com/resnet18.zip', model_dir="./paddle/test_file_is_zip")